Updated the support of Tuya Circuit Breaker 'dlq' (#63519)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
10e2caf9e6
commit
77ccf46c9b
4 changed files with 104 additions and 1 deletions
|
@ -1,8 +1,10 @@
|
|||
"""Tuya Home Assistant Base Device Model."""
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
from dataclasses import dataclass
|
||||
import json
|
||||
import struct
|
||||
from typing import Any
|
||||
|
||||
from tuya_iot import TuyaDevice, TuyaDeviceManager
|
||||
|
@ -99,6 +101,17 @@ class ElectricityTypeData:
|
|||
"""Load JSON string and return a ElectricityTypeData object."""
|
||||
return cls(**json.loads(data.lower()))
|
||||
|
||||
@classmethod
|
||||
def from_raw(cls, data: str) -> ElectricityTypeData:
|
||||
"""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
|
||||
return cls(
|
||||
electriccurrent=str(electriccurrent), power=str(power), voltage=str(voltage)
|
||||
)
|
||||
|
||||
|
||||
class TuyaEntity(Entity):
|
||||
"""Tuya base device."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue