From d5b1173941244628d910adc2c2cd09e92272be17 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Wed, 19 Jan 2022 18:46:45 -0500 Subject: [PATCH 1/3] Add cloud fallback for color bulbs --- src/wyzeapy/services/base_service.py | 7 +++---- src/wyzeapy/services/bulb_service.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/wyzeapy/services/base_service.py b/src/wyzeapy/services/base_service.py index 4068b9c..cdd2ca0 100644 --- a/src/wyzeapy/services/base_service.py +++ b/src/wyzeapy/services/base_service.py @@ -115,12 +115,10 @@ async def get_object_list(self) -> List[Device]: response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/home_page/get_object_list", json=payload) - check_for_errors_standard(response_json) # Cache the devices so that update calls can pull more recent device_params BaseService._devices = [Device(device) for device in response_json['data']['device_list']] - return BaseService._devices async def get_updated_params(self, device_mac: str = None) -> Dict[str, Optional[Any]]: @@ -163,7 +161,6 @@ async def _get_property_list(self, device: Device) -> List[Tuple[PropertyIDs, An check_for_errors_standard(response_json) properties = response_json['data']['property_list'] - property_list = [] for prop in properties: try: @@ -610,4 +607,6 @@ async def _local_bulb_command(self, bulb, plist): async with session.post(url, data=payload_str) as response: print(await response.text()) except aiohttp.ClientConnectionError: - _LOGGER.warning("Failed to connect to bulb %s" % bulb.mac) + _LOGGER.warning("Failed to connect to bulb %s, reverting to cloud." % bulb.mac) + await self._set_property_list(bulb, plist) + bulb.cloud_fallback = True diff --git a/src/wyzeapy/services/bulb_service.py b/src/wyzeapy/services/bulb_service.py index 8327642..359472a 100644 --- a/src/wyzeapy/services/bulb_service.py +++ b/src/wyzeapy/services/bulb_service.py @@ -21,6 +21,7 @@ class Bulb(Device): enr: str on: bool = False + cloud_fallback = False def __init__(self, dictionary: Dict[Any, Any]): super().__init__(dictionary) @@ -119,7 +120,10 @@ async def turn_on(self, bulb: Bulb, options=None): elif ( bulb.type in [DeviceTypes.MESH_LIGHT, DeviceTypes.LIGHTSTRIP] ): - await self._local_bulb_command(bulb, plist) + if not bulb.cloud_fallback: + await self._local_bulb_command(bulb, plist) + else: + await self._set_property_list(bulb, plist) async def turn_off(self, bulb: Bulb): plist = [ @@ -133,7 +137,10 @@ async def turn_off(self, bulb: Bulb): elif ( bulb.type in [DeviceTypes.MESH_LIGHT, DeviceTypes.LIGHTSTRIP] ): - await self._local_bulb_command(bulb, plist) + if not bulb.cloud_fallback: + await self._local_bulb_command(bulb, plist) + else: + await self._set_property_list(bulb, plist) async def set_color_temp(self, bulb: Bulb, color_temp: int): plist = [ From 52e04988db6e79cceb44805168450b775203a7c1 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Fri, 21 Jan 2022 11:34:45 -0500 Subject: [PATCH 2/3] blank lines --- src/wyzeapy/services/base_service.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wyzeapy/services/base_service.py b/src/wyzeapy/services/base_service.py index cdd2ca0..a0defe3 100644 --- a/src/wyzeapy/services/base_service.py +++ b/src/wyzeapy/services/base_service.py @@ -115,10 +115,12 @@ async def get_object_list(self) -> List[Device]: response_json = await self._auth_lib.post("https://api.wyzecam.com/app/v2/home_page/get_object_list", json=payload) + check_for_errors_standard(response_json) # Cache the devices so that update calls can pull more recent device_params BaseService._devices = [Device(device) for device in response_json['data']['device_list']] + return BaseService._devices async def get_updated_params(self, device_mac: str = None) -> Dict[str, Optional[Any]]: @@ -161,6 +163,7 @@ async def _get_property_list(self, device: Device) -> List[Tuple[PropertyIDs, An check_for_errors_standard(response_json) properties = response_json['data']['property_list'] + property_list = [] for prop in properties: try: From 971775531d21706749dc0dc965c3adf21c94fdf5 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Mon, 24 Jan 2022 15:48:39 -0500 Subject: [PATCH 3/3] use run_action_list --- src/wyzeapy/services/base_service.py | 2 +- src/wyzeapy/services/bulb_service.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wyzeapy/services/base_service.py b/src/wyzeapy/services/base_service.py index a0defe3..990b4e4 100644 --- a/src/wyzeapy/services/base_service.py +++ b/src/wyzeapy/services/base_service.py @@ -611,5 +611,5 @@ async def _local_bulb_command(self, bulb, plist): print(await response.text()) except aiohttp.ClientConnectionError: _LOGGER.warning("Failed to connect to bulb %s, reverting to cloud." % bulb.mac) - await self._set_property_list(bulb, plist) + await self._run_action_list(bulb, plist) bulb.cloud_fallback = True diff --git a/src/wyzeapy/services/bulb_service.py b/src/wyzeapy/services/bulb_service.py index 359472a..587ed14 100644 --- a/src/wyzeapy/services/bulb_service.py +++ b/src/wyzeapy/services/bulb_service.py @@ -123,7 +123,7 @@ async def turn_on(self, bulb: Bulb, options=None): if not bulb.cloud_fallback: await self._local_bulb_command(bulb, plist) else: - await self._set_property_list(bulb, plist) + await self._run_action_list(bulb, plist) async def turn_off(self, bulb: Bulb): plist = [ @@ -140,7 +140,7 @@ async def turn_off(self, bulb: Bulb): if not bulb.cloud_fallback: await self._local_bulb_command(bulb, plist) else: - await self._set_property_list(bulb, plist) + await self._run_action_list(bulb, plist) async def set_color_temp(self, bulb: Bulb, color_temp: int): plist = [