FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Stabilise on_since value for smart devices by sdb9696 · Pull Request #1144 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 10 additions & 1 deletion kasa/smart/smartdevice.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
self._children: Mapping[str, SmartDevice] = {}
self._last_update = {}
self._last_update_time: float | None = None
self._on_since: datetime | None = None

async def _initialize_children(self):
"""Initialize children for power strips."""
Expand Down Expand Up @@ -502,7 +503,15 @@ def on_since(self) -> datetime | None:
return None
Comment thread
rytilahti marked this conversation as resolved.
Resolved

on_time = cast(float, on_time)
return self.time - timedelta(seconds=on_time)
on_since = self.time - timedelta(seconds=on_time)
# Ensure slight variations between time module and on_time do not cause
# the on_since time to change. More likely to happen with child devices
# or P100s that do not do multi-queries.
if not self._on_since or timedelta(
seconds=0
) < on_since - self._on_since > timedelta(seconds=5):
self._on_since = on_since
return self._on_since

@property
def timezone(self) -> dict:
Expand Down

Back | FazBrowse Home | New Git URL