From 284172fffe86c65a404a0e95e55535a11def597a Mon Sep 17 00:00:00 2001 From: Shaun Tarves Date: Wed, 28 Apr 2021 10:57:30 -0400 Subject: [PATCH] Added support for python 3.8 --- Pipfile | 2 +- Pipfile.lock | 6 +-- README.md | 2 +- setup.py | 5 +- wyze_sdk/api/devices/bulbs.py | 10 ++-- wyze_sdk/api/devices/plugs.py | 6 +-- wyze_sdk/models/__init__.py | 2 + wyze_sdk/models/devices/__init__.py | 3 +- wyze_sdk/models/devices/base.py | 21 +++++--- wyze_sdk/models/devices/bulbs.py | 42 +++++++--------- wyze_sdk/models/devices/cameras.py | 31 +++--------- wyze_sdk/models/devices/locks.py | 15 +++--- wyze_sdk/models/devices/plugs.py | 20 ++++---- wyze_sdk/models/devices/scales.py | 7 +-- wyze_sdk/models/devices/sensors.py | 19 +++---- wyze_sdk/models/devices/thermostats.py | 66 +++++++++++-------------- wyze_sdk/models/devices/vacuums.py | 27 +++++----- wyze_sdk/models/events/__init__.py | 2 + wyze_sdk/service/api_service.py | 2 + wyze_sdk/service/auth_service.py | 2 + wyze_sdk/service/base.py | 2 + wyze_sdk/service/earth_service.py | 2 + wyze_sdk/service/ford_service.py | 2 + wyze_sdk/service/general_api_service.py | 2 + wyze_sdk/service/platform_service.py | 2 + wyze_sdk/service/scale_service.py | 2 + wyze_sdk/service/venus_service.py | 2 + wyze_sdk/service/wyze_response.py | 1 + wyze_sdk/version.py | 2 +- 29 files changed, 149 insertions(+), 158 deletions(-) diff --git a/Pipfile b/Pipfile index e31802c..254dd01 100644 --- a/Pipfile +++ b/Pipfile @@ -13,4 +13,4 @@ flake8 = "*" isort = "*" [requires] -python_version = "3.9" +python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock index d62193b..ab7ed36 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,11 +1,11 @@ { "_meta": { "hash": { - "sha256": "14381b2f1b76b1eed1b442911b4ff2a3965f39b8a4441eab75d041da9e865f97" + "sha256": "0b69dab2aa50897c3137af6645b90ea247234d76acd53dd164bc478c0e14d56b" }, "pipfile-spec": 6, "requires": { - "python_version": "3.9" + "python_version": "3.8" }, "sources": [ { @@ -48,7 +48,7 @@ }, "iniconfig": { "path": ".", - "version": "==0.0.1" + "version": "==1.1.0" }, "protobuf": { "hashes": [ diff --git a/README.md b/README.md index 44c3851..8c9cf7e 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The **Python Wyze SDK** allows interaction with: --- -This library requires Python 3.9 and above. If you're unsure how to check what version of Python you're on, you can check it using the following: +This library requires Python 3.8 and above. If you're unsure how to check what version of Python you're on, you can check it using the following: > **Note:** You may need to use `python3` before your commands to ensure you use the correct Python path. e.g. `python3 --version` diff --git a/setup.py b/setup.py index 6e7cbec..fa12bcb 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ url="https://github.com/shauntarves/wyze-sdk", author='Shaun Tarves', author_email='shaun@tarves.net', - python_requires=">=3.9.0", + python_requires=">=3.8.0", include_package_data=True, license="The Unlicense", classifiers=[ @@ -43,7 +43,8 @@ 'Topic :: Software Development :: Libraries :: Python Modules', "Topic :: Home Automation", 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.9' + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', ], keywords=["wyze", "wyze-labs", "wyze-sdk", "wyze-api", "wyzeapy", "wyze-apy", "smart home", "home automation"], packages=find_packages( diff --git a/wyze_sdk/api/devices/bulbs.py b/wyze_sdk/api/devices/bulbs.py index aa0937c..721625a 100644 --- a/wyze_sdk/api/devices/bulbs.py +++ b/wyze_sdk/api/devices/bulbs.py @@ -73,7 +73,7 @@ def turn_on(self, *, device_mac: str, device_model: str, after: Optional[timedel device_model (str): The device model. e.g. 'WLPA19' after (timedelta): The delay before performing the action. """ - prop_def = DeviceProps.power_state + prop_def = DeviceProps.power_state() if device_model in DeviceModels.MESH_BULB: if after is not None: @@ -100,7 +100,7 @@ def turn_off(self, *, device_mac: str, device_model: str, after: Optional[timede device_model (str): The device model. e.g. 'WLPA19' after (timedelta): The delay before performing the action. """ - prop_def = DeviceProps.power_state + prop_def = DeviceProps.power_state() if device_model in DeviceModels.MESH_BULB: if after is not None: @@ -127,7 +127,7 @@ def set_brightness(self, *, device_mac: str, device_model: str, brightness: int, device_model (str): The device model. e.g. 'WLPA19' brightness (int): The new brightness. e.g. 45 """ - prop_def = BulbProps.brightness + prop_def = BulbProps.brightness() prop_def.validate(brightness) if device_model in DeviceModels.MESH_BULB: @@ -150,7 +150,7 @@ def set_color_temp(self, *, device_mac: str, device_model: str, color_temp: int, device_model (str): The device model. e.g. 'WLPA19' color_temp (int): The new color temperature. e.g. 3400 """ - prop_def = BulbProps.color_temp + prop_def = BulbProps.color_temp() prop_def.validate(color_temp) if device_model in DeviceModels.MESH_BULB: @@ -179,7 +179,7 @@ def set_color(self, *, device_mac: str, device_model: str, color: str, **kwargs) if device_model not in DeviceModels.MESH_BULB: raise WyzeFeatureNotSupportedError("set_color") - prop_def = BulbProps.color + prop_def = BulbProps.color()() prop_def.validate(color) return super()._api_client().run_action_list( diff --git a/wyze_sdk/api/devices/plugs.py b/wyze_sdk/api/devices/plugs.py index 8168bac..ee1cb33 100644 --- a/wyze_sdk/api/devices/plugs.py +++ b/wyze_sdk/api/devices/plugs.py @@ -66,7 +66,7 @@ def turn_on(self, *, device_mac: str, device_model: str, after: Optional[timedel device_model (str): The device model. e.g. 'WLPP1' after (timedelta): The delay before performing the action. """ - prop_def = DeviceProps.power_state + prop_def = DeviceProps.power_state() if after is None: return super()._api_client().set_device_property( @@ -82,7 +82,7 @@ def turn_off(self, *, device_mac: str, device_model: str, after: Optional[timede device_model (str): The device model. e.g. 'WLPP1' after (timedelta): The delay before performing the action. """ - prop_def = DeviceProps.power_state + prop_def = DeviceProps.power_state() if after is None: return super()._api_client().set_device_property( @@ -106,7 +106,7 @@ def set_away_mode(self, *, device_mac: str, device_model: str, away_mode: bool = device_model (str): The device model. e.g. 'WLPP1' away_mode (bool): The new away mode. e.g. True """ - prop_def = PlugProps.away_mode + prop_def = PlugProps.away_mode() if away_mode: return super()._api_client().run_action( mac=device_mac, diff --git a/wyze_sdk/models/__init__.py b/wyze_sdk/models/__init__.py index 9fe0dfd..2944dc2 100644 --- a/wyze_sdk/models/__init__.py +++ b/wyze_sdk/models/__init__.py @@ -1,5 +1,7 @@ """Classes for constructing Wyze-specific data strtucture""" +from __future__ import annotations + import distutils.util import logging from abc import ABCMeta, abstractmethod diff --git a/wyze_sdk/models/devices/__init__.py b/wyze_sdk/models/devices/__init__.py index 49457f9..3d095cb 100644 --- a/wyze_sdk/models/devices/__init__.py +++ b/wyze_sdk/models/devices/__init__.py @@ -1,10 +1,11 @@ """Classes for constructing Wyze-specific data strtucture""" +from __future__ import annotations from .base import (AbstractWirelessNetworkedDevice, ClimateMixin, ContactMixin, # noqa Device, DeviceModels, DeviceProp, DeviceProps, LockableMixin, MotionMixin, PropDef, SwitchableMixin, VoltageMixin) from .bulbs import Bulb, MeshBulb, BulbProps # noqa -from .cameras import Camera, CameraProps # noqa +from .cameras import Camera, CameraProps # noqa from .locks import (Lock, LockGateway, LockEventType, LockProps, LockRecord, LockRecordDetail) # noqa from .plugs import Plug, OutdoorPlug, PlugProps # noqa from .scales import Scale, ScaleRecord, UserGoalWeight, ScaleProps # noqa diff --git a/wyze_sdk/models/devices/base.py b/wyze_sdk/models/devices/base.py index 43162f0..12cfc83 100644 --- a/wyze_sdk/models/devices/base.py +++ b/wyze_sdk/models/devices/base.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import distutils.util import logging from abc import ABCMeta @@ -117,11 +119,11 @@ def __init__( self._ts = ts elif ts is not None: self._ts = epoch_to_datetime(ts, ms=True) - if value is not None and not isinstance(value, definition.type): + if value is not None and not isinstance(value, self._definition.type): try: - value = bool(distutils.util.strtobool(str(value))) if definition.type == bool else definition._type(value) + value = bool(distutils.util.strtobool(str(value))) if self._definition.type == bool else self._definition._type(value) except ValueError: - self.logger.warning(f"could not cast value `{value}` into expected type {definition.type}") + self.logger.warning(f"could not cast value `{value}` into expected type {self._definition.type}") self._value = value @property @@ -175,17 +177,14 @@ def api_value(self) -> Any: class DeviceProps(object): @classmethod - @property def push_notifications_enabled(cls) -> PropDef: return PropDef("P1", bool, int, [0, 1]) @classmethod - @property def power_state(cls) -> PropDef: return PropDef("P3", bool, int, [0, 1]) @classmethod - @property def online_state(cls) -> PropDef: return PropDef("P5", bool, int, [0, 1]) @@ -252,9 +251,9 @@ def __init__( self._mac = mac self._nickname = nickname if conn_state is not None and conn_state_ts is not None: - self._is_online = DeviceProp(definition=DeviceProps.online_state, value=conn_state, ts=conn_state_ts) + self._is_online = DeviceProp(definition=DeviceProps.online_state(), value=conn_state, ts=conn_state_ts) else: - self._is_online = self._extract_property(DeviceProps.online_state, others) + self._is_online = self._extract_property(DeviceProps.online_state(), others) self._enr = enr self._push_switch = push_switch self._firmware_version = firmware_ver if firmware_ver is not None else self._extract_attribute('firmware_ver', others) @@ -342,6 +341,12 @@ def _extract_property(self, prop_def: Union[str, PropDef], others: Union[dict, S self.logger.debug(f"returning new DeviceProp with {value}") return DeviceProp(definition=prop_def, **value) + @classmethod + def remove_model_prefix(cls, text: str, model: str) -> str: + if text.startswith(model): + return text[len(model):] + return text + class AbstractNetworkedDevice(Device, metaclass=ABCMeta): diff --git a/wyze_sdk/models/devices/bulbs.py b/wyze_sdk/models/devices/bulbs.py index b9124a2..aab68e8 100644 --- a/wyze_sdk/models/devices/bulbs.py +++ b/wyze_sdk/models/devices/bulbs.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import (Optional, Set, Union) from wyze_sdk.errors import WyzeFeatureNotSupportedError @@ -11,42 +13,34 @@ class BulbProps(object): """ @classmethod - @property def away_mode(cls) -> PropDef: return PropDef("P1506", bool, int, [0, 1]) @classmethod - @property def power_loss_recovery(cls) -> PropDef: return PropDef("P1509", bool, int, [0, 1]) @classmethod - @property def brightness(cls) -> PropDef: return PropDef("P1501", int, acceptable_values=range(0, 100 + 1)) @classmethod - @property def color_temp(cls) -> PropDef: return PropDef("P1502", int, acceptable_values=range(2700, 6500 + 1)) @classmethod - @property def color(cls) -> PropDef: return PropDef("P1507", str) @classmethod - @property def remaining_time(cls) -> PropDef: return PropDef("P1505", int) @classmethod - @property def control_light(cls) -> PropDef: return PropDef("P1508", bool, int, [0, 1]) @classmethod - @property def delay_off(cls) -> PropDef: return PropDef("P1510", bool, int, [0, 1]) @@ -78,11 +72,11 @@ def __init__( **others: dict, ): super().__init__(type=type, **others) - self.switch_state = self._extract_property(DeviceProps.power_state, others) - self.brightness = super()._extract_property(BulbProps.brightness, others) - self.color_temp = super()._extract_property(BulbProps.color_temp, others) - self.away_mode = super()._extract_property(BulbProps.away_mode, others) - self.power_loss_recovery = super()._extract_property(BulbProps.power_loss_recovery, others) + self.switch_state = self._extract_property(DeviceProps.power_state(), others) + self.brightness = super()._extract_property(BulbProps.brightness(), others) + self.color_temp = super()._extract_property(BulbProps.color_temp(), others) + self.away_mode = super()._extract_property(BulbProps.away_mode(), others) + self.power_loss_recovery = super()._extract_property(BulbProps.power_loss_recovery(), others) show_unknown_key_warning(self, others) @property @@ -92,7 +86,7 @@ def brightness(self) -> int: @brightness.setter def brightness(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=BulbProps.brightness, value=value) + value = DeviceProp(definition=BulbProps.brightness(), value=value) self._brightness = value @property @@ -102,7 +96,7 @@ def color_temp(self) -> int: @color_temp.setter def color_temp(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=BulbProps.color_temp, value=value) + value = DeviceProp(definition=BulbProps.color_temp(), value=value) self._color_temp = value @property @@ -112,7 +106,7 @@ def away_mode(self) -> bool: @away_mode.setter def away_mode(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=BulbProps.away_mode, value=value) + value = DeviceProp(definition=BulbProps.away_mode(), value=value) self._away_mode = value @property @@ -122,7 +116,7 @@ def power_loss_recovery(self) -> bool: @power_loss_recovery.setter def power_loss_recovery(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=BulbProps.power_loss_recovery, value=value) + value = DeviceProp(definition=BulbProps.power_loss_recovery(), value=value) self._power_loss_recovery = value @property @@ -165,7 +159,7 @@ def __init__( **others: dict, ): super().__init__(type=self.type, **others) - self.color = super()._extract_property(BulbProps.color, others) + self.color = super()._extract_property(BulbProps.color(), others) show_unknown_key_warning(self, others) @property @@ -175,15 +169,15 @@ def color(self) -> str: @color.setter def color(self, value: Union[str, DeviceProp]): if isinstance(value, str): - value = DeviceProp(definition=BulbProps.color, value=value) + value = DeviceProp(definition=BulbProps.color(), value=value) self._color = value @classmethod def props(cls) -> dict[str, PropDef]: return {**Bulb.props(), **{ - "color": BulbProps.color, - "remaining_time": BulbProps.remaining_time, - "control_light": BulbProps.control_light, - "power_loss_recovery": BulbProps.power_loss_recovery, # remember_off - "delay_off": BulbProps.delay_off, + "color": BulbProps.color()(), + "remaining_time": BulbProps.remaining_time(), + "control_light": BulbProps.control_light(), + "power_loss_recovery": BulbProps.power_loss_recovery(), # remember_off + "delay_off": BulbProps.delay_off(), }} diff --git a/wyze_sdk/models/devices/cameras.py b/wyze_sdk/models/devices/cameras.py index 9f479b9..f0c4fca 100644 --- a/wyze_sdk/models/devices/cameras.py +++ b/wyze_sdk/models/devices/cameras.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import (Optional, Sequence, Set) from wyze_sdk.models import (PropDef, show_unknown_key_warning) @@ -75,87 +77,70 @@ class CameraProps(object): """ @classmethod - @property def event_switch(cls) -> PropDef: return PropDef("P4", int, [0, 1]) @classmethod - @property def dongle_light_switch(cls) -> PropDef: return PropDef("P1021", int, [0, 1]) @classmethod - @property def motion_alarm_enable(cls) -> PropDef: return PropDef("P1047", int, [0, 1]) @classmethod - @property def sound_alarm_enable(cls) -> PropDef: return PropDef("P1048", int, [0, 1]) @classmethod - @property def power_switch(cls) -> PropDef: return PropDef("power_switch", int, [0, 1]) @classmethod - @property def temperature(cls) -> PropDef: return PropDef("temperature", float) @classmethod - @property def humidity(cls) -> PropDef: return PropDef("humidity", float) @classmethod - @property def comfort_standard_level(cls) -> PropDef: return PropDef("comfort_standard_level", int) @classmethod - @property def room_type(cls) -> PropDef: return PropDef("temp_humi_room_type", int) @classmethod - @property def supports_continuous_record(cls) -> PropDef: return PropDef("records_event_switch", bool, int, [0, 1]) @classmethod - @property def suppprts_motion_alarm(cls) -> PropDef: return PropDef("motion_alarm_switch", bool, int, [0, 1]) @classmethod - @property def suppprts_temperature_humidity(cls) -> PropDef: return PropDef("is_temperature_humidity", bool, int, [0, 1]) @classmethod - @property def suppprts_audio_alarm(cls) -> PropDef: return PropDef("audio_alarm_switch", bool, int, [0, 1]) @classmethod - @property def suppprts_smoke_alarm(cls) -> PropDef: return PropDef("smoke_alarm_switch", bool, int, [0, 1]) @classmethod - @property def suppprts_co_alarm(cls) -> PropDef: return PropDef("co_alarm_switch", bool, int, [0, 1]) @classmethod - @property def voltage(cls) -> PropDef: return PropDef("electricity", int) @classmethod - @property def battery_charging(cls) -> PropDef: return PropDef("battery_charging_status", int) @@ -190,14 +175,14 @@ def __init__( **others: dict ): super().__init__(type=self.type, **others) - self.switch_state = super()._extract_property(DeviceProps.power_state, others) + self.switch_state = super()._extract_property(DeviceProps.power_state(), others) self._temperature = super()._extract_attribute('temperature', others) self._humidity = super()._extract_attribute('humidity', others) - self._voltage = super()._extract_property(CameraProps.voltage, others) - self._supports_audio_alarm = super()._extract_property(CameraProps.suppprts_audio_alarm, others) - self._supports_co_alarm = super()._extract_property(CameraProps.suppprts_co_alarm, others) - self._supports_motion_alarm = super()._extract_property(CameraProps.suppprts_motion_alarm, others) - self._suppprts_smoke_alarm = super()._extract_property(CameraProps.suppprts_smoke_alarm, others) + self._voltage = super()._extract_property(CameraProps.voltage(), others) + self._supports_audio_alarm = super()._extract_property(CameraProps.suppprts_audio_alarm(), others) + self._supports_co_alarm = super()._extract_property(CameraProps.suppprts_co_alarm(), others) + self._supports_motion_alarm = super()._extract_property(CameraProps.suppprts_motion_alarm(), others) + self._suppprts_smoke_alarm = super()._extract_property(CameraProps.suppprts_smoke_alarm(), others) if event_list is not None: self.latest_events = event_list show_unknown_key_warning(self, others) diff --git a/wyze_sdk/models/devices/locks.py b/wyze_sdk/models/devices/locks.py index 7743275..260e2e3 100644 --- a/wyze_sdk/models/devices/locks.py +++ b/wyze_sdk/models/devices/locks.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from enum import Enum from typing import Optional, Sequence, Set, Tuple, Union @@ -10,12 +12,10 @@ class LockProps(object): @classmethod - @property def lock_state(cls) -> PropDef: return PropDef("switch_state", bool, int) @classmethod - @property def open_close_state(cls) -> PropDef: return PropDef("open_close_state", bool, int) @@ -251,7 +251,7 @@ def attributes(self) -> Set[str]: def parse_uuid(cls, mac: str) -> str: for model in DeviceModels.LOCK: if model in mac: - return mac.removeprefix(model + '.') + return Lock.remove_model_prefix(mac, model + '.') def __init__( self, @@ -262,8 +262,8 @@ def __init__( super().__init__(type=self.type, **others) if self.mac is not None: self._uuid = Lock.parse_uuid(self.mac) - self.lock_state = super()._extract_property(LockProps.lock_state, others) - self.open_close_state = super()._extract_property(LockProps.open_close_state, others) + self.lock_state = super()._extract_property(LockProps.lock_state(), others) + self.open_close_state = super()._extract_property(LockProps.open_close_state(), others) self._parent = parent if parent is not None else super()._extract_attribute("parent", others) self._record_count = record_count if record_count is not None else super()._extract_attribute("record_count", others) show_unknown_key_warning(self, others) @@ -297,7 +297,7 @@ def attributes(self) -> Set[str]: def parse_uuid(cls, mac: str) -> str: for model in DeviceModels.LOCK_GATEWAY: if model in mac: - return mac.removeprefix(model + '.') + return LockGateway.remove_model_prefix(mac, model + '.') def __init__( self, @@ -314,8 +314,7 @@ def __init__( ssid = super()._extract_attribute('ssid', connection) super().__init__(type=self.type, **others) if self.mac is not None: - for model in DeviceModels.LOCK_GATEWAY: - self._uuid = self.mac.removeprefix(model + '.') + self._uuid = LockGateway.parse_uuid(self.mac) self.locks = locks if locks is not None else super()._extract_attribute('locks', others) show_unknown_key_warning(self, others) diff --git a/wyze_sdk/models/devices/plugs.py b/wyze_sdk/models/devices/plugs.py index 7b17062..626ee74 100644 --- a/wyze_sdk/models/devices/plugs.py +++ b/wyze_sdk/models/devices/plugs.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import (Optional, Set, Union) from wyze_sdk.models import (PropDef, show_unknown_key_warning) @@ -7,22 +9,18 @@ class PlugProps(object): @classmethod - @property def status_light(cls) -> PropDef: return PropDef("P13", bool) @classmethod - @property def away_mode(cls) -> PropDef: return PropDef("P1614", bool) @classmethod - @property def rssi(cls) -> PropDef: return PropDef("P1612", int) @classmethod - @property def photosensitive_switch(cls) -> PropDef: return PropDef("photosensitive_switch", bool) @@ -43,10 +41,10 @@ def __init__( **others: dict, ): super().__init__(type=type, **others) - self.switch_state = self._extract_property(DeviceProps.power_state, others) + self.switch_state = self._extract_property(DeviceProps.power_state(), others) self._switch_state_timer = super()._extract_attribute("switch_state_timer", others) - self.status_light = self._extract_property(PlugProps.status_light, others) - self.away_mode = self._extract_property(PlugProps.away_mode, others) + self.status_light = self._extract_property(PlugProps.status_light(), others) + self.away_mode = self._extract_property(PlugProps.away_mode(), others) show_unknown_key_warning(self, others) @property @@ -56,7 +54,7 @@ def away_mode(self) -> bool: @away_mode.setter def away_mode(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=PlugProps.away_mode, value=value) + value = DeviceProp(definition=PlugProps.away_mode(), value=value) self._away_mode = value @property @@ -66,7 +64,7 @@ def status_light(self) -> bool: @status_light.setter def status_light(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=PlugProps.status_light, value=value) + value = DeviceProp(definition=PlugProps.status_light(), value=value) self._status_light = value @classmethod @@ -105,7 +103,7 @@ def __init__( **others: dict, ): super().__init__(type=self.type, **others) - self.photosensitive_switch = super()._extract_property(PlugProps.photosensitive_switch, others) + self.photosensitive_switch = super()._extract_property(PlugProps.photosensitive_switch(), others) show_unknown_key_warning(self, others) @property @@ -119,5 +117,5 @@ def photosensitive_switch(self) -> bool: @photosensitive_switch.setter def photosensitive_switch(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=PlugProps.photosensitive_switch, value=value) + value = DeviceProp(definition=PlugProps.photosensitive_switch(), value=value) self._photosensitive_switch = value diff --git a/wyze_sdk/models/devices/scales.py b/wyze_sdk/models/devices/scales.py index c387283..75d3a53 100644 --- a/wyze_sdk/models/devices/scales.py +++ b/wyze_sdk/models/devices/scales.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from typing import (Optional, Sequence, Set, Union) @@ -8,7 +10,6 @@ class ScaleProps(object): @classmethod - @property def unit(cls) -> PropDef: return PropDef('unit', str, acceptable_values=['kg', 'lb']) @@ -173,7 +174,7 @@ def __init__( **others: dict, ): super().__init__(type=self.type, **others) - self.unit = unit if unit else super()._extract_property(ScaleProps.unit, others) + self.unit = unit if unit else super()._extract_property(ScaleProps.unit(), others) self._broadcast = super()._extract_attribute('broadcast', others) self.goal_weight = goal_weight latest_records = latest_records if latest_records is not None else super()._extract_attribute('latest_records', others) @@ -189,7 +190,7 @@ def unit(self) -> str: @unit.setter def unit(self, value: Union[str, DeviceProp]): if isinstance(value, str): - value = DeviceProp(definition=ScaleProps.unit, value=value) + value = DeviceProp(definition=ScaleProps.unit(), value=value) self._unit = value @property diff --git a/wyze_sdk/models/devices/sensors.py b/wyze_sdk/models/devices/sensors.py index 33cc08b..b4434c5 100644 --- a/wyze_sdk/models/devices/sensors.py +++ b/wyze_sdk/models/devices/sensors.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from abc import ABCMeta from typing import (Set) @@ -12,8 +14,8 @@ class SensorProps(object): contact See: com.hualai.dws3u.device.WyzeEventSettingPage return {**Sensor.props(), **{ - "power_state": DeviceProps.power_state, # "is low battery" - "open_close_state": SensorProps.open_close_state, + "power_state": DeviceProps.power_state(), # "is low battery" + "open_close_state": SensorProps.open_close_state(), "open_notification": PropDef("P1306", bool), # "opens" "close_notification": PropDef("P1307", bool), # "closes" "open_notification_delay": PropDef("P1308", ""), # "left open" @@ -46,27 +48,22 @@ class SensorProps(object): """ @classmethod - @property def notification(cls) -> PropDef: return PropDef("P1", bool, int, [0, 1]) @classmethod - @property def rssi(cls) -> PropDef: return PropDef("P1304", int) @classmethod - @property def voltage(cls) -> PropDef: return PropDef("P1329", int) @classmethod - @property def open_close_state(cls) -> PropDef: return PropDef("P1301", bool, int, [0, 1]) @classmethod - @property def motion_state(cls) -> PropDef: return PropDef("P1302", bool, int, [0, 1]) @@ -86,8 +83,8 @@ def __init__( **others: dict, ): super().__init__(type=type, **others) - self.switch_state = self._extract_property(DeviceProps.power_state, others) - self.voltage = super()._extract_property(SensorProps.voltage, others) + self.switch_state = self._extract_property(DeviceProps.power_state(), others) + self.voltage = super()._extract_property(SensorProps.voltage(), others) class ContactSensor(ContactMixin, Sensor): @@ -105,7 +102,7 @@ def __init__( self, **others: dict, ): super().__init__(type=self.type, **others) - self.open_close_state = super()._extract_property(SensorProps.open_close_state, others) + self.open_close_state = super()._extract_property(SensorProps.open_close_state(), others) show_unknown_key_warning(self, others) @@ -124,5 +121,5 @@ def __init__( self, **others: dict, ): super().__init__(type=self.type, **others) - self.motion_state = super()._extract_property(SensorProps.motion_state, others) + self.motion_state = super()._extract_property(SensorProps.motion_state(), others) show_unknown_key_warning(self, others) diff --git a/wyze_sdk/models/devices/thermostats.py b/wyze_sdk/models/devices/thermostats.py index 1ccd952..4a820c0 100644 --- a/wyze_sdk/models/devices/thermostats.py +++ b/wyze_sdk/models/devices/thermostats.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from enum import Enum from typing import (Optional, Set, Union) @@ -9,62 +11,50 @@ class ThermostatProps(object): @classmethod - @property def temperature(cls) -> PropDef: return PropDef("temperature", float) @classmethod - @property def time_to_temp(cls) -> PropDef: return PropDef("time2temp_val", int) # in minutes @classmethod - @property def humidity(cls) -> PropDef: return PropDef("humidity", int) @classmethod - @property def fan_mode(cls) -> PropDef: return PropDef("fan_mode", str) @classmethod - @property def system_mode(cls) -> PropDef: return PropDef("mode_sys", str) @classmethod - @property def locked(cls) -> PropDef: return PropDef("kid_lock", bool, str, ['0', '1']) @classmethod - @property def heating_setpoint(cls) -> PropDef: return PropDef("heat_sp", int, str) @classmethod - @property def cooling_setpoint(cls) -> PropDef: return PropDef("cool_sp", int, str) @classmethod - @property def current_scenario(cls) -> PropDef: return PropDef("current_scenario", str) @classmethod - @property def working_state(cls) -> PropDef: return PropDef("working_state", str) @classmethod - @property def auto_switch(cls) -> PropDef: return PropDef("auto_switch_mode", int) @classmethod - @property def temperature_unit(cls) -> PropDef: return PropDef("temp_unit", str, acceptable_values=['F', 'C']) @@ -151,22 +141,22 @@ def props(cls) -> dict[str, PropDef]: return { "trigger_off_val": PropDef("trigger_off_val", int), "emheat": PropDef("emheat", int), - "temperature": ThermostatProps.temperature, - "humidity": ThermostatProps.humidity, - "time2temp_val": ThermostatProps.time_to_temp, + "temperature": ThermostatProps.temperature(), + "humidity": ThermostatProps.humidity(), + "time2temp_val": ThermostatProps.time_to_temp(), "protect_time": PropDef("protect_time", str), - "system_mode": ThermostatProps.system_mode, - "heating_setpoint": ThermostatProps.heating_setpoint, - "cooling_setpoint": ThermostatProps.cooling_setpoint, - "current_scenario": ThermostatProps.current_scenario, + "system_mode": ThermostatProps.system_mode(), + "heating_setpoint": ThermostatProps.heating_setpoint(), + "cooling_setpoint": ThermostatProps.cooling_setpoint(), + "current_scenario": ThermostatProps.current_scenario(), "config_scenario": PropDef("config_scenario", dict), - "temp_unit": ThermostatProps.temperature_unit, - "fan_mode": ThermostatProps.fan_mode, + "temp_unit": ThermostatProps.temperature_unit(), + "fan_mode": ThermostatProps.fan_mode(), "iot_state": PropDef("iot_state", str), "w_city_id": PropDef("w_city_id", int), "w_lat": PropDef("w_lat", int), "w_lon": PropDef("w_lon", int), - "working_state": ThermostatProps.working_state, + "working_state": ThermostatProps.working_state(), "device_hold": PropDef("dev_hold", int), "device_hold_time": PropDef("dev_holdtime", int), "asw_hold": PropDef("asw_hold", int), @@ -174,7 +164,7 @@ def props(cls) -> dict[str, PropDef]: "setup_state": PropDef("setup_state", int), "wiring_logic_id": PropDef("wiring_logic_id", int), "save_comfort_balance": PropDef("save_comfort_balance", int), - "locked": ThermostatProps.locked, + "locked": ThermostatProps.locked(), "calibrate_humidity": PropDef("calibrate_humidity", str), "calibrate_temperature": PropDef("calibrate_temperature", str), "fancirc_time": PropDef("fancirc_time", str), @@ -184,7 +174,7 @@ def props(cls) -> dict[str, PropDef]: @classmethod def device_info_props(cls) -> dict[str, PropDef]: return { - "auto_switch_mode": ThermostatProps.auto_switch, + "auto_switch_mode": ThermostatProps.auto_switch(), "setup_is_have_cadapter": PropDef("setup_is_have_cadapter", str), "setup_personalization_state": PropDef("setup_personalization_state", str), "setup_step": PropDef("setup_step", str), @@ -196,17 +186,17 @@ def device_info_props(cls) -> dict[str, PropDef]: def __init__(self, **others: dict): super().__init__(type=self.type, **others) - self._humidity = super()._extract_attribute(ThermostatProps.humidity.pid, others) - self._temperature = super()._extract_attribute(ThermostatProps.temperature.pid, others) - self._cooling_setpoint = super()._extract_attribute(ThermostatProps.cooling_setpoint.pid, others) - self._heating_setpoint = super()._extract_attribute(ThermostatProps.heating_setpoint.pid, others) - self.fan_mode = super()._extract_property(ThermostatProps.fan_mode, others) - self.system_mode = super()._extract_property(ThermostatProps.system_mode, others) - self.working_state = super()._extract_attribute(ThermostatProps.working_state.pid, others) - self.auto_switch_mode = super()._extract_attribute(ThermostatProps.auto_switch.pid, others) - self.lock_state = super()._extract_property(ThermostatProps.locked, others) - self._temperature_unit = super()._extract_attribute(ThermostatProps.temperature_unit.pid, others) - self.current_scenario = super()._extract_property(ThermostatProps.current_scenario, others) + self._humidity = super()._extract_attribute(ThermostatProps.humidity().pid, others) + self._temperature = super()._extract_attribute(ThermostatProps.temperature().pid, others) + self._cooling_setpoint = super()._extract_attribute(ThermostatProps.cooling_setpoint().pid, others) + self._heating_setpoint = super()._extract_attribute(ThermostatProps.heating_setpoint().pid, others) + self.fan_mode = super()._extract_property(ThermostatProps.fan_mode(), others) + self.system_mode = super()._extract_property(ThermostatProps.system_mode(), others) + self.working_state = super()._extract_attribute(ThermostatProps.working_state().pid, others) + self.auto_switch_mode = super()._extract_attribute(ThermostatProps.auto_switch().pid, others) + self.lock_state = super()._extract_property(ThermostatProps.locked(), others) + self._temperature_unit = super()._extract_attribute(ThermostatProps.temperature_unit().pid, others) + self.current_scenario = super()._extract_property(ThermostatProps.current_scenario(), others) show_unknown_key_warning(self, others) @property @@ -222,7 +212,7 @@ def fan_mode(self, value: Union[str, DeviceProp]): if value is None: return if isinstance(value, str): - value = DeviceProp(definition=ThermostatProps.fan_mode, value=value) + value = DeviceProp(definition=ThermostatProps.fan_mode(), value=value) self._fan_mode = ThermostatFanMode.parse(value.value) @property @@ -234,7 +224,7 @@ def system_mode(self, value: Union[str, DeviceProp]): if value is None: return if isinstance(value, str): - value = DeviceProp(definition=ThermostatProps.system_mode, value=value) + value = DeviceProp(definition=ThermostatProps.system_mode(), value=value) self._system_mode = ThermostatSystemMode.parse(value.value) @property @@ -246,7 +236,7 @@ def current_scenario(self, value: Union[str, DeviceProp]): if value is None: return if isinstance(value, str): - value = DeviceProp(definition=ThermostatProps.current_scenario, value=value) + value = DeviceProp(definition=ThermostatProps.current_scenario(), value=value) self._current_scenario = ThermostatScenarioType.parse(value.value) @property diff --git a/wyze_sdk/models/devices/vacuums.py b/wyze_sdk/models/devices/vacuums.py index 1896e39..2ab246f 100644 --- a/wyze_sdk/models/devices/vacuums.py +++ b/wyze_sdk/models/devices/vacuums.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from enum import Enum import logging @@ -11,27 +13,22 @@ class VacuumProps(object): @classmethod - @property def clean_level(cls) -> PropDef: return PropDef("cleanlevel", str) @classmethod - @property def sweep_record_clean_time(cls) -> PropDef: return PropDef("clean_time", int) @classmethod - @property def sweep_record_clean_size(cls) -> PropDef: return PropDef("clean_size", int) @classmethod - @property def mode(cls) -> PropDef: return PropDef("mode", int) @classmethod - @property def battery(cls) -> PropDef: return PropDef("battary", int) # typo required @@ -460,7 +457,7 @@ def clean_time(self) -> int: @clean_time.setter def clean_time(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=VacuumProps.sweep_record_clean_time, value=value) + value = DeviceProp(definition=VacuumProps.sweep_record_clean_time(), value=value) self._clean_time = value @property @@ -477,7 +474,7 @@ def clean_size(self) -> int: @clean_size.setter def clean_size(self, value: Union[int, DeviceProp]): if isinstance(value, int): - value = DeviceProp(definition=VacuumProps.sweep_record_clean_size, value=value) + value = DeviceProp(definition=VacuumProps.sweep_record_clean_size(), value=value) self._clean_size = value @property @@ -509,8 +506,8 @@ def attributes(self) -> Set[str]: def props(cls) -> dict[str, PropDef]: return { "iot_state": PropDef("iot_state", str), - "battery": VacuumProps.battery, - "mode": VacuumProps.mode, + "battery": VacuumProps.battery(), + "mode": VacuumProps.mode(), "charge_state": PropDef("chargeState", int), "clean_size": PropDef("cleanSize", int), "clean_time": PropDef("cleanTime", int), @@ -518,7 +515,7 @@ def props(cls) -> dict[str, PropDef]: "fault_code": PropDef("fault_code", int), "current_map_id": PropDef("current_mapid", int), "count": PropDef("count", int), - "clean_level": VacuumProps.clean_level, + "clean_level": VacuumProps.clean_level(), "notice_save_map": PropDef("notice_save_map", bool), "memory_map_update_time": PropDef("memory_map_update_time", int), } @@ -537,9 +534,9 @@ def __init__( **others: dict, ): super().__init__(type=self.type, **others) - self.voltage = super()._extract_property(VacuumProps.battery, others) - self.mode = super()._extract_attribute('mode' if "mode" in others else VacuumProps.mode.pid, others) - self.clean_level = super()._extract_attribute('clean_level' if "clean_level" in others else VacuumProps.clean_level.pid, others) + self.voltage = super()._extract_property(VacuumProps.battery(), others) + self.mode = super()._extract_attribute('mode' if "mode" in others else VacuumProps.mode().pid, others) + self.clean_level = super()._extract_attribute('clean_level' if "clean_level" in others else VacuumProps.clean_level().pid, others) self._current_map = VacuumMap(**super()._extract_attribute('current_map', others)) if "current_map" in others else None self.current_position = super()._extract_attribute('current_position', others) show_unknown_key_warning(self, others) @@ -575,7 +572,7 @@ def mode(self, value: Union[int, DeviceProp]): if value is None: return if isinstance(value, int): - value = DeviceProp(definition=VacuumProps.mode, value=value) + value = DeviceProp(definition=VacuumProps.mode(), value=value) self._mode = VacuumMode.parse(code=value.value) @property @@ -587,5 +584,5 @@ def clean_level(self, value: Union[str, int, DeviceProp]): if value is None: return if isinstance(value, (str, int)): - value = DeviceProp(definition=VacuumProps.clean_level, value=value) + value = DeviceProp(definition=VacuumProps.clean_level(), value=value) self._clean_level = VacuumSuctionLevel.parse(code=value.value) diff --git a/wyze_sdk/models/events/__init__.py b/wyze_sdk/models/events/__init__.py index bccf6f5..05f21d4 100644 --- a/wyze_sdk/models/events/__init__.py +++ b/wyze_sdk/models/events/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from enum import Enum import logging diff --git a/wyze_sdk/service/api_service.py b/wyze_sdk/service/api_service.py index cb6a448..945b800 100644 --- a/wyze_sdk/service/api_service.py +++ b/wyze_sdk/service/api_service.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging from datetime import datetime, timedelta diff --git a/wyze_sdk/service/auth_service.py b/wyze_sdk/service/auth_service.py index 9bbc96f..ad2d68a 100644 --- a/wyze_sdk/service/auth_service.py +++ b/wyze_sdk/service/auth_service.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Dict, Optional from wyze_sdk.signature import RequestVerifier diff --git a/wyze_sdk/service/base.py b/wyze_sdk/service/base.py index 9490159..f3adebb 100644 --- a/wyze_sdk/service/base.py +++ b/wyze_sdk/service/base.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging import platform import sys diff --git a/wyze_sdk/service/earth_service.py b/wyze_sdk/service/earth_service.py index a1219de..508b6ee 100644 --- a/wyze_sdk/service/earth_service.py +++ b/wyze_sdk/service/earth_service.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Optional, Sequence, Tuple, Union from .base import ExServiceClient, WyzeResponse diff --git a/wyze_sdk/service/ford_service.py b/wyze_sdk/service/ford_service.py index 5634afd..65d35e7 100644 --- a/wyze_sdk/service/ford_service.py +++ b/wyze_sdk/service/ford_service.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime import logging import urllib diff --git a/wyze_sdk/service/general_api_service.py b/wyze_sdk/service/general_api_service.py index 61143fb..a1ad53d 100644 --- a/wyze_sdk/service/general_api_service.py +++ b/wyze_sdk/service/general_api_service.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Dict, Optional from .base import BaseServiceClient, WyzeResponse diff --git a/wyze_sdk/service/platform_service.py b/wyze_sdk/service/platform_service.py index 9b97bf7..d0dfdbf 100644 --- a/wyze_sdk/service/platform_service.py +++ b/wyze_sdk/service/platform_service.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Optional, Sequence, Tuple, Union from .base import ExServiceClient, WyzeResponse diff --git a/wyze_sdk/service/scale_service.py b/wyze_sdk/service/scale_service.py index f4cecf1..641e53b 100644 --- a/wyze_sdk/service/scale_service.py +++ b/wyze_sdk/service/scale_service.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from typing import Optional, Sequence, Tuple, Union diff --git a/wyze_sdk/service/venus_service.py b/wyze_sdk/service/venus_service.py index 8c0f680..56eed25 100644 --- a/wyze_sdk/service/venus_service.py +++ b/wyze_sdk/service/venus_service.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import datetime from typing import Optional, Sequence, Tuple, Union diff --git a/wyze_sdk/service/wyze_response.py b/wyze_sdk/service/wyze_response.py index 05b0344..2792883 100644 --- a/wyze_sdk/service/wyze_response.py +++ b/wyze_sdk/service/wyze_response.py @@ -1,4 +1,5 @@ """A Python module for interacting and consuming responses from Wyze.""" +from __future__ import annotations import logging from typing import Union diff --git a/wyze_sdk/version.py b/wyze_sdk/version.py index 7863915..6849410 100644 --- a/wyze_sdk/version.py +++ b/wyze_sdk/version.py @@ -1 +1 @@ -__version__ = "1.0.2" +__version__ = "1.1.0"