Skip to content

Commit

Permalink
Added support for python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Tarves committed Apr 28, 2021
1 parent bf71293 commit 284172f
Show file tree
Hide file tree
Showing 29 changed files with 149 additions and 158 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ flake8 = "*"
isort = "*"

[requires]
python_version = "3.9"
python_version = "3.8"
6 changes: 3 additions & 3 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
url="https://github.com/shauntarves/wyze-sdk",
author='Shaun Tarves',
author_email='[email protected]',
python_requires=">=3.9.0",
python_requires=">=3.8.0",
include_package_data=True,
license="The Unlicense",
classifiers=[
Expand All @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions wyze_sdk/api/devices/bulbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions wyze_sdk/api/devices/plugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions wyze_sdk/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion wyze_sdk/models/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 13 additions & 8 deletions wyze_sdk/models/devices/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import distutils.util
import logging
from abc import ABCMeta
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):

Expand Down
42 changes: 18 additions & 24 deletions wyze_sdk/models/devices/bulbs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import (Optional, Set, Union)

from wyze_sdk.errors import WyzeFeatureNotSupportedError
Expand All @@ -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])

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(),
}}
Loading

0 comments on commit 284172f

Please sign in to comment.