From e099fe4741fe99029263fbd4813a7579dc376c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sun, 20 Dec 2020 22:58:04 +0000 Subject: [PATCH] Parse GET_LIVE_DATA fields. --- enums.py | 13 ++++++++++- neohub.py | 4 ++-- neostat.py | 65 ++++++++++++++++++++++++++++++++++++++++++------------ test.py | 2 +- 4 files changed, 66 insertions(+), 18 deletions(-) diff --git a/enums.py b/enums.py index e96564f..6e88b49 100644 --- a/enums.py +++ b/enums.py @@ -6,7 +6,7 @@ import enum -class ScheduleFormat(str, enum.Enum): +class ScheduleFormat(enum.Enum): """ Enum to specify Schedule Format @@ -21,6 +21,7 @@ class ScheduleFormat(str, enum.Enum): TWO = "5DAY/2DAY" SEVEN = "7DAY" + def schedule_format_int_to_enum(int_format): if int_format == 0: return ScheduleFormat.ZERO @@ -32,3 +33,13 @@ def schedule_format_int_to_enum(int_format): return ScheduleFormat.SEVEN else: raise ValueError('Unrecognized ScheduleFormat') + + +class Weekday(enum.Enum): + MONDAY = "monday" + TUESDAY = "tuesday" + WEDNESDAY = "wednesday" + THURSDAY = "thursday" + FRIDAY = "friday" + SATURDAY = "saturday" + SUNDAY = "sunday" diff --git a/neohub.py b/neohub.py index 5eea602..85c5e3f 100644 --- a/neohub.py +++ b/neohub.py @@ -364,7 +364,7 @@ class NeoHub: result = await self._send(message) return result - async def lock(self, pin: int, devices: [NeoStat]): + async def set_lock(self, pin: int, devices: [NeoStat]): """ PIN locks thermostats @@ -399,7 +399,7 @@ class NeoHub: result = await self._send(message, reply) return result - async def frost(self, state: bool, devices: [NeoStat]): + async def set_frost(self, state: bool, devices: [NeoStat]): """ Enables or disables Frost mode """ diff --git a/neostat.py b/neostat.py index 9af5386..3cc8571 100644 --- a/neostat.py +++ b/neostat.py @@ -3,8 +3,12 @@ # SPDX-FileCopyrightText: 2020 Andrius Štikonas # SPDX-License-Identifier: LGPL-3.0-or-later +from datetime import datetime, timedelta + from types import SimpleNamespace +from enums import Weekday + class NeoStat(SimpleNamespace): """ @@ -15,17 +19,50 @@ class NeoStat(SimpleNamespace): self._data_ = thermostat self._hub = hub - @property - def name(self): - """ Zone name. """ - - return self._data_.ZONE_NAME - - @property - def temperature(self): - """ Actual zone temperature. """ - - return self._data_.ACTUAL_TEMP + self.active_level = self._data_.ACTIVE_LEVEL + self.active_profile = self._data_.ACTIVE_PROFILE + self.available_modes = self._data_.AVAILABLE_MODES + self.away = self._data_.AWAY + self.cool_on = self._data_.COOL_ON + self.cool_temp = self._data_.COOL_TEMP + self.current_floor_temperature = self._data_.CURRENT_FLOOR_TEMPERATURE + self.weekday = Weekday(self._data_.DATE) + self.device_id = self._data_.DEVICE_ID + self.fan_control = self._data_.FAN_CONTROL + self.fan_speed = self._data_.FAN_SPEED + self.floor_limit = self._data_.ZONE_NAME + self.hc_mode = self._data_.HC_MODE + self.heat_mode = self._data_.HEAT_MODE + self.heat_on = self._data_.HEAT_ON + self.hold_cool = self._data_.HOLD_COOL + self.hold_off = self._data_.HOLD_OFF + self.hold_on = self._data_.HOLD_ON + self.hold_temp = self._data_.HOLD_TEMP + _hold_time = datetime.strptime(self._data_.HOLD_TIME, "%H:%M") + self.hold_time = timedelta(hours=_hold_time.hour, minutes=_hold_time.minute) + self.holiday = self._data_.HOLIDAY + self.lock = self._data_.LOCK + self.low_battery = self._data_.LOW_BATTERY + self.manual_off = self._data_.MANUAL_OFF + self.modelock = self._data_.MODELOCK + self.modulation_level = self._data_.MODULATION_LEVEL + self.name = self._data_.ZONE_NAME + self.offline = self._data_.OFFLINE + 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.set_temp = 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.timer_on = self._data_.TIMER_ON + self.window_open = self._data_.WINDOW_OPEN + self.write_count = self._data_.WRITE_COUNT async def identify(self): """ @@ -65,15 +102,15 @@ class NeoStat(SimpleNamespace): result = await self._hub._send(message, reply) return result - async def lock(self, pin: int): - result = await self._hub.lock(pin, [self]) + async def set_lock(self, pin: int): + result = await self._hub.set_lock(pin, [self]) return result async def unlock(self): result = await self._hub.unlock([self]) return result - async def frost(self, state: bool): + async def set_frost(self, state: bool): result = await self._hub.frost(state, [self]) return result diff --git a/test.py b/test.py index d04ca89..23ea245 100755 --- a/test.py +++ b/test.py @@ -19,7 +19,7 @@ async def run(): hub_data, thermostats = await hub.get_live_data() for device in thermostats: print(f"Temperature in zone {device.name}: {device.temperature}") - #await device.identify() + await device.identify() logging.basicConfig(level=logging.DEBUG)