Fix state_class for Accuweather precipitation sensor (#86088)

This commit is contained in:
Maciej Bieniek 2023-01-20 23:36:25 +01:00 committed by GitHub
parent 80929c5f8c
commit 58bfeb3110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -17,10 +17,10 @@ from homeassistant.const import (
PERCENTAGE,
UV_INDEX,
UnitOfLength,
UnitOfPrecipitationDepth,
UnitOfSpeed,
UnitOfTemperature,
UnitOfTime,
UnitOfVolumetricFlux,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -290,11 +290,11 @@ SENSOR_TYPES: tuple[AccuWeatherSensorDescription, ...] = (
),
AccuWeatherSensorDescription(
key="Precipitation",
device_class=SensorDeviceClass.PRECIPITATION,
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
name="Precipitation",
state_class=SensorStateClass.MEASUREMENT,
metric_unit=UnitOfPrecipitationDepth.MILLIMETERS,
us_customary_unit=UnitOfPrecipitationDepth.INCHES,
metric_unit=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
us_customary_unit=UnitOfVolumetricFlux.INCHES_PER_HOUR,
value_fn=lambda data, unit: cast(float, data[unit][ATTR_VALUE]),
attr_fn=lambda data: {"type": data["PrecipitationType"]},
),
@ -452,7 +452,7 @@ def _get_sensor_data(
return sensors[ATTR_FORECAST][forecast_day][kind]
if kind == "Precipitation":
return sensors["PrecipitationSummary"][kind]
return sensors["PrecipitationSummary"]["PastHour"]
return sensors[kind]

View File

@ -24,6 +24,7 @@ from homeassistant.const import (
UnitOfSpeed,
UnitOfTemperature,
UnitOfTime,
UnitOfVolumetricFlux,
)
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
@ -57,11 +58,17 @@ async def test_sensor_without_forecast(hass):
assert state
assert state.state == "0.0"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfLength.MILLIMETERS
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR
)
assert state.attributes.get(ATTR_ICON) is None
assert state.attributes.get("type") is None
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PRECIPITATION
assert (
state.attributes.get(ATTR_DEVICE_CLASS)
== SensorDeviceClass.PRECIPITATION_INTENSITY
)
entry = registry.async_get("sensor.home_precipitation")
assert entry