Skip to content

Commit

Permalink
Wait to state and power updates to send color state on legacy firmware (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Aug 12, 2023
1 parent afda9d3 commit 3f7f306
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions flux_led/aiodevice.py
@@ -1,6 +1,7 @@
import asyncio
import logging
import time
from asyncio import ALL_COMPLETED, FIRST_COMPLETED
from datetime import datetime
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

Expand Down Expand Up @@ -198,9 +199,11 @@ async def _async_send_state_query(self) -> None:
async def _async_wait_state_change(
self, futures: List["asyncio.Future[Any]"], state: bool, timeout: float
) -> bool:
done, _ = await asyncio.wait(
futures, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
)
# If the device requires the two step turn on, we need to wait for the
# power state and the state update. If its the single step turn on, we
# only need to wait for any future.
return_when = ALL_COMPLETED if self.requires_turn_on else FIRST_COMPLETED
done, _ = await asyncio.wait(futures, timeout=timeout, return_when=return_when)
return bool(done and self.is_on == state)

async def _async_set_power_state(
Expand Down
3 changes: 2 additions & 1 deletion flux_led/models_db.py
Expand Up @@ -737,8 +737,9 @@ def protocol_for_version_num(self, version_num: int) -> str:
),
LEDENETModel(
model_num=0x07,
# "AK001-ZJ2101" == v1.06
# "AK001-ZJ2146" == v2.06 has RF remote support
models=["AK001-ZJ2146"],
models=["AK001-ZJ2101", "AK001-ZJ2146"],
description="Controller RGBCW",
always_writes_white_and_colors=False, # Formerly rgbwprotocol
protocols=[
Expand Down
2 changes: 1 addition & 1 deletion flux_led/sock.py
Expand Up @@ -13,7 +13,7 @@
from .device import WifiLedBulb


def _socket_retry(attempts: int = DEFAULT_RETRIES) -> WrapFuncType: # type: ignore[type-var]
def _socket_retry(attempts: int = DEFAULT_RETRIES) -> WrapFuncType: # type: ignore[type-var, misc]
"""Define a wrapper to retry on socket failures."""

def decorator_retry(func: WrapFuncType) -> WrapFuncType:
Expand Down

0 comments on commit 3f7f306

Please sign in to comment.