forked from andrius/neohubapi
Allow for the hub not returning some of our desired attributes.
This commit is contained in:
parent
5ef21a23fd
commit
aa6020c621
|
@ -1,4 +1,5 @@
|
||||||
# SPDX-FileCopyrightText: 2020-2021 Andrius Štikonas <andrius@stikonas.eu>
|
# SPDX-FileCopyrightText: 2020-2021 Andrius Štikonas <andrius@stikonas.eu>
|
||||||
|
# SPDX-FileCopyrightText: 2021 Dave O'Connor <daveoc@google.com>
|
||||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# SPDX-FileCopyrightText: 2020-2021 Andrius Štikonas <andrius@stikonas.eu>
|
# SPDX-FileCopyrightText: 2020-2021 Andrius Štikonas <andrius@stikonas.eu>
|
||||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
|
import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
@ -15,54 +16,86 @@ class NeoStat(SimpleNamespace):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, hub, thermostat):
|
def __init__(self, hub, thermostat):
|
||||||
|
self._logger = logging.getLogger('neohub')
|
||||||
self._data_ = thermostat
|
self._data_ = thermostat
|
||||||
self._hub = hub
|
self._hub = hub
|
||||||
|
|
||||||
self.active_level = self._data_.ACTIVE_LEVEL
|
self._simple_attrs = (
|
||||||
self.active_profile = self._data_.ACTIVE_PROFILE
|
'active_level',
|
||||||
self.available_modes = self._data_.AVAILABLE_MODES
|
'active_profile',
|
||||||
self.away = self._data_.AWAY
|
'available_modes',
|
||||||
self.cool_on = self._data_.COOL_ON
|
'away',
|
||||||
self.cool_temp = self._data_.COOL_TEMP
|
'cool_on',
|
||||||
self.current_floor_temperature = self._data_.CURRENT_FLOOR_TEMPERATURE
|
'cool_temp',
|
||||||
self.weekday = Weekday(self._data_.DATE)
|
'current_floor_temperature',
|
||||||
self.device_id = self._data_.DEVICE_ID
|
'date',
|
||||||
self.fan_control = self._data_.FAN_CONTROL
|
'device_id',
|
||||||
self.fan_speed = self._data_.FAN_SPEED
|
'fan_control',
|
||||||
self.floor_limit = self._data_.ZONE_NAME
|
'fan_speed',
|
||||||
self.hc_mode = self._data_.HC_MODE
|
'floor_limit',
|
||||||
self.heat_mode = self._data_.HEAT_MODE
|
'hc_mode',
|
||||||
self.heat_on = self._data_.HEAT_ON
|
'heat_mode',
|
||||||
self.hold_cool = self._data_.HOLD_COOL
|
'heat_on',
|
||||||
self.hold_off = self._data_.HOLD_OFF
|
'hold_cool',
|
||||||
self.hold_on = self._data_.HOLD_ON
|
'fan_control',
|
||||||
self.hold_temp = self._data_.HOLD_TEMP
|
'fan_speed',
|
||||||
_hold_time = list(map(int, self._data_.HOLD_TIME.split(':'))) # HOLD_TIME can be up to 99:99
|
'hc_mode',
|
||||||
|
'heat_mode',
|
||||||
|
'heat_on',
|
||||||
|
'hold_cool',
|
||||||
|
'hold_off',
|
||||||
|
'hold_on',
|
||||||
|
'hold_temp',
|
||||||
|
'hold_time', # This is updated below.
|
||||||
|
'holiday',
|
||||||
|
'lock',
|
||||||
|
'low_battery',
|
||||||
|
'manual_off',
|
||||||
|
'modelock',
|
||||||
|
'modulation_level',
|
||||||
|
'offline',
|
||||||
|
'pin_number',
|
||||||
|
'preheat_active',
|
||||||
|
'prg_temp',
|
||||||
|
'prg_timer',
|
||||||
|
'standby',
|
||||||
|
'switch_delay_left', # This is updated below.
|
||||||
|
'temporary_set_flag',
|
||||||
|
'time', # This is updated below.
|
||||||
|
'timer_on',
|
||||||
|
'window_open',
|
||||||
|
'write_count'
|
||||||
|
)
|
||||||
|
|
||||||
|
for a in self._simple_attrs:
|
||||||
|
data_attr = a.upper()
|
||||||
|
if not hasattr(self._data_, data_attr):
|
||||||
|
self._logger.debug(f"Thermostat object has no attribute {data_attr}")
|
||||||
|
self.__dict__[a] = getattr(self._data_, data_attr, None)
|
||||||
|
|
||||||
|
# Renamed attrs
|
||||||
|
self.name = getattr(self._data_, 'ZONE_NAME', None)
|
||||||
|
self.floor_limit = getattr(self._data_, 'ZONE_NAME', None)
|
||||||
|
self.target_temperature = getattr(self._data_, 'SET_TEMP', None)
|
||||||
|
self.temperature = getattr(self._data_, 'ACTUAL_TEMP', None)
|
||||||
|
|
||||||
|
# must be ints
|
||||||
|
self.pin_number = int(self.pin_number)
|
||||||
|
self.preheat_active = int(self.preheat_active)
|
||||||
|
|
||||||
|
# HOLD_TIME can be up to 99:99
|
||||||
|
_hold_time = list(map(int, self.hold_time.split(':')))
|
||||||
_hold_time_minutes = _hold_time[0] * 60 + _hold_time[1]
|
_hold_time_minutes = _hold_time[0] * 60 + _hold_time[1]
|
||||||
self.hold_time = timedelta(minutes=_hold_time_minutes)
|
self.hold_time = timedelta(minutes=_hold_time_minutes)
|
||||||
self.holiday = self._data_.HOLIDAY
|
|
||||||
self.lock = self._data_.LOCK
|
self.weekday = Weekday(self.date)
|
||||||
self.low_battery = self._data_.LOW_BATTERY
|
|
||||||
self.manual_off = self._data_.MANUAL_OFF
|
_switch_delay_left = datetime.strptime(self.switch_delay_left, "%H:%M")
|
||||||
self.modelock = self._data_.MODELOCK
|
self.switch_delay_left = timedelta(
|
||||||
self.modulation_level = self._data_.MODULATION_LEVEL
|
hours=_switch_delay_left.hour,
|
||||||
self.name = self._data_.ZONE_NAME
|
minutes=_switch_delay_left.minute)
|
||||||
self.offline = self._data_.OFFLINE
|
_time = datetime.strptime(self.time, "%H:%M")
|
||||||
self.pin_number = int(self._data_.PIN_NUMBER)
|
|
||||||
self.preheat_active = int(self._data_.PREHEAT_ACTIVE)
|
|
||||||
self.prg_temp = self._data_.PRG_TEMP
|
|
||||||
self.prg_timer = self._data_.PRG_TIMER
|
|
||||||
self.target_temperature = self._data_.SET_TEMP # target temperature
|
|
||||||
self.standby = self._data_.STANDBY
|
|
||||||
_switch_delay_left = datetime.strptime(self._data_.SWITCH_DELAY_LEFT, "%H:%M")
|
|
||||||
self.switch_delay_left = timedelta(hours=_switch_delay_left.hour, minutes=_switch_delay_left.minute)
|
|
||||||
self.temporary_set_flag = self._data_.TEMPORARY_SET_FLAG
|
|
||||||
self.temperature = self._data_.ACTUAL_TEMP
|
|
||||||
_time = datetime.strptime(self._data_.TIME, "%H:%M")
|
|
||||||
self.time = timedelta(hours=_time.hour, minutes=_time.minute)
|
self.time = timedelta(hours=_time.hour, minutes=_time.minute)
|
||||||
self.timer_on = self._data_.TIMER_ON
|
|
||||||
self.window_open = self._data_.WINDOW_OPEN
|
|
||||||
self.write_count = self._data_.WRITE_COUNT
|
|
||||||
|
|
||||||
async def identify(self):
|
async def identify(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue