mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add humidity to weather forecast (#95064)
* allow humidty in forecast * Add tests * float --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
parent
e5afff7f98
commit
29ef925d73
@ -71,6 +71,7 @@ ATTR_CONDITION_WINDY = "windy"
|
|||||||
ATTR_CONDITION_WINDY_VARIANT = "windy-variant"
|
ATTR_CONDITION_WINDY_VARIANT = "windy-variant"
|
||||||
ATTR_FORECAST = "forecast"
|
ATTR_FORECAST = "forecast"
|
||||||
ATTR_FORECAST_CONDITION: Final = "condition"
|
ATTR_FORECAST_CONDITION: Final = "condition"
|
||||||
|
ATTR_FORECAST_HUMIDITY: Final = "humidity"
|
||||||
ATTR_FORECAST_NATIVE_PRECIPITATION: Final = "native_precipitation"
|
ATTR_FORECAST_NATIVE_PRECIPITATION: Final = "native_precipitation"
|
||||||
ATTR_FORECAST_PRECIPITATION: Final = "precipitation"
|
ATTR_FORECAST_PRECIPITATION: Final = "precipitation"
|
||||||
ATTR_FORECAST_PRECIPITATION_PROBABILITY: Final = "precipitation_probability"
|
ATTR_FORECAST_PRECIPITATION_PROBABILITY: Final = "precipitation_probability"
|
||||||
@ -125,6 +126,7 @@ class Forecast(TypedDict, total=False):
|
|||||||
|
|
||||||
condition: str | None
|
condition: str | None
|
||||||
datetime: Required[str]
|
datetime: Required[str]
|
||||||
|
humidity: float | None
|
||||||
precipitation_probability: int | None
|
precipitation_probability: int | None
|
||||||
cloud_coverage: int | None
|
cloud_coverage: int | None
|
||||||
native_precipitation: float | None
|
native_precipitation: float | None
|
||||||
@ -869,6 +871,18 @@ class WeatherEntity(Entity):
|
|||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
forecast_humidity := forecast_entry.pop(
|
||||||
|
ATTR_FORECAST_HUMIDITY,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
) is not None:
|
||||||
|
with suppress(TypeError, ValueError):
|
||||||
|
forecast_humidity_f = float(forecast_humidity)
|
||||||
|
forecast_entry[ATTR_FORECAST_HUMIDITY] = round(
|
||||||
|
forecast_humidity_f
|
||||||
|
)
|
||||||
|
|
||||||
forecast.append(forecast_entry)
|
forecast.append(forecast_entry)
|
||||||
|
|
||||||
data[ATTR_FORECAST] = forecast
|
data[ATTR_FORECAST] = forecast
|
||||||
|
@ -8,6 +8,7 @@ from homeassistant.components.weather import (
|
|||||||
ATTR_FORECAST,
|
ATTR_FORECAST,
|
||||||
ATTR_FORECAST_APPARENT_TEMP,
|
ATTR_FORECAST_APPARENT_TEMP,
|
||||||
ATTR_FORECAST_DEW_POINT,
|
ATTR_FORECAST_DEW_POINT,
|
||||||
|
ATTR_FORECAST_HUMIDITY,
|
||||||
ATTR_FORECAST_PRECIPITATION,
|
ATTR_FORECAST_PRECIPITATION,
|
||||||
ATTR_FORECAST_PRESSURE,
|
ATTR_FORECAST_PRESSURE,
|
||||||
ATTR_FORECAST_TEMP,
|
ATTR_FORECAST_TEMP,
|
||||||
@ -34,6 +35,7 @@ from homeassistant.components.weather import (
|
|||||||
from homeassistant.components.weather.const import (
|
from homeassistant.components.weather.const import (
|
||||||
ATTR_WEATHER_CLOUD_COVERAGE,
|
ATTR_WEATHER_CLOUD_COVERAGE,
|
||||||
ATTR_WEATHER_DEW_POINT,
|
ATTR_WEATHER_DEW_POINT,
|
||||||
|
ATTR_WEATHER_HUMIDITY,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_FRIENDLY_NAME,
|
ATTR_FRIENDLY_NAME,
|
||||||
@ -557,6 +559,21 @@ async def test_wind_bearing_ozone_and_cloud_coverage(
|
|||||||
assert float(state.attributes[ATTR_WEATHER_CLOUD_COVERAGE]) == 75
|
assert float(state.attributes[ATTR_WEATHER_CLOUD_COVERAGE]) == 75
|
||||||
|
|
||||||
|
|
||||||
|
async def test_humidity(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
enable_custom_integrations: None,
|
||||||
|
) -> None:
|
||||||
|
"""Test humidity."""
|
||||||
|
humidity_value = 80.2
|
||||||
|
|
||||||
|
entity0 = await create_entity(hass, humidity=humidity_value)
|
||||||
|
|
||||||
|
state = hass.states.get(entity0.entity_id)
|
||||||
|
forecast = state.attributes[ATTR_FORECAST][0]
|
||||||
|
assert float(state.attributes[ATTR_WEATHER_HUMIDITY]) == 80
|
||||||
|
assert float(forecast[ATTR_FORECAST_HUMIDITY]) == 80
|
||||||
|
|
||||||
|
|
||||||
async def test_none_forecast(
|
async def test_none_forecast(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
enable_custom_integrations: None,
|
enable_custom_integrations: None,
|
||||||
|
@ -6,6 +6,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
ATTR_FORECAST_CLOUD_COVERAGE,
|
ATTR_FORECAST_CLOUD_COVERAGE,
|
||||||
|
ATTR_FORECAST_HUMIDITY,
|
||||||
ATTR_FORECAST_NATIVE_APPARENT_TEMP,
|
ATTR_FORECAST_NATIVE_APPARENT_TEMP,
|
||||||
ATTR_FORECAST_NATIVE_DEW_POINT,
|
ATTR_FORECAST_NATIVE_DEW_POINT,
|
||||||
ATTR_FORECAST_NATIVE_PRECIPITATION,
|
ATTR_FORECAST_NATIVE_PRECIPITATION,
|
||||||
@ -223,6 +224,7 @@ class MockWeatherMockForecast(MockWeather):
|
|||||||
ATTR_FORECAST_NATIVE_PRECIPITATION: self._values.get(
|
ATTR_FORECAST_NATIVE_PRECIPITATION: self._values.get(
|
||||||
"native_precipitation"
|
"native_precipitation"
|
||||||
),
|
),
|
||||||
|
ATTR_FORECAST_HUMIDITY: self.humidity,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user