Use enum device class in Netatmo health index sensor (#115409)
This commit is contained in:
parent
6cc2b1e10a
commit
adafdb2b2d
4 changed files with 110 additions and 24 deletions
|
@ -83,15 +83,12 @@ def process_health(health: StateType) -> str | None:
|
||||||
"""Process health index and return string for display."""
|
"""Process health index and return string for display."""
|
||||||
if not isinstance(health, int):
|
if not isinstance(health, int):
|
||||||
return None
|
return None
|
||||||
if health == 0:
|
return {
|
||||||
return "Healthy"
|
0: "healthy",
|
||||||
if health == 1:
|
1: "fine",
|
||||||
return "Fine"
|
2: "fair",
|
||||||
if health == 2:
|
3: "poor",
|
||||||
return "Fair"
|
}.get(health, "unhealthy")
|
||||||
if health == 3:
|
|
||||||
return "Poor"
|
|
||||||
return "Unhealthy"
|
|
||||||
|
|
||||||
|
|
||||||
def process_rf(strength: StateType) -> str | None:
|
def process_rf(strength: StateType) -> str | None:
|
||||||
|
@ -274,6 +271,8 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
|
||||||
NetatmoSensorEntityDescription(
|
NetatmoSensorEntityDescription(
|
||||||
key="health_idx",
|
key="health_idx",
|
||||||
netatmo_name="health_idx",
|
netatmo_name="health_idx",
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
options=["healthy", "fine", "fair", "poor", "unhealthy"],
|
||||||
value_fn=process_health,
|
value_fn=process_health,
|
||||||
),
|
),
|
||||||
NetatmoSensorEntityDescription(
|
NetatmoSensorEntityDescription(
|
||||||
|
|
|
@ -229,7 +229,14 @@
|
||||||
"name": "Wi-Fi"
|
"name": "Wi-Fi"
|
||||||
},
|
},
|
||||||
"health_idx": {
|
"health_idx": {
|
||||||
"name": "Health index"
|
"name": "Health index",
|
||||||
|
"state": {
|
||||||
|
"healthy": "Healthy",
|
||||||
|
"fine": "Fine",
|
||||||
|
"fair": "Fair",
|
||||||
|
"poor": "Poor",
|
||||||
|
"unhealthy": "Unhealthy"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,15 @@
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
'area_id': None,
|
'area_id': None,
|
||||||
'capabilities': None,
|
'capabilities': dict({
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
|
}),
|
||||||
'config_entry_id': <ANY>,
|
'config_entry_id': <ANY>,
|
||||||
'device_class': None,
|
'device_class': None,
|
||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
|
@ -135,7 +143,7 @@
|
||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': None,
|
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Health index',
|
'original_name': 'Health index',
|
||||||
'platform': 'netatmo',
|
'platform': 'netatmo',
|
||||||
|
@ -150,16 +158,24 @@
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'attribution': 'Data provided by Netatmo',
|
'attribution': 'Data provided by Netatmo',
|
||||||
|
'device_class': 'enum',
|
||||||
'friendly_name': 'Baby Bedroom Health index',
|
'friendly_name': 'Baby Bedroom Health index',
|
||||||
'latitude': 13.377726,
|
'latitude': 13.377726,
|
||||||
'longitude': 52.516263,
|
'longitude': 52.516263,
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.baby_bedroom_health_index',
|
'entity_id': 'sensor.baby_bedroom_health_index',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'Fine',
|
'state': 'fine',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_entity[sensor.baby_bedroom_humidity-entry]
|
# name: test_entity[sensor.baby_bedroom_humidity-entry]
|
||||||
|
@ -638,7 +654,15 @@
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
'area_id': None,
|
'area_id': None,
|
||||||
'capabilities': None,
|
'capabilities': dict({
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
|
}),
|
||||||
'config_entry_id': <ANY>,
|
'config_entry_id': <ANY>,
|
||||||
'device_class': None,
|
'device_class': None,
|
||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
|
@ -655,7 +679,7 @@
|
||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': None,
|
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Health index',
|
'original_name': 'Health index',
|
||||||
'platform': 'netatmo',
|
'platform': 'netatmo',
|
||||||
|
@ -670,7 +694,15 @@
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'attribution': 'Data provided by Netatmo',
|
'attribution': 'Data provided by Netatmo',
|
||||||
|
'device_class': 'enum',
|
||||||
'friendly_name': 'Bedroom Health index',
|
'friendly_name': 'Bedroom Health index',
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.bedroom_health_index',
|
'entity_id': 'sensor.bedroom_health_index',
|
||||||
|
@ -2845,7 +2877,15 @@
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
'area_id': None,
|
'area_id': None,
|
||||||
'capabilities': None,
|
'capabilities': dict({
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
|
}),
|
||||||
'config_entry_id': <ANY>,
|
'config_entry_id': <ANY>,
|
||||||
'device_class': None,
|
'device_class': None,
|
||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
|
@ -2862,7 +2902,7 @@
|
||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': None,
|
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Health index',
|
'original_name': 'Health index',
|
||||||
'platform': 'netatmo',
|
'platform': 'netatmo',
|
||||||
|
@ -2877,9 +2917,17 @@
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'attribution': 'Data provided by Netatmo',
|
'attribution': 'Data provided by Netatmo',
|
||||||
|
'device_class': 'enum',
|
||||||
'friendly_name': 'Kitchen Health index',
|
'friendly_name': 'Kitchen Health index',
|
||||||
'latitude': 13.377726,
|
'latitude': 13.377726,
|
||||||
'longitude': 52.516263,
|
'longitude': 52.516263,
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.kitchen_health_index',
|
'entity_id': 'sensor.kitchen_health_index',
|
||||||
|
@ -3916,7 +3964,15 @@
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
'area_id': None,
|
'area_id': None,
|
||||||
'capabilities': None,
|
'capabilities': dict({
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
|
}),
|
||||||
'config_entry_id': <ANY>,
|
'config_entry_id': <ANY>,
|
||||||
'device_class': None,
|
'device_class': None,
|
||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
|
@ -3933,7 +3989,7 @@
|
||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': None,
|
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Health index',
|
'original_name': 'Health index',
|
||||||
'platform': 'netatmo',
|
'platform': 'netatmo',
|
||||||
|
@ -3948,9 +4004,17 @@
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'attribution': 'Data provided by Netatmo',
|
'attribution': 'Data provided by Netatmo',
|
||||||
|
'device_class': 'enum',
|
||||||
'friendly_name': 'Livingroom Health index',
|
'friendly_name': 'Livingroom Health index',
|
||||||
'latitude': 13.377726,
|
'latitude': 13.377726,
|
||||||
'longitude': 52.516263,
|
'longitude': 52.516263,
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.livingroom_health_index',
|
'entity_id': 'sensor.livingroom_health_index',
|
||||||
|
@ -4440,7 +4504,15 @@
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
'area_id': None,
|
'area_id': None,
|
||||||
'capabilities': None,
|
'capabilities': dict({
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
|
}),
|
||||||
'config_entry_id': <ANY>,
|
'config_entry_id': <ANY>,
|
||||||
'device_class': None,
|
'device_class': None,
|
||||||
'device_id': <ANY>,
|
'device_id': <ANY>,
|
||||||
|
@ -4457,7 +4529,7 @@
|
||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': None,
|
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Health index',
|
'original_name': 'Health index',
|
||||||
'platform': 'netatmo',
|
'platform': 'netatmo',
|
||||||
|
@ -4472,16 +4544,24 @@
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'attribution': 'Data provided by Netatmo',
|
'attribution': 'Data provided by Netatmo',
|
||||||
|
'device_class': 'enum',
|
||||||
'friendly_name': 'Parents Bedroom Health index',
|
'friendly_name': 'Parents Bedroom Health index',
|
||||||
'latitude': 13.377726,
|
'latitude': 13.377726,
|
||||||
'longitude': 52.516263,
|
'longitude': 52.516263,
|
||||||
|
'options': list([
|
||||||
|
'healthy',
|
||||||
|
'fine',
|
||||||
|
'fair',
|
||||||
|
'poor',
|
||||||
|
'unhealthy',
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.parents_bedroom_health_index',
|
'entity_id': 'sensor.parents_bedroom_health_index',
|
||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'Fine',
|
'state': 'fine',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_entity[sensor.parents_bedroom_humidity-entry]
|
# name: test_entity[sensor.parents_bedroom_humidity-entry]
|
||||||
|
|
|
@ -136,7 +136,7 @@ async def test_process_rf(strength: int, expected: str) -> None:
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("health", "expected"),
|
("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:
|
async def test_process_health(health: int, expected: str) -> None:
|
||||||
"""Test health index translation."""
|
"""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",
|
"12:34:56:26:68:92-health_idx",
|
||||||
"baby_bedroom_health",
|
"baby_bedroom_health",
|
||||||
"Fine",
|
"fine",
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"12:34:56:26:68:92-wifi_status",
|
"12:34:56:26:68:92-wifi_status",
|
||||||
|
|
Loading…
Add table
Reference in a new issue