Use enum device class in Netatmo wind direction (#115413)

* Use enum device class in Netatmo wind direction

* Use enum device class in Netatmo wind direction

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Joost Lekkerkerker 2024-04-12 08:39:59 +02:00 committed by GitHub
parent fb5fc136e8
commit 6cc2b1e10a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 92 additions and 11 deletions

View File

@ -67,6 +67,17 @@ from .helper import NetatmoArea
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DIRECTION_OPTIONS = [
"n",
"ne",
"e",
"se",
"s",
"sw",
"w",
"nw",
]
def process_health(health: StateType) -> str | None: def process_health(health: StateType) -> str | None:
"""Process health index and return string for display.""" """Process health index and return string for display."""
@ -199,6 +210,9 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
NetatmoSensorEntityDescription( NetatmoSensorEntityDescription(
key="windangle", key="windangle",
netatmo_name="wind_direction", netatmo_name="wind_direction",
device_class=SensorDeviceClass.ENUM,
options=DIRECTION_OPTIONS,
value_fn=lambda x: x.lower() if isinstance(x, str) else None,
), ),
NetatmoSensorEntityDescription( NetatmoSensorEntityDescription(
key="windangle_value", key="windangle_value",
@ -218,6 +232,9 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
key="gustangle", key="gustangle",
netatmo_name="gust_direction", netatmo_name="gust_direction",
entity_registry_enabled_default=False, 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( NetatmoSensorEntityDescription(
key="gustangle_value", key="gustangle_value",

View File

@ -185,13 +185,33 @@
"name": "Precipitation today" "name": "Precipitation today"
}, },
"wind_direction": { "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": { "wind_angle": {
"name": "Wind angle" "name": "Wind angle"
}, },
"gust_direction": { "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": { "gust_angle": {
"name": "Gust angle" "name": "Gust angle"

View File

@ -6073,7 +6073,18 @@
'aliases': set({ 'aliases': set({
}), }),
'area_id': None, 'area_id': None,
'capabilities': None, 'capabilities': dict({
'options': list([
'n',
'ne',
'e',
'se',
's',
'sw',
'w',
'nw',
]),
}),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
'device_class': None, 'device_class': None,
'device_id': <ANY>, 'device_id': <ANY>,
@ -6090,7 +6101,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': 'Gust direction', 'original_name': 'Gust direction',
'platform': 'netatmo', 'platform': 'netatmo',
@ -6105,14 +6116,25 @@
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'attribution': 'Data provided by Netatmo', 'attribution': 'Data provided by Netatmo',
'device_class': 'enum',
'friendly_name': 'Villa Garden Gust direction', 'friendly_name': 'Villa Garden Gust direction',
'options': list([
'n',
'ne',
'e',
'se',
's',
'sw',
'w',
'nw',
]),
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'sensor.villa_garden_gust_direction', 'entity_id': 'sensor.villa_garden_gust_direction',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'S', 'state': 's',
}) })
# --- # ---
# name: test_entity[sensor.villa_garden_gust_strength-entry] # name: test_entity[sensor.villa_garden_gust_strength-entry]
@ -6317,7 +6339,18 @@
'aliases': set({ 'aliases': set({
}), }),
'area_id': None, 'area_id': None,
'capabilities': None, 'capabilities': dict({
'options': list([
'n',
'ne',
'e',
'se',
's',
'sw',
'w',
'nw',
]),
}),
'config_entry_id': <ANY>, 'config_entry_id': <ANY>,
'device_class': None, 'device_class': None,
'device_id': <ANY>, 'device_id': <ANY>,
@ -6334,7 +6367,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': 'Wind direction', 'original_name': 'Wind direction',
'platform': 'netatmo', 'platform': 'netatmo',
@ -6349,14 +6382,25 @@
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'attribution': 'Data provided by Netatmo', 'attribution': 'Data provided by Netatmo',
'device_class': 'enum',
'friendly_name': 'Villa Garden Wind direction', 'friendly_name': 'Villa Garden Wind direction',
'options': list([
'n',
'ne',
'e',
'se',
's',
'sw',
'w',
'nw',
]),
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'sensor.villa_garden_wind_direction', 'entity_id': 'sensor.villa_garden_wind_direction',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'SW', 'state': 'sw',
}) })
# --- # ---
# name: test_entity[sensor.villa_garden_wind_speed-entry] # name: test_entity[sensor.villa_garden_wind_speed-entry]

View File

@ -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_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: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", "12:34:56:03:1b:e4-windangle_value",
"netatmoindoor_garden_angle", "netatmoindoor_garden_angle",
"217", "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", "12:34:56:03:1b:e4-gustangle",
"netatmoindoor_garden_gust_direction", "netatmoindoor_garden_gust_direction",
"S", "s",
), ),
( (
"12:34:56:03:1b:e4-gustangle_value", "12:34:56:03:1b:e4-gustangle_value",