diff --git a/homeassistant/components/netatmo/sensor.py b/homeassistant/components/netatmo/sensor.py index 6e96a73135f..fd40bbf88b6 100644 --- a/homeassistant/components/netatmo/sensor.py +++ b/homeassistant/components/netatmo/sensor.py @@ -83,15 +83,12 @@ def process_health(health: StateType) -> str | None: """Process health index and return string for display.""" if not isinstance(health, int): return None - if health == 0: - return "Healthy" - if health == 1: - return "Fine" - if health == 2: - return "Fair" - if health == 3: - return "Poor" - return "Unhealthy" + return { + 0: "healthy", + 1: "fine", + 2: "fair", + 3: "poor", + }.get(health, "unhealthy") def process_rf(strength: StateType) -> str | None: @@ -274,6 +271,8 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = ( NetatmoSensorEntityDescription( key="health_idx", netatmo_name="health_idx", + device_class=SensorDeviceClass.ENUM, + options=["healthy", "fine", "fair", "poor", "unhealthy"], value_fn=process_health, ), NetatmoSensorEntityDescription( diff --git a/homeassistant/components/netatmo/strings.json b/homeassistant/components/netatmo/strings.json index b8840c27006..3c360634147 100644 --- a/homeassistant/components/netatmo/strings.json +++ b/homeassistant/components/netatmo/strings.json @@ -229,7 +229,14 @@ "name": "Wi-Fi" }, "health_idx": { - "name": "Health index" + "name": "Health index", + "state": { + "healthy": "Healthy", + "fine": "Fine", + "fair": "Fair", + "poor": "Poor", + "unhealthy": "Unhealthy" + } } } } diff --git a/tests/components/netatmo/snapshots/test_sensor.ambr b/tests/components/netatmo/snapshots/test_sensor.ambr index b6dacb1911c..0684956adb8 100644 --- a/tests/components/netatmo/snapshots/test_sensor.ambr +++ b/tests/components/netatmo/snapshots/test_sensor.ambr @@ -118,7 +118,15 @@ 'aliases': set({ }), 'area_id': None, - 'capabilities': None, + 'capabilities': dict({ + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), + }), 'config_entry_id': , 'device_class': None, 'device_id': , @@ -135,7 +143,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, 'original_name': 'Health index', 'platform': 'netatmo', @@ -150,16 +158,24 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'attribution': 'Data provided by Netatmo', + 'device_class': 'enum', 'friendly_name': 'Baby Bedroom Health index', 'latitude': 13.377726, 'longitude': 52.516263, + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), }), 'context': , 'entity_id': 'sensor.baby_bedroom_health_index', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'Fine', + 'state': 'fine', }) # --- # name: test_entity[sensor.baby_bedroom_humidity-entry] @@ -638,7 +654,15 @@ 'aliases': set({ }), 'area_id': None, - 'capabilities': None, + 'capabilities': dict({ + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), + }), 'config_entry_id': , 'device_class': None, 'device_id': , @@ -655,7 +679,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, 'original_name': 'Health index', 'platform': 'netatmo', @@ -670,7 +694,15 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'attribution': 'Data provided by Netatmo', + 'device_class': 'enum', 'friendly_name': 'Bedroom Health index', + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), }), 'context': , 'entity_id': 'sensor.bedroom_health_index', @@ -2845,7 +2877,15 @@ 'aliases': set({ }), 'area_id': None, - 'capabilities': None, + 'capabilities': dict({ + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), + }), 'config_entry_id': , 'device_class': None, 'device_id': , @@ -2862,7 +2902,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, 'original_name': 'Health index', 'platform': 'netatmo', @@ -2877,9 +2917,17 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'attribution': 'Data provided by Netatmo', + 'device_class': 'enum', 'friendly_name': 'Kitchen Health index', 'latitude': 13.377726, 'longitude': 52.516263, + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), }), 'context': , 'entity_id': 'sensor.kitchen_health_index', @@ -3916,7 +3964,15 @@ 'aliases': set({ }), 'area_id': None, - 'capabilities': None, + 'capabilities': dict({ + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), + }), 'config_entry_id': , 'device_class': None, 'device_id': , @@ -3933,7 +3989,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, 'original_name': 'Health index', 'platform': 'netatmo', @@ -3948,9 +4004,17 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'attribution': 'Data provided by Netatmo', + 'device_class': 'enum', 'friendly_name': 'Livingroom Health index', 'latitude': 13.377726, 'longitude': 52.516263, + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), }), 'context': , 'entity_id': 'sensor.livingroom_health_index', @@ -4440,7 +4504,15 @@ 'aliases': set({ }), 'area_id': None, - 'capabilities': None, + 'capabilities': dict({ + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), + }), 'config_entry_id': , 'device_class': None, 'device_id': , @@ -4457,7 +4529,7 @@ 'name': None, 'options': dict({ }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, 'original_name': 'Health index', 'platform': 'netatmo', @@ -4472,16 +4544,24 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'attribution': 'Data provided by Netatmo', + 'device_class': 'enum', 'friendly_name': 'Parents Bedroom Health index', 'latitude': 13.377726, 'longitude': 52.516263, + 'options': list([ + 'healthy', + 'fine', + 'fair', + 'poor', + 'unhealthy', + ]), }), 'context': , 'entity_id': 'sensor.parents_bedroom_health_index', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'Fine', + 'state': 'fine', }) # --- # name: test_entity[sensor.parents_bedroom_humidity-entry] diff --git a/tests/components/netatmo/test_sensor.py b/tests/components/netatmo/test_sensor.py index 4a6233e17e1..4fa64e59b11 100644 --- a/tests/components/netatmo/test_sensor.py +++ b/tests/components/netatmo/test_sensor.py @@ -136,7 +136,7 @@ async def test_process_rf(strength: int, expected: str) -> None: @pytest.mark.parametrize( ("health", "expected"), - [(4, "Unhealthy"), (3, "Poor"), (2, "Fair"), (1, "Fine"), (0, "Healthy")], + [(4, "unhealthy"), (3, "poor"), (2, "fair"), (1, "fine"), (0, "healthy")], ) async def test_process_health(health: int, expected: str) -> None: """Test health index translation.""" @@ -195,7 +195,7 @@ async def test_process_health(health: int, expected: str) -> None: ( "12:34:56:26:68:92-health_idx", "baby_bedroom_health", - "Fine", + "fine", ), ( "12:34:56:26:68:92-wifi_status",