Skip to content

Commit 67171ab

Browse files
committed
Use nicer types for the presets version.
1 parent f0e4b45 commit 67171ab

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/wled/wled.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
from .const import LiveDataOverride
3232

3333

34+
@dataclass
35+
class _PresetsVersion:
36+
presets_modified_timestamp: int
37+
boot_time: int
38+
39+
3440
@dataclass
3541
class WLED:
3642
"""Main class for handling connections with WLED."""
@@ -42,7 +48,7 @@ class WLED:
4248
_client: aiohttp.ClientWebSocketResponse | None = None
4349
_close_session: bool = False
4450
_device: Device | None = None
45-
_presets_version: tuple[int, int] | None = None
51+
_presets_version: _PresetsVersion | None = None
4652

4753
@property
4854
def connected(self) -> bool:
@@ -724,7 +730,7 @@ async def __aexit__(self, *_exc_info: object) -> None:
724730

725731
def _check_presets_version(
726732
self, device_data: Any
727-
) -> tuple[bool, tuple[int, int] | None]:
733+
) -> tuple[bool, _PresetsVersion | None]:
728734
"""Check if the presets have possibly been changed since last check.
729735
730736
Returns
@@ -749,7 +755,9 @@ def _check_presets_version(
749755
uptime_seconds = int(uptime)
750756
current_time_seconds = int(time.time())
751757
boot_time_approx = current_time_seconds - uptime_seconds
752-
new_version = (presets_modified_timestamp, int(boot_time_approx))
758+
new_version = _PresetsVersion(
759+
presets_modified_timestamp, int(boot_time_approx)
760+
)
753761

754762
# Presets are the same if the presets last modified timestamp has not been
755763
# modified. Since the last modified timestamp is only stored in memory, it
@@ -764,8 +772,9 @@ def _check_presets_version(
764772
# around boot.
765773
changed = (
766774
self._presets_version is None
767-
or self._presets_version[0] != new_version[0]
768-
or abs(self._presets_version[1] - new_version[1]) > 2
775+
or self._presets_version.presets_modified_timestamp
776+
!= new_version.presets_modified_timestamp
777+
or abs(self._presets_version.boot_time - new_version.boot_time) > 2
769778
)
770779
except ValueError:
771780
# In case of a parse failure, assume presets might have changed

0 commit comments

Comments
 (0)