1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Fix device class and unit for Shelly rainfall sensor (#156124)

This commit is contained in:
Maciej Bieniek
2025-11-08 15:11:56 +01:00
committed by GitHub
parent 3519611d8e
commit 9479a88393
4 changed files with 19 additions and 19 deletions

View File

@@ -30,12 +30,12 @@ from homeassistant.const import (
UnitOfEnergy,
UnitOfFrequency,
UnitOfPower,
UnitOfPrecipitationDepth,
UnitOfPressure,
UnitOfTemperature,
UnitOfTime,
UnitOfVolume,
UnitOfVolumeFlowRate,
UnitOfVolumetricFlux,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@@ -1465,9 +1465,9 @@ RPC_SENSORS: Final = {
"number_last_precipitation": RpcSensorDescription(
key="number",
sub_key="value",
translation_key="rainfall_last_24h",
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
device_class=SensorDeviceClass.PRECIPITATION,
translation_key="rainfall",
native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
role="last_precipitation",
removal_condition=lambda config, _s, _k: not config.get("service:0", {}).get(
"weather_api", False

View File

@@ -315,8 +315,8 @@
"pulse_counter_with_channel_name": {
"name": "{channel_name} pulse counter"
},
"rainfall_last_24h": {
"name": "Rainfall last 24h"
"rainfall": {
"name": "Rainfall"
},
"right_slot_level": {
"name": "Right slot level"

View File

@@ -766,7 +766,7 @@
'state': '0',
})
# ---
# name: test_shelly_irrigation_weather_sensors[sensor.test_name_rainfall_last_24h-entry]
# name: test_shelly_irrigation_weather_sensors[sensor.test_name_rainfall-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@@ -779,7 +779,7 @@
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.test_name_rainfall_last_24h',
'entity_id': 'sensor.test_name_rainfall',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
@@ -792,27 +792,27 @@
'suggested_display_precision': 0,
}),
}),
'original_device_class': <SensorDeviceClass.PRECIPITATION: 'precipitation'>,
'original_device_class': <SensorDeviceClass.PRECIPITATION_INTENSITY: 'precipitation_intensity'>,
'original_icon': None,
'original_name': 'Rainfall last 24h',
'original_name': 'Rainfall',
'platform': 'shelly',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'rainfall_last_24h',
'translation_key': 'rainfall',
'unique_id': '123456789ABC-number:201-number_last_precipitation',
'unit_of_measurement': <UnitOfPrecipitationDepth.MILLIMETERS: 'mm'>,
'unit_of_measurement': <UnitOfVolumetricFlux.MILLIMETERS_PER_DAY: 'mm/d'>,
})
# ---
# name: test_shelly_irrigation_weather_sensors[sensor.test_name_rainfall_last_24h-state]
# name: test_shelly_irrigation_weather_sensors[sensor.test_name_rainfall-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'precipitation',
'friendly_name': 'Test name Rainfall last 24h',
'unit_of_measurement': <UnitOfPrecipitationDepth.MILLIMETERS: 'mm'>,
'device_class': 'precipitation_intensity',
'friendly_name': 'Test name Rainfall',
'unit_of_measurement': <UnitOfVolumetricFlux.MILLIMETERS_PER_DAY: 'mm/d'>,
}),
'context': <ANY>,
'entity_id': 'sensor.test_name_rainfall_last_24h',
'entity_id': 'sensor.test_name_rainfall',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,

View File

@@ -2025,7 +2025,7 @@ async def test_shelly_irrigation_weather_sensors(
config_entry = await init_integration(hass, gen=3)
for entity in ("average_temperature", "rainfall_last_24h"):
for entity in ("average_temperature", "rainfall"):
entity_id = f"{SENSOR_DOMAIN}.test_name_{entity}"
state = hass.states.get(entity_id)
@@ -2039,6 +2039,6 @@ async def test_shelly_irrigation_weather_sensors(
await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done()
for entity in ("average_temperature", "rainfall_last_24h"):
for entity in ("average_temperature", "rainfall"):
entity_id = f"{SENSOR_DOMAIN}.test_name_{entity}"
assert hass.states.get(entity_id) is None