diff --git a/homeassistant/components/netatmo/sensor.py b/homeassistant/components/netatmo/sensor.py index 4e470437f7a..6e96a73135f 100644 --- a/homeassistant/components/netatmo/sensor.py +++ b/homeassistant/components/netatmo/sensor.py @@ -67,6 +67,17 @@ from .helper import NetatmoArea _LOGGER = logging.getLogger(__name__) +DIRECTION_OPTIONS = [ + "n", + "ne", + "e", + "se", + "s", + "sw", + "w", + "nw", +] + def process_health(health: StateType) -> str | None: """Process health index and return string for display.""" @@ -199,6 +210,9 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = ( NetatmoSensorEntityDescription( key="windangle", netatmo_name="wind_direction", + device_class=SensorDeviceClass.ENUM, + options=DIRECTION_OPTIONS, + value_fn=lambda x: x.lower() if isinstance(x, str) else None, ), NetatmoSensorEntityDescription( key="windangle_value", @@ -218,6 +232,9 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = ( key="gustangle", netatmo_name="gust_direction", entity_registry_enabled_default=False, + device_class=SensorDeviceClass.ENUM, + options=DIRECTION_OPTIONS, + value_fn=lambda x: x.lower() if isinstance(x, str) else None, ), NetatmoSensorEntityDescription( key="gustangle_value", diff --git a/homeassistant/components/netatmo/strings.json b/homeassistant/components/netatmo/strings.json index f6aba92d005..b8840c27006 100644 --- a/homeassistant/components/netatmo/strings.json +++ b/homeassistant/components/netatmo/strings.json @@ -185,13 +185,33 @@ "name": "Precipitation today" }, "wind_direction": { - "name": "Wind direction" + "name": "Wind direction", + "state": { + "n": "North", + "ne": "North-east", + "e": "East", + "se": "South-east", + "s": "South", + "sw": "South-west", + "w": "West", + "nw": "North-west" + } }, "wind_angle": { "name": "Wind angle" }, "gust_direction": { - "name": "Gust direction" + "name": "Gust direction", + "state": { + "n": "[%key:component::netatmo::entity::sensor::wind_direction::state::n%]", + "ne": "[%key:component::netatmo::entity::sensor::wind_direction::state::ne%]", + "e": "[%key:component::netatmo::entity::sensor::wind_direction::state::e%]", + "se": "[%key:component::netatmo::entity::sensor::wind_direction::state::se%]", + "s": "[%key:component::netatmo::entity::sensor::wind_direction::state::s%]", + "sw": "[%key:component::netatmo::entity::sensor::wind_direction::state::sw%]", + "w": "[%key:component::netatmo::entity::sensor::wind_direction::state::w%]", + "nw": "[%key:component::netatmo::entity::sensor::wind_direction::state::nw%]" + } }, "gust_angle": { "name": "Gust angle" diff --git a/tests/components/netatmo/snapshots/test_sensor.ambr b/tests/components/netatmo/snapshots/test_sensor.ambr index ed5f4decc86..b6dacb1911c 100644 --- a/tests/components/netatmo/snapshots/test_sensor.ambr +++ b/tests/components/netatmo/snapshots/test_sensor.ambr @@ -6073,7 +6073,18 @@ 'aliases': set({ }), 'area_id': None, - 'capabilities': None, + 'capabilities': dict({ + 'options': list([ + 'n', + 'ne', + 'e', + 'se', + 's', + 'sw', + 'w', + 'nw', + ]), + }), 'config_entry_id': , 'device_class': None, 'device_id': , @@ -6090,7 +6101,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, 'original_name': 'Gust direction', 'platform': 'netatmo', @@ -6105,14 +6116,25 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'attribution': 'Data provided by Netatmo', + 'device_class': 'enum', 'friendly_name': 'Villa Garden Gust direction', + 'options': list([ + 'n', + 'ne', + 'e', + 'se', + 's', + 'sw', + 'w', + 'nw', + ]), }), 'context': , 'entity_id': 'sensor.villa_garden_gust_direction', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'S', + 'state': 's', }) # --- # name: test_entity[sensor.villa_garden_gust_strength-entry] @@ -6317,7 +6339,18 @@ 'aliases': set({ }), 'area_id': None, - 'capabilities': None, + 'capabilities': dict({ + 'options': list([ + 'n', + 'ne', + 'e', + 'se', + 's', + 'sw', + 'w', + 'nw', + ]), + }), 'config_entry_id': , 'device_class': None, 'device_id': , @@ -6334,7 +6367,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, 'original_name': 'Wind direction', 'platform': 'netatmo', @@ -6349,14 +6382,25 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'attribution': 'Data provided by Netatmo', + 'device_class': 'enum', 'friendly_name': 'Villa Garden Wind direction', + 'options': list([ + 'n', + 'ne', + 'e', + 'se', + 's', + 'sw', + 'w', + 'nw', + ]), }), 'context': , 'entity_id': 'sensor.villa_garden_wind_direction', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'SW', + 'state': 'sw', }) # --- # name: test_entity[sensor.villa_garden_wind_speed-entry] diff --git a/tests/components/netatmo/test_sensor.py b/tests/components/netatmo/test_sensor.py index d2cc20b8394..4a6233e17e1 100644 --- a/tests/components/netatmo/test_sensor.py +++ b/tests/components/netatmo/test_sensor.py @@ -165,17 +165,17 @@ async def test_process_health(health: int, expected: str) -> None: ), ("12:34:56:80:c1:ea-sum_rain_1", "villa_rain_rain_last_hour", "0"), ("12:34:56:80:c1:ea-sum_rain_24", "villa_rain_rain_today", "6.9"), - ("12:34:56:03:1b:e4-windangle", "netatmoindoor_garden_direction", "SW"), + ("12:34:56:03:1b:e4-windangle", "netatmoindoor_garden_direction", "sw"), ( "12:34:56:03:1b:e4-windangle_value", "netatmoindoor_garden_angle", "217", ), - ("12:34:56:03:1b:e4-gustangle", "mystation_garden_gust_direction", "S"), + ("12:34:56:03:1b:e4-gustangle", "mystation_garden_gust_direction", "s"), ( "12:34:56:03:1b:e4-gustangle", "netatmoindoor_garden_gust_direction", - "S", + "s", ), ( "12:34:56:03:1b:e4-gustangle_value",