Tweaks to Tuya base entity (#57526)

This commit is contained in:
Franck Nijhof 2021-10-12 12:25:03 +02:00 committed by GitHub
parent d90d804260
commit c943677675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ from typing import Any
from tuya_iot import TuyaDevice, TuyaDeviceManager from tuya_iot import TuyaDevice, TuyaDeviceManager
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from .const import DOMAIN, TUYA_HA_SIGNAL_UPDATE_ENTITY from .const import DOMAIN, TUYA_HA_SIGNAL_UPDATE_ENTITY
@ -28,21 +28,21 @@ class TuyaHaEntity(Entity):
return self.tuya_device.name return self.tuya_device.name
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return a device description for device registry.""" """Return a device description for device registry."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, f"{self.tuya_device.id}")}, identifiers={(DOMAIN, self.tuya_device.id)},
"manufacturer": "Tuya", manufacturer="Tuya",
"name": self.tuya_device.name, name=self.tuya_device.name,
"model": self.tuya_device.product_name, model=self.tuya_device.product_name,
} )
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Return if the device is available.""" """Return if the device is available."""
return self.tuya_device.online return self.tuya_device.online
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Call when entity is added to hass.""" """Call when entity is added to hass."""
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(