Skip to content

Commit

Permalink
Update base.py
Browse files Browse the repository at this point in the history
  • Loading branch information
azerty9971 committed Sep 1, 2024
1 parent a59c935 commit c83cd1c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions homeassistant/components/tuya/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ def from_json(cls, data: str) -> Self:
def from_raw(cls, data: str) -> Self:
"""Decode base64 string and return a ElectricityTypeData object."""
raw = base64.b64decode(data)
voltage = struct.unpack(">H", raw[0:2])[0] / 10.0
electriccurrent = struct.unpack(">L", b"\x00" + raw[2:5])[0] / 1000.0
power = struct.unpack(">L", b"\x00" + raw[5:8])[0] / 1000.0
try:
voltage = struct.unpack(">H", raw[0:2])[0] / 10.0
electriccurrent = struct.unpack(">L", b"\x00" + raw[2:5])[0] / 1000.0
power = struct.unpack(">L", b"\x00" + raw[5:8])[0] / 1000.0
except:

Check failure on line 129 in homeassistant/components/tuya/base.py

View workflow job for this annotation

GitHub Actions / Check ruff

Ruff (E722)

homeassistant/components/tuya/base.py:129:9: E722 Do not use bare `except`
LOGGER.warning(f"Failed UNPACK: {data}")
return cls(
electriccurrent=str(electriccurrent), power=str(power), voltage=str(voltage)
)
Expand Down

0 comments on commit c83cd1c

Please sign in to comment.