Add Self typing (4) [mypy 1.0] (#87601)

This commit is contained in:
Marc Mueller 2023-02-07 05:30:22 +01:00 committed by GitHub
parent f7b39aa4a8
commit ea4e2ab4aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 32 additions and 19 deletions

View file

@ -8,6 +8,7 @@ import struct
from typing import Any, Literal, overload
from tuya_iot import TuyaDevice, TuyaDeviceManager
from typing_extensions import Self
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo, Entity
@ -112,12 +113,12 @@ class ElectricityTypeData:
voltage: str | None = None
@classmethod
def from_json(cls, data: str) -> ElectricityTypeData:
def from_json(cls, data: str) -> Self:
"""Load JSON string and return a ElectricityTypeData object."""
return cls(**json.loads(data.lower()))
@classmethod
def from_raw(cls, data: str) -> ElectricityTypeData:
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