mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Fix state_class
for Accuweather precipitation
sensor (#86088)
This commit is contained in:
parent
80929c5f8c
commit
58bfeb3110
@ -17,10 +17,10 @@ from homeassistant.const import (
|
|||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
UV_INDEX,
|
UV_INDEX,
|
||||||
UnitOfLength,
|
UnitOfLength,
|
||||||
UnitOfPrecipitationDepth,
|
|
||||||
UnitOfSpeed,
|
UnitOfSpeed,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
UnitOfTime,
|
UnitOfTime,
|
||||||
|
UnitOfVolumetricFlux,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -290,11 +290,11 @@ SENSOR_TYPES: tuple[AccuWeatherSensorDescription, ...] = (
|
|||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="Precipitation",
|
key="Precipitation",
|
||||||
device_class=SensorDeviceClass.PRECIPITATION,
|
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
|
||||||
name="Precipitation",
|
name="Precipitation",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
metric_unit=UnitOfPrecipitationDepth.MILLIMETERS,
|
metric_unit=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
|
||||||
us_customary_unit=UnitOfPrecipitationDepth.INCHES,
|
us_customary_unit=UnitOfVolumetricFlux.INCHES_PER_HOUR,
|
||||||
value_fn=lambda data, unit: cast(float, data[unit][ATTR_VALUE]),
|
value_fn=lambda data, unit: cast(float, data[unit][ATTR_VALUE]),
|
||||||
attr_fn=lambda data: {"type": data["PrecipitationType"]},
|
attr_fn=lambda data: {"type": data["PrecipitationType"]},
|
||||||
),
|
),
|
||||||
@ -452,7 +452,7 @@ def _get_sensor_data(
|
|||||||
return sensors[ATTR_FORECAST][forecast_day][kind]
|
return sensors[ATTR_FORECAST][forecast_day][kind]
|
||||||
|
|
||||||
if kind == "Precipitation":
|
if kind == "Precipitation":
|
||||||
return sensors["PrecipitationSummary"][kind]
|
return sensors["PrecipitationSummary"]["PastHour"]
|
||||||
|
|
||||||
return sensors[kind]
|
return sensors[kind]
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ from homeassistant.const import (
|
|||||||
UnitOfSpeed,
|
UnitOfSpeed,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
UnitOfTime,
|
UnitOfTime,
|
||||||
|
UnitOfVolumetricFlux,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
@ -57,11 +58,17 @@ async def test_sensor_without_forecast(hass):
|
|||||||
assert state
|
assert state
|
||||||
assert state.state == "0.0"
|
assert state.state == "0.0"
|
||||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
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(ATTR_ICON) is None
|
||||||
assert state.attributes.get("type") is None
|
assert state.attributes.get("type") is None
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
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")
|
entry = registry.async_get("sensor.home_precipitation")
|
||||||
assert entry
|
assert entry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user