Updated the support of Tuya Circuit Breaker 'dlq' (#63519)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Dmitry Vasilyev 2022-01-06 15:01:16 +04:00 committed by GitHub
parent 10e2caf9e6
commit 77ccf46c9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 1 deletions

View file

@ -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."""