1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-22 23:17:47 +01:00

Filter unsupported features and convert sensor data to float

This commit is contained in:
Felipe Martins Diel 2021-01-11 02:25:50 -03:00
parent 4169b265d6
commit 055d7f77ad

View File

@ -311,6 +311,18 @@ class sp4b(sp4):
device.__init__(self, *args, **kwargs)
self.type = "SP4B"
def get_state(self) -> dict:
"""Get full state of device."""
state = super().get_state()
# Convert sensor data to float. Remove keys if sensors are not supported.
sensor_attrs = ["current", "volt", "power", "totalconsum", "overload"]
for attr in sensor_attrs:
value = state.pop(attr, -1)
if value != -1:
state[attr] = value / 1000
return state
def _encode(self, flag: int, state: dict) -> bytes:
"""Encode a message."""
payload = json.dumps(state, separators=(",", ":")).encode()