Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud fallback when local control is unavailable #35

Merged
merged 3 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/wyzeapy/services/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,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._run_action_list(bulb, plist)
bulb.cloud_fallback = True
11 changes: 9 additions & 2 deletions src/wyzeapy/services/bulb_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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._run_action_list(bulb, plist)

async def turn_off(self, bulb: Bulb):
plist = [
Expand All @@ -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._run_action_list(bulb, plist)

async def set_color_temp(self, bulb: Bulb, color_temp: int):
plist = [
Expand Down