Skip to content

Commit 32ad31c

Browse files
slyoldfoxfabaff
andauthored
Add boot_id, energy_since_boot and time_since_boot (fixes #48) (#50)
Co-authored-by: Fabian Affolter <[email protected]>
1 parent 0d62b65 commit 32ad31c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## next release
44

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

78
## 2.2.0 (2023-05-21)

pymystrom/switch.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def __init__(self, host: str, session: aiohttp.client.ClientSession = None) -> N
1717
self._session = session
1818
self._consumption = 0
1919
self._consumedWs = 0
20+
self._boot_id = None
21+
self._energy_since_boot = None
22+
self._time_since_boot = None
2023
self._state = None
2124
self._temperature = None
2225
self._firmware = None
@@ -56,6 +59,18 @@ async def get_state(self) -> None:
5659
self._consumedWs = response["Ws"]
5760
except KeyError:
5861
self._consumedWs = None
62+
try:
63+
self._boot_id = response["boot_id"]
64+
except KeyError:
65+
self._boot_id = None
66+
try:
67+
self._energy_since_boot = response["energy_since_boot"]
68+
except KeyError:
69+
self._energy_since_boot = None
70+
try:
71+
self._time_since_boot = response["time_since_boot"]
72+
except KeyError:
73+
self._time_since_boot = None
5974
self._state = response["relay"]
6075
try:
6176
self._temperature = response["temperature"]
@@ -103,6 +118,24 @@ def consumedWs(self) -> Optional[float]:
103118
return round(self._consumedWs, 1)
104119

105120
return self._consumedWs
121+
122+
@property
123+
def boot_id(self) -> Optional[str]:
124+
"""A unique identifier to distinguish whether the energy counter has been reset."""
125+
return self._boot_id
126+
127+
@property
128+
def energy_since_boot(self) -> Optional[float]:
129+
"""The total energy in watt seconds (Ws) that has been measured since the last power-up or restart of the device."""
130+
if self._energy_since_boot is not None:
131+
return round(self._energy_since_boot, 2)
132+
133+
return self._energy_since_boot
134+
135+
@property
136+
def time_since_boot(self) -> Optional[int]:
137+
"""The time in seconds that has elapsed since the last start or restart of the device."""
138+
return self._time_since_boot
106139

107140
@property
108141
def firmware(self) -> Optional[str]:

0 commit comments

Comments
 (0)