mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Add new sensors to Stookwijzer (#131587)
This commit is contained in:
parent
442a270473
commit
af29bfceb0
@ -16,4 +16,6 @@ async def async_get_config_entry_diagnostics(
|
|||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.client
|
||||||
return {
|
return {
|
||||||
"advice": client.advice,
|
"advice": client.advice,
|
||||||
|
"air_quality_index": client.lki,
|
||||||
|
"windspeed_ms": client.windspeed_ms,
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,9 @@ from homeassistant.components.sensor import (
|
|||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
|
from homeassistant.const import UnitOfSpeed
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -25,10 +27,25 @@ from .coordinator import StookwijzerConfigEntry, StookwijzerCoordinator
|
|||||||
class StookwijzerSensorDescription(SensorEntityDescription):
|
class StookwijzerSensorDescription(SensorEntityDescription):
|
||||||
"""Class describing Stookwijzer sensor entities."""
|
"""Class describing Stookwijzer sensor entities."""
|
||||||
|
|
||||||
value_fn: Callable[[Stookwijzer], str | None]
|
value_fn: Callable[[Stookwijzer], int | float | str | None]
|
||||||
|
|
||||||
|
|
||||||
STOOKWIJZER_SENSORS = [
|
STOOKWIJZER_SENSORS = [
|
||||||
|
StookwijzerSensorDescription(
|
||||||
|
key="windspeed",
|
||||||
|
native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
|
||||||
|
suggested_unit_of_measurement=UnitOfSpeed.BEAUFORT,
|
||||||
|
device_class=SensorDeviceClass.WIND_SPEED,
|
||||||
|
suggested_display_precision=0,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_fn=lambda client: client.windspeed_ms,
|
||||||
|
),
|
||||||
|
StookwijzerSensorDescription(
|
||||||
|
key="air_quality_index",
|
||||||
|
device_class=SensorDeviceClass.AQI,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_fn=lambda client: client.lki,
|
||||||
|
),
|
||||||
StookwijzerSensorDescription(
|
StookwijzerSensorDescription(
|
||||||
key="advice",
|
key="advice",
|
||||||
translation_key="advice",
|
translation_key="advice",
|
||||||
@ -74,6 +91,6 @@ class StookwijzerSensor(CoordinatorEntity[StookwijzerCoordinator], SensorEntity)
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> str | None:
|
def native_value(self) -> int | float | str | None:
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self.entity_description.value_fn(self.coordinator.client)
|
return self.entity_description.value_fn(self.coordinator.client)
|
||||||
|
@ -76,6 +76,9 @@ def mock_stookwijzer() -> Generator[MagicMock]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
client = stookwijzer_mock.return_value
|
client = stookwijzer_mock.return_value
|
||||||
|
client.lki = 2
|
||||||
|
client.windspeed_ms = 2.5
|
||||||
|
client.windspeed_bft = 2
|
||||||
client.advice = "code_yellow"
|
client.advice = "code_yellow"
|
||||||
|
|
||||||
yield stookwijzer_mock
|
yield stookwijzer_mock
|
||||||
|
@ -2,5 +2,7 @@
|
|||||||
# name: test_get_diagnostics
|
# name: test_get_diagnostics
|
||||||
dict({
|
dict({
|
||||||
'advice': 'code_yellow',
|
'advice': 'code_yellow',
|
||||||
|
'air_quality_index': 2,
|
||||||
|
'windspeed_ms': 2.5,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
@ -58,3 +58,112 @@
|
|||||||
'state': 'code_yellow',
|
'state': 'code_yellow',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_entities[sensor.stookwijzer_air_quality_index-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': dict({
|
||||||
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
|
}),
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'sensor.stookwijzer_air_quality_index',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.AQI: 'aqi'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Air quality index',
|
||||||
|
'platform': 'stookwijzer',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '12345_air_quality_index',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_entities[sensor.stookwijzer_air_quality_index-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'attribution': 'Data provided by atlasleefomgeving.nl',
|
||||||
|
'device_class': 'aqi',
|
||||||
|
'friendly_name': 'Stookwijzer Air quality index',
|
||||||
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.stookwijzer_air_quality_index',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '2',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_entities[sensor.stookwijzer_wind_speed-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': dict({
|
||||||
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
|
}),
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'sensor.stookwijzer_wind_speed',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
'sensor': dict({
|
||||||
|
'suggested_display_precision': 0,
|
||||||
|
}),
|
||||||
|
'sensor.private': dict({
|
||||||
|
'suggested_unit_of_measurement': <UnitOfSpeed.BEAUFORT: 'Beaufort'>,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.WIND_SPEED: 'wind_speed'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Wind speed',
|
||||||
|
'platform': 'stookwijzer',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '12345_windspeed',
|
||||||
|
'unit_of_measurement': <UnitOfSpeed.BEAUFORT: 'Beaufort'>,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_entities[sensor.stookwijzer_wind_speed-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'attribution': 'Data provided by atlasleefomgeving.nl',
|
||||||
|
'device_class': 'wind_speed',
|
||||||
|
'friendly_name': 'Stookwijzer Wind speed',
|
||||||
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
|
'unit_of_measurement': <UnitOfSpeed.BEAUFORT: 'Beaufort'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.stookwijzer_wind_speed',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '2.0',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
Loading…
x
Reference in New Issue
Block a user