Add hood fan speed capability to SmartThings (#144919)

This commit is contained in:
Joost Lekkerkerker 2025-05-16 13:39:03 +02:00 committed by GitHub
parent 38cee53999
commit 119d0c576a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 126 additions and 1 deletions

View File

@ -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),
)

View File

@ -105,6 +105,9 @@
"washer_rinse_cycles": {
"name": "Rinse cycles",
"unit_of_measurement": "cycles"
},
"hood_fan_speed": {
"name": "Fan speed"
}
},
"select": {

View File

@ -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': <NumberMode.SLIDER: 'slider'>,
'step': 1.0,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'number',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'number.microwave_fan_speed',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'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': <NumberMode.SLIDER: 'slider'>,
'step': 1.0,
}),
'context': <ANY>,
'entity_id': 'number.microwave_fan_speed',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0',
})
# ---
# name: test_all_entities[da_wm_wm_000001][number.washer_rinse_cycles-entry]
EntityRegistryEntrySnapshot({
'aliases': set({