Skip to content

Commit 5ebfb1f

Browse files
committed
Filter unsupported features and convert sensor data to float
1 parent 69afcd7 commit 5ebfb1f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

broadlink/switch.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,18 @@ def __init__(self, *args, **kwargs) -> None:
312312
device.__init__(self, *args, **kwargs)
313313
self.type = "SP4B"
314314

315+
def get_state(self) -> dict:
316+
"""Get full state of device."""
317+
state = super().get_state()
318+
319+
# Convert sensor data to float. Remove keys if sensors are not supported.
320+
sensor_attrs = ["current", "volt", "power", "totalconsum", "overload"]
321+
for attr in sensor_attrs:
322+
value = state.pop(attr, -1)
323+
if value != -1:
324+
state[attr] = value / 1000
325+
return state
326+
315327
def _encode(self, flag: int, state: dict) -> bytes:
316328
"""Encode a message."""
317329
payload = json.dumps(state, separators=(",", ":")).encode()

0 commit comments

Comments
 (0)