diff --git a/homeassistant/components/smartthings/icons.json b/homeassistant/components/smartthings/icons.json index 394035aafb6..54dee9b29d2 100644 --- a/homeassistant/components/smartthings/icons.json +++ b/homeassistant/components/smartthings/icons.json @@ -31,6 +31,9 @@ "number": { "washer_rinse_cycles": { "default": "mdi:waves-arrow-up" + }, + "freezer_temperature": { + "default": "mdi:snowflake-thermometer" } }, "select": { diff --git a/homeassistant/components/smartthings/number.py b/homeassistant/components/smartthings/number.py index 1ad9486903a..6ac2f60d7a9 100644 --- a/homeassistant/components/smartthings/number.py +++ b/homeassistant/components/smartthings/number.py @@ -4,13 +4,13 @@ from __future__ import annotations from pysmartthings import Attribute, Capability, Command, SmartThings -from homeassistant.components.number import NumberEntity, NumberMode +from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from . import FullDevice, SmartThingsConfigEntry -from .const import MAIN +from .const import MAIN, UNIT_MAP from .entity import SmartThingsEntity @@ -35,6 +35,15 @@ async def async_setup_entry( and Capability.SAMSUNG_CE_CONNECTION_STATE not in hood_component ) ) + entities.extend( + SmartThingsRefrigeratorTemperatureNumberEntity( + entry_data.client, device, component + ) + for device in entry_data.devices.values() + for component in device.status + if component in ("cooler", "freezer") + and Capability.THERMOSTAT_COOLING_SETPOINT in device.status[component] + ) async_add_entities(entities) @@ -142,3 +151,69 @@ class SmartThingsHoodNumberEntity(SmartThingsEntity, NumberEntity): Command.SET_HOOD_FAN_SPEED, int(value), ) + + +class SmartThingsRefrigeratorTemperatureNumberEntity(SmartThingsEntity, NumberEntity): + """Define a SmartThings number.""" + + _attr_entity_category = EntityCategory.CONFIG + _attr_device_class = NumberDeviceClass.TEMPERATURE + + def __init__(self, client: SmartThings, device: FullDevice, component: str) -> None: + """Initialize the instance.""" + super().__init__( + client, + device, + {Capability.THERMOSTAT_COOLING_SETPOINT}, + component=component, + ) + self._attr_unique_id = f"{device.device.device_id}_{component}_{Capability.THERMOSTAT_COOLING_SETPOINT}_{Attribute.COOLING_SETPOINT}_{Attribute.COOLING_SETPOINT}" + unit = self._internal_state[Capability.THERMOSTAT_COOLING_SETPOINT][ + Attribute.COOLING_SETPOINT + ].unit + assert unit is not None + self._attr_native_unit_of_measurement = UNIT_MAP[unit] + self._attr_translation_key = { + "cooler": "cooler_temperature", + "freezer": "freezer_temperature", + }[component] + + @property + def range(self) -> dict[str, int]: + """Return the list of options.""" + return self.get_attribute_value( + Capability.THERMOSTAT_COOLING_SETPOINT, + Attribute.COOLING_SETPOINT_RANGE, + ) + + @property + def native_value(self) -> int: + """Return the current value.""" + return int( + self.get_attribute_value( + Capability.THERMOSTAT_COOLING_SETPOINT, Attribute.COOLING_SETPOINT + ) + ) + + @property + def native_min_value(self) -> float: + """Return the minimum value.""" + return self.range["minimum"] + + @property + def native_max_value(self) -> float: + """Return the maximum value.""" + return self.range["maximum"] + + @property + def native_step(self) -> float: + """Return the step value.""" + return self.range["step"] + + async def async_set_native_value(self, value: float) -> None: + """Set the value.""" + await self.execute_device_command( + Capability.THERMOSTAT_COOLING_SETPOINT, + Command.SET_COOLING_SETPOINT, + int(value), + ) diff --git a/homeassistant/components/smartthings/strings.json b/homeassistant/components/smartthings/strings.json index 4bcd7463b42..4005e769bc5 100644 --- a/homeassistant/components/smartthings/strings.json +++ b/homeassistant/components/smartthings/strings.json @@ -108,6 +108,15 @@ }, "hood_fan_speed": { "name": "Fan speed" + }, + "freezer_temperature": { + "name": "Freezer temperature" + }, + "cooler_temperature": { + "name": "Cooler temperature" + }, + "cool_select_plus_temperature": { + "name": "CoolSelect+ temperature" } }, "select": { diff --git a/tests/components/smartthings/snapshots/test_number.ambr b/tests/components/smartthings/snapshots/test_number.ambr index 8832336a1fa..34073173861 100644 --- a/tests/components/smartthings/snapshots/test_number.ambr +++ b/tests/components/smartthings/snapshots/test_number.ambr @@ -55,6 +55,354 @@ 'state': '0', }) # --- +# name: test_all_entities[da_ref_normal_000001][number.refrigerator_cooler_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'max': 7.0, + 'min': 1.0, + 'mode': , + 'step': 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'number', + 'entity_category': , + 'entity_id': 'number.refrigerator_cooler_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Cooler temperature', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'cooler_temperature', + 'unique_id': '7db87911-7dce-1cf2-7119-b953432a2f09_cooler_thermostatCoolingSetpoint_coolingSetpoint_coolingSetpoint', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[da_ref_normal_000001][number.refrigerator_cooler_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'Refrigerator Cooler temperature', + 'max': 7.0, + 'min': 1.0, + 'mode': , + 'step': 1, + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'number.refrigerator_cooler_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '3.0', + }) +# --- +# name: test_all_entities[da_ref_normal_000001][number.refrigerator_freezer_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'max': -15.0, + 'min': -23.0, + 'mode': , + 'step': 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'number', + 'entity_category': , + 'entity_id': 'number.refrigerator_freezer_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Freezer temperature', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'freezer_temperature', + 'unique_id': '7db87911-7dce-1cf2-7119-b953432a2f09_freezer_thermostatCoolingSetpoint_coolingSetpoint_coolingSetpoint', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[da_ref_normal_000001][number.refrigerator_freezer_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'Refrigerator Freezer temperature', + 'max': -15.0, + 'min': -23.0, + 'mode': , + 'step': 1, + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'number.refrigerator_freezer_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '-18.0', + }) +# --- +# name: test_all_entities[da_ref_normal_01001][number.refrigerator_cooler_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'max': 7.0, + 'min': 1.0, + 'mode': , + 'step': 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'number', + 'entity_category': , + 'entity_id': 'number.refrigerator_cooler_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Cooler temperature', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'cooler_temperature', + 'unique_id': '7d3feb98-8a36-4351-c362-5e21ad3a78dd_cooler_thermostatCoolingSetpoint_coolingSetpoint_coolingSetpoint', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[da_ref_normal_01001][number.refrigerator_cooler_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'Refrigerator Cooler temperature', + 'max': 7.0, + 'min': 1.0, + 'mode': , + 'step': 1, + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'number.refrigerator_cooler_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '3.0', + }) +# --- +# name: test_all_entities[da_ref_normal_01001][number.refrigerator_freezer_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'max': -15.0, + 'min': -23.0, + 'mode': , + 'step': 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'number', + 'entity_category': , + 'entity_id': 'number.refrigerator_freezer_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Freezer temperature', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'freezer_temperature', + 'unique_id': '7d3feb98-8a36-4351-c362-5e21ad3a78dd_freezer_thermostatCoolingSetpoint_coolingSetpoint_coolingSetpoint', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[da_ref_normal_01001][number.refrigerator_freezer_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'Refrigerator Freezer temperature', + 'max': -15.0, + 'min': -23.0, + 'mode': , + 'step': 1, + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'number.refrigerator_freezer_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '-18.0', + }) +# --- +# name: test_all_entities[da_ref_normal_01011][number.frigo_cooler_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'max': 7, + 'min': 1, + 'mode': , + 'step': 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'number', + 'entity_category': , + 'entity_id': 'number.frigo_cooler_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Cooler temperature', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'cooler_temperature', + 'unique_id': '5758b2ec-563e-f39b-ec39-208e54aabf60_cooler_thermostatCoolingSetpoint_coolingSetpoint_coolingSetpoint', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[da_ref_normal_01011][number.frigo_cooler_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'Frigo Cooler temperature', + 'max': 7, + 'min': 1, + 'mode': , + 'step': 1, + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'number.frigo_cooler_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '6', + }) +# --- +# name: test_all_entities[da_ref_normal_01011][number.frigo_freezer_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'max': -15, + 'min': -23, + 'mode': , + 'step': 1, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'number', + 'entity_category': , + 'entity_id': 'number.frigo_freezer_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Freezer temperature', + 'platform': 'smartthings', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'freezer_temperature', + 'unique_id': '5758b2ec-563e-f39b-ec39-208e54aabf60_freezer_thermostatCoolingSetpoint_coolingSetpoint_coolingSetpoint', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[da_ref_normal_01011][number.frigo_freezer_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'Frigo Freezer temperature', + 'max': -15, + 'min': -23, + 'mode': , + 'step': 1, + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'number.frigo_freezer_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '-17', + }) +# --- # name: test_all_entities[da_wm_wm_000001][number.washer_rinse_cycles-entry] EntityRegistryEntrySnapshot({ 'aliases': set({