1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-21 22:51:41 +01:00

Filter unsupported features and convert sensor data to float (#495)

This commit is contained in:
Felipe Martins Diel 2021-01-11 02:25:50 -03:00
parent c3bb598e27
commit 448e3026df

View File

@ -312,6 +312,18 @@ class sp4b(sp4):
device.__init__(self, *args, **kwargs) device.__init__(self, *args, **kwargs)
self.type = "SP4B" 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: def _encode(self, flag: int, state: dict) -> bytes:
"""Encode a message.""" """Encode a message."""
payload = json.dumps(state, separators=(",", ":")).encode() payload = json.dumps(state, separators=(",", ":")).encode()