mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Add new sensors to IMGW-PIB integration (#116631)
Add flood warning/alarm level sensors Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
parent
d81fad1ef1
commit
74df693079
@ -15,6 +15,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
"flood_warning_level": {
|
||||||
|
"default": "mdi:alert-outline"
|
||||||
|
},
|
||||||
|
"flood_alarm_level": {
|
||||||
|
"default": "mdi:alert"
|
||||||
|
},
|
||||||
"water_level": {
|
"water_level": {
|
||||||
"default": "mdi:waves"
|
"default": "mdi:waves"
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import UnitOfLength, UnitOfTemperature
|
from homeassistant.const import EntityCategory, UnitOfLength, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
@ -33,6 +33,26 @@ class ImgwPibSensorEntityDescription(SensorEntityDescription):
|
|||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[ImgwPibSensorEntityDescription, ...] = (
|
SENSOR_TYPES: tuple[ImgwPibSensorEntityDescription, ...] = (
|
||||||
|
ImgwPibSensorEntityDescription(
|
||||||
|
key="flood_alarm_level",
|
||||||
|
translation_key="flood_alarm_level",
|
||||||
|
native_unit_of_measurement=UnitOfLength.CENTIMETERS,
|
||||||
|
device_class=SensorDeviceClass.DISTANCE,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
suggested_display_precision=0,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value=lambda data: data.flood_alarm_level.value,
|
||||||
|
),
|
||||||
|
ImgwPibSensorEntityDescription(
|
||||||
|
key="flood_warning_level",
|
||||||
|
translation_key="flood_warning_level",
|
||||||
|
native_unit_of_measurement=UnitOfLength.CENTIMETERS,
|
||||||
|
device_class=SensorDeviceClass.DISTANCE,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
suggested_display_precision=0,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value=lambda data: data.flood_warning_level.value,
|
||||||
|
),
|
||||||
ImgwPibSensorEntityDescription(
|
ImgwPibSensorEntityDescription(
|
||||||
key="water_level",
|
key="water_level",
|
||||||
translation_key="water_level",
|
translation_key="water_level",
|
||||||
|
@ -26,6 +26,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
"flood_alarm_level": {
|
||||||
|
"name": "Flood alarm level"
|
||||||
|
},
|
||||||
|
"flood_warning_level": {
|
||||||
|
"name": "Flood warning level"
|
||||||
|
},
|
||||||
"water_level": {
|
"water_level": {
|
||||||
"name": "Water level"
|
"name": "Water level"
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,108 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
|
# name: test_sensor[sensor.river_name_station_name_flood_alarm_level-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
|
'entity_id': 'sensor.river_name_station_name_flood_alarm_level',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
'sensor': dict({
|
||||||
|
'suggested_display_precision': 0,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.DISTANCE: 'distance'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Flood alarm level',
|
||||||
|
'platform': 'imgw_pib',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'flood_alarm_level',
|
||||||
|
'unique_id': '123_flood_alarm_level',
|
||||||
|
'unit_of_measurement': <UnitOfLength.CENTIMETERS: 'cm'>,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensor[sensor.river_name_station_name_flood_alarm_level-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'attribution': 'Data provided by IMGW-PIB',
|
||||||
|
'device_class': 'distance',
|
||||||
|
'friendly_name': 'River Name (Station Name) Flood alarm level',
|
||||||
|
'unit_of_measurement': <UnitOfLength.CENTIMETERS: 'cm'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.river_name_station_name_flood_alarm_level',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '630.0',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensor[sensor.river_name_station_name_flood_warning_level-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'sensor',
|
||||||
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
|
'entity_id': 'sensor.river_name_station_name_flood_warning_level',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
'sensor': dict({
|
||||||
|
'suggested_display_precision': 0,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'original_device_class': <SensorDeviceClass.DISTANCE: 'distance'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Flood warning level',
|
||||||
|
'platform': 'imgw_pib',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'flood_warning_level',
|
||||||
|
'unique_id': '123_flood_warning_level',
|
||||||
|
'unit_of_measurement': <UnitOfLength.CENTIMETERS: 'cm'>,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensor[sensor.river_name_station_name_flood_warning_level-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'attribution': 'Data provided by IMGW-PIB',
|
||||||
|
'device_class': 'distance',
|
||||||
|
'friendly_name': 'River Name (Station Name) Flood warning level',
|
||||||
|
'unit_of_measurement': <UnitOfLength.CENTIMETERS: 'cm'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.river_name_station_name_flood_warning_level',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '590.0',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_sensor[sensor.river_name_station_name_water_level-entry]
|
# name: test_sensor[sensor.river_name_station_name_water_level-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
|
@ -24,6 +24,7 @@ async def test_sensor(
|
|||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
mock_imgw_pib_client: AsyncMock,
|
mock_imgw_pib_client: AsyncMock,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
|
entity_registry_enabled_by_default: None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test states of the sensor."""
|
"""Test states of the sensor."""
|
||||||
with patch("homeassistant.components.imgw_pib.PLATFORMS", [Platform.SENSOR]):
|
with patch("homeassistant.components.imgw_pib.PLATFORMS", [Platform.SENSOR]):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user