diff --git a/homeassistant/components/tuya/camera.py b/homeassistant/components/tuya/camera.py index 3790f470b78..36b69885b2e 100644 --- a/homeassistant/components/tuya/camera.py +++ b/homeassistant/components/tuya/camera.py @@ -9,7 +9,11 @@ from tuya_device_handlers.definition.camera import ( from tuya_sharing import CustomerDevice, Manager from homeassistant.components import ffmpeg -from homeassistant.components.camera import Camera as CameraEntity, CameraEntityFeature +from homeassistant.components.camera import ( + Camera as CameraEntity, + CameraEntityDescription, + CameraEntityFeature, +) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -18,10 +22,10 @@ from . import TuyaConfigEntry from .const import TUYA_DISCOVERY_NEW, DeviceCategory from .entity import TuyaEntity -CAMERAS: tuple[DeviceCategory, ...] = ( - DeviceCategory.DGHSXJ, - DeviceCategory.SP, -) +CAMERAS: dict[DeviceCategory, CameraEntityDescription] = { + DeviceCategory.DGHSXJ: CameraEntityDescription(key=""), + DeviceCategory.SP: CameraEntityDescription(key=""), +} async def async_setup_entry( @@ -38,9 +42,11 @@ async def async_setup_entry( entities: list[TuyaCameraEntity] = [] for device_id in device_ids: device = manager.device_map[device_id] - if device.category in CAMERAS: + if description := CAMERAS.get(device.category): entities.append( - TuyaCameraEntity(device, manager, get_default_definition(device)) + TuyaCameraEntity( + device, manager, description, get_default_definition(device) + ) ) async_add_entities(entities) @@ -63,10 +69,11 @@ class TuyaCameraEntity(TuyaEntity, CameraEntity): self, device: CustomerDevice, device_manager: Manager, + description: CameraEntityDescription, definition: TuyaCameraDefinition, ) -> None: """Init Tuya Camera.""" - super().__init__(device, device_manager) + super().__init__(device, device_manager, description) CameraEntity.__init__(self) self._attr_model = device.product_name self._motion_detection_switch = definition.motion_detection_switch diff --git a/homeassistant/components/tuya/entity.py b/homeassistant/components/tuya/entity.py index 33c729e9179..7ebe9aaf416 100644 --- a/homeassistant/components/tuya/entity.py +++ b/homeassistant/components/tuya/entity.py @@ -24,17 +24,15 @@ class TuyaEntity(Entity): self, device: CustomerDevice, device_manager: Manager, - description: EntityDescription | None = None, + description: EntityDescription, ) -> None: """Init TuyaHaEntity.""" - self._attr_unique_id = f"tuya.{device.id}" + self._attr_unique_id = f"tuya.{device.id}{description.key}" + self.entity_description = description # TuyaEntity initialize mq can subscribe device.set_up = True self.device = device self.device_manager = device_manager - if description: - self._attr_unique_id = f"tuya.{device.id}{description.key}" - self.entity_description = description @property def device_info(self) -> DeviceInfo: diff --git a/homeassistant/components/tuya/fan.py b/homeassistant/components/tuya/fan.py index baf3b74e71a..5d0db0adc67 100644 --- a/homeassistant/components/tuya/fan.py +++ b/homeassistant/components/tuya/fan.py @@ -15,6 +15,7 @@ from homeassistant.components.fan import ( DIRECTION_FORWARD, DIRECTION_REVERSE, FanEntity, + FanEntityDescription, FanEntityFeature, ) from homeassistant.core import HomeAssistant, callback @@ -25,13 +26,13 @@ from . import TuyaConfigEntry from .const import TUYA_DISCOVERY_NEW, DeviceCategory from .entity import TuyaEntity -TUYA_SUPPORT_TYPE: set[DeviceCategory] = { - DeviceCategory.CS, - DeviceCategory.FS, - DeviceCategory.FSD, - DeviceCategory.FSKG, - DeviceCategory.KJ, - DeviceCategory.KS, +FANS: dict[DeviceCategory, FanEntityDescription] = { + DeviceCategory.CS: FanEntityDescription(key=""), + DeviceCategory.FS: FanEntityDescription(key=""), + DeviceCategory.FSD: FanEntityDescription(key=""), + DeviceCategory.FSKG: FanEntityDescription(key=""), + DeviceCategory.KJ: FanEntityDescription(key=""), + DeviceCategory.KS: FanEntityDescription(key=""), } _TUYA_TO_HA_DIRECTION_MAPPINGS = { @@ -57,10 +58,10 @@ async def async_setup_entry( entities: list[TuyaFanEntity] = [] for device_id in device_ids: device = manager.device_map[device_id] - if device.category in TUYA_SUPPORT_TYPE and ( + if (description := FANS.get(device.category)) and ( definition := get_default_definition(device) ): - entities.append(TuyaFanEntity(device, manager, definition)) + entities.append(TuyaFanEntity(device, manager, description, definition)) async_add_entities(entities) async_discover_device([*manager.device_map]) @@ -79,10 +80,11 @@ class TuyaFanEntity(TuyaEntity, FanEntity): self, device: CustomerDevice, device_manager: Manager, + description: FanEntityDescription, definition: TuyaFanDefinition, ) -> None: """Init Tuya Fan Device.""" - super().__init__(device, device_manager) + super().__init__(device, device_manager, description) self._direction_wrapper = definition.direction_wrapper self._mode_wrapper = definition.mode_wrapper self._oscillate_wrapper = definition.oscillate_wrapper diff --git a/homeassistant/components/tuya/vacuum.py b/homeassistant/components/tuya/vacuum.py index f6e7b79bcdd..ef2eba4a5fa 100644 --- a/homeassistant/components/tuya/vacuum.py +++ b/homeassistant/components/tuya/vacuum.py @@ -16,6 +16,7 @@ from tuya_sharing import CustomerDevice, Manager from homeassistant.components.vacuum import ( StateVacuumEntity, + StateVacuumEntityDescription, VacuumActivity, VacuumEntityFeature, ) @@ -36,6 +37,10 @@ _TUYA_TO_HA_ACTIVITY_MAPPINGS = { TuyaVacuumActivity.ERROR: VacuumActivity.ERROR, } +VACUUMS: dict[DeviceCategory, StateVacuumEntityDescription] = { + DeviceCategory.SD: StateVacuumEntityDescription(key=""), +} + async def async_setup_entry( hass: HomeAssistant, @@ -51,9 +56,11 @@ async def async_setup_entry( entities: list[TuyaVacuumEntity] = [] for device_id in device_ids: device = manager.device_map[device_id] - if device.category == DeviceCategory.SD: + if description := VACUUMS.get(device.category): entities.append( - TuyaVacuumEntity(device, manager, get_default_definition(device)) + TuyaVacuumEntity( + device, manager, description, get_default_definition(device) + ) ) async_add_entities(entities) @@ -73,10 +80,11 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity): self, device: CustomerDevice, device_manager: Manager, + description: StateVacuumEntityDescription, definition: TuyaVacuumDefinition, ) -> None: """Init Tuya vacuum.""" - super().__init__(device, device_manager) + super().__init__(device, device_manager, description) self._action_wrapper = definition.action_wrapper self._activity_wrapper = definition.activity_wrapper self._fan_speed_wrapper = definition.fan_speed_wrapper