Skip to content

Commit

Permalink
Add boot_id, energy_since_boot and time_since_boot (fixes #48) (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabian Affolter <[email protected]>
  • Loading branch information
slyoldfox and fabaff authored Dec 25, 2024
1 parent 0d62b65 commit 32ad31c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## next release

- Add boot_id, energy_since_boot and time_since_boot to switch (thanks @slyoldfox)
- Expose `device_type` property on switches

## 2.2.0 (2023-05-21)
Expand Down
33 changes: 33 additions & 0 deletions pymystrom/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, host: str, session: aiohttp.client.ClientSession = None) -> N
self._session = session
self._consumption = 0
self._consumedWs = 0
self._boot_id = None
self._energy_since_boot = None
self._time_since_boot = None
self._state = None
self._temperature = None
self._firmware = None
Expand Down Expand Up @@ -56,6 +59,18 @@ async def get_state(self) -> None:
self._consumedWs = response["Ws"]
except KeyError:
self._consumedWs = None
try:
self._boot_id = response["boot_id"]
except KeyError:
self._boot_id = None
try:
self._energy_since_boot = response["energy_since_boot"]
except KeyError:
self._energy_since_boot = None
try:
self._time_since_boot = response["time_since_boot"]
except KeyError:
self._time_since_boot = None
self._state = response["relay"]
try:
self._temperature = response["temperature"]
Expand Down Expand Up @@ -103,6 +118,24 @@ def consumedWs(self) -> Optional[float]:
return round(self._consumedWs, 1)

return self._consumedWs

@property
def boot_id(self) -> Optional[str]:
"""A unique identifier to distinguish whether the energy counter has been reset."""
return self._boot_id

@property
def energy_since_boot(self) -> Optional[float]:
"""The total energy in watt seconds (Ws) that has been measured since the last power-up or restart of the device."""
if self._energy_since_boot is not None:
return round(self._energy_since_boot, 2)

return self._energy_since_boot

@property
def time_since_boot(self) -> Optional[int]:
"""The time in seconds that has elapsed since the last start or restart of the device."""
return self._time_since_boot

@property
def firmware(self) -> Optional[str]:
Expand Down

0 comments on commit 32ad31c

Please sign in to comment.