diff --git a/homeassistant/components/smartthings/select.py b/homeassistant/components/smartthings/select.py index 4fcd7fd080f..39a49da2bbe 100644 --- a/homeassistant/components/smartthings/select.py +++ b/homeassistant/components/smartthings/select.py @@ -32,6 +32,8 @@ class SmartThingsSelectDescription(SelectEntityDescription): command: Command options_map: dict[str, str] | None = None default_options: list[str] | None = None + extra_components: list[str] | None = None + capability_ignore_list: list[Capability] | None = None CAPABILITIES_TO_SELECT: dict[Capability | str, SmartThingsSelectDescription] = { @@ -88,6 +90,8 @@ CAPABILITIES_TO_SELECT: dict[Capability | str, SmartThingsSelectDescription] = { command=Command.SET_BRIGHTNESS_LEVEL, options_map=LAMP_TO_HA, entity_category=EntityCategory.CONFIG, + extra_components=["hood"], + capability_ignore_list=[Capability.SAMSUNG_CE_CONNECTION_STATE], ), } @@ -100,12 +104,25 @@ async def async_setup_entry( """Add select entities for a config entry.""" entry_data = entry.runtime_data async_add_entities( - SmartThingsSelectEntity( - entry_data.client, device, CAPABILITIES_TO_SELECT[capability] - ) + SmartThingsSelectEntity(entry_data.client, device, description, component) + for capability, description in CAPABILITIES_TO_SELECT.items() for device in entry_data.devices.values() - for capability in device.status[MAIN] - if capability in CAPABILITIES_TO_SELECT + for component in device.status + if capability in device.status[component] + and ( + component == MAIN + or ( + description.extra_components is not None + and component in description.extra_components + ) + ) + and ( + description.capability_ignore_list is None + or any( + capability not in device.status[component] + for capability in description.capability_ignore_list + ) + ) ) @@ -119,14 +136,15 @@ class SmartThingsSelectEntity(SmartThingsEntity, SelectEntity): client: SmartThings, device: FullDevice, entity_description: SmartThingsSelectDescription, + component: str, ) -> None: """Initialize the instance.""" capabilities = {entity_description.key} if entity_description.requires_remote_control_status: capabilities.add(Capability.REMOTE_CONTROL_STATUS) - super().__init__(client, device, capabilities) + super().__init__(client, device, capabilities, component=component) self.entity_description = entity_description - self._attr_unique_id = f"{device.device.device_id}_{MAIN}_{entity_description.key}_{entity_description.status_attribute}_{entity_description.status_attribute}" + self._attr_unique_id = f"{device.device.device_id}_{component}_{entity_description.key}_{entity_description.status_attribute}_{entity_description.status_attribute}" @property def options(self) -> list[str]: diff --git a/tests/components/smartthings/snapshots/test_select.ambr b/tests/components/smartthings/snapshots/test_select.ambr index b2c3234847e..c1093bbd209 100644 --- a/tests/components/smartthings/snapshots/test_select.ambr +++ b/tests/components/smartthings/snapshots/test_select.ambr @@ -1,4 +1,62 @@ # serializer version: 1 +# name: test_all_entities[da_ks_microwave_0101x][select.microwave_lamp-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'off', + 'low', + 'high', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'select', + 'entity_category': , + 'entity_id': 'select.microwave_lamp', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Lamp', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'lamp', + 'unique_id': '2bad3237-4886-e699-1b90-4a51a3d55c8a_hood_samsungce.lamp_brightnessLevel_brightnessLevel', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[da_ks_microwave_0101x][select.microwave_lamp-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Microwave Lamp', + 'options': list([ + 'off', + 'low', + 'high', + ]), + }), + 'context': , + 'entity_id': 'select.microwave_lamp', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_all_entities[da_ks_oven_01061][select.oven_lamp-entry] EntityRegistryEntrySnapshot({ 'aliases': set({