From 119d0c576a8bbfc63a5492b8a09f631c1ef1c8d8 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 16 May 2025 13:39:03 +0200 Subject: [PATCH] Add hood fan speed capability to SmartThings (#144919) --- .../components/smartthings/number.py | 68 ++++++++++++++++++- .../components/smartthings/strings.json | 3 + .../smartthings/snapshots/test_number.ambr | 56 +++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/smartthings/number.py b/homeassistant/components/smartthings/number.py index 0a9b5dcb03f..1ad9486903a 100644 --- a/homeassistant/components/smartthings/number.py +++ b/homeassistant/components/smartthings/number.py @@ -21,11 +21,21 @@ async def async_setup_entry( ) -> None: """Add number entities for a config entry.""" entry_data = entry.runtime_data - async_add_entities( + entities: list[NumberEntity] = [ SmartThingsWasherRinseCyclesNumberEntity(entry_data.client, device) for device in entry_data.devices.values() if Capability.CUSTOM_WASHER_RINSE_CYCLES in device.status[MAIN] + ] + entities.extend( + SmartThingsHoodNumberEntity(entry_data.client, device) + for device in entry_data.devices.values() + if ( + (hood_component := device.status.get("hood")) is not None + and Capability.SAMSUNG_CE_HOOD_FAN_SPEED in hood_component + and Capability.SAMSUNG_CE_CONNECTION_STATE not in hood_component + ) ) + async_add_entities(entities) class SmartThingsWasherRinseCyclesNumberEntity(SmartThingsEntity, NumberEntity): @@ -76,3 +86,59 @@ class SmartThingsWasherRinseCyclesNumberEntity(SmartThingsEntity, NumberEntity): Command.SET_WASHER_RINSE_CYCLES, str(int(value)), ) + + +class SmartThingsHoodNumberEntity(SmartThingsEntity, NumberEntity): + """Define a SmartThings number.""" + + _attr_translation_key = "hood_fan_speed" + _attr_native_step = 1.0 + _attr_mode = NumberMode.SLIDER + _attr_entity_category = EntityCategory.CONFIG + + def __init__(self, client: SmartThings, device: FullDevice) -> None: + """Initialize the instance.""" + super().__init__( + client, device, {Capability.SAMSUNG_CE_HOOD_FAN_SPEED}, component="hood" + ) + self._attr_unique_id = f"{device.device.device_id}_hood_{Capability.SAMSUNG_CE_HOOD_FAN_SPEED}_{Attribute.HOOD_FAN_SPEED}_{Attribute.HOOD_FAN_SPEED}" + + @property + def options(self) -> list[int]: + """Return the list of options.""" + min_value = self.get_attribute_value( + Capability.SAMSUNG_CE_HOOD_FAN_SPEED, + Attribute.SETTABLE_MIN_FAN_SPEED, + ) + max_value = self.get_attribute_value( + Capability.SAMSUNG_CE_HOOD_FAN_SPEED, + Attribute.SETTABLE_MAX_FAN_SPEED, + ) + return list(range(min_value, max_value + 1)) + + @property + def native_value(self) -> int: + """Return the current value.""" + return int( + self.get_attribute_value( + Capability.SAMSUNG_CE_HOOD_FAN_SPEED, Attribute.HOOD_FAN_SPEED + ) + ) + + @property + def native_min_value(self) -> float: + """Return the minimum value.""" + return min(self.options) + + @property + def native_max_value(self) -> float: + """Return the maximum value.""" + return max(self.options) + + async def async_set_native_value(self, value: float) -> None: + """Set the value.""" + await self.execute_device_command( + Capability.SAMSUNG_CE_HOOD_FAN_SPEED, + Command.SET_HOOD_FAN_SPEED, + int(value), + ) diff --git a/homeassistant/components/smartthings/strings.json b/homeassistant/components/smartthings/strings.json index 1113083c00f..96fec1fb0e8 100644 --- a/homeassistant/components/smartthings/strings.json +++ b/homeassistant/components/smartthings/strings.json @@ -105,6 +105,9 @@ "washer_rinse_cycles": { "name": "Rinse cycles", "unit_of_measurement": "cycles" + }, + "hood_fan_speed": { + "name": "Fan speed" } }, "select": { diff --git a/tests/components/smartthings/snapshots/test_number.ambr b/tests/components/smartthings/snapshots/test_number.ambr index ee8dd42712a..8832336a1fa 100644 --- a/tests/components/smartthings/snapshots/test_number.ambr +++ b/tests/components/smartthings/snapshots/test_number.ambr @@ -1,4 +1,60 @@ # serializer version: 1 +# name: test_all_entities[da_ks_microwave_0101x][number.microwave_fan_speed-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'max': 3, + 'min': 0, + 'mode': , + 'step': 1.0, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'number', + 'entity_category': , + 'entity_id': 'number.microwave_fan_speed', + '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': 'Fan speed', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'hood_fan_speed', + 'unique_id': '2bad3237-4886-e699-1b90-4a51a3d55c8a_hood_samsungce.hoodFanSpeed_hoodFanSpeed_hoodFanSpeed', + 'unit_of_measurement': None, + }) +# --- +# name: test_all_entities[da_ks_microwave_0101x][number.microwave_fan_speed-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Microwave Fan speed', + 'max': 3, + 'min': 0, + 'mode': , + 'step': 1.0, + }), + 'context': , + 'entity_id': 'number.microwave_fan_speed', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0', + }) +# --- # name: test_all_entities[da_wm_wm_000001][number.washer_rinse_cycles-entry] EntityRegistryEntrySnapshot({ 'aliases': set({