mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add support for OpenWeatherMap's visibility (#71013)
* Add support for visibility * Add docstrings
This commit is contained in:
parent
caf71c854f
commit
805aa3375a
@ -31,6 +31,7 @@ from homeassistant.components.weather import (
|
||||
)
|
||||
from homeassistant.const import (
|
||||
DEGREE,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILLIMETERS,
|
||||
PERCENTAGE,
|
||||
PRESSURE_HPA,
|
||||
@ -65,6 +66,7 @@ ATTR_API_CLOUDS = "clouds"
|
||||
ATTR_API_RAIN = "rain"
|
||||
ATTR_API_SNOW = "snow"
|
||||
ATTR_API_UV_INDEX = "uv_index"
|
||||
ATTR_API_VISIBILITY_DISTANCE = "visibility_distance"
|
||||
ATTR_API_WEATHER_CODE = "weather_code"
|
||||
ATTR_API_FORECAST = "forecast"
|
||||
UPDATE_LISTENER = "update_listener"
|
||||
@ -243,6 +245,12 @@ WEATHER_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
native_unit_of_measurement=UV_INDEX,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key=ATTR_API_VISIBILITY_DISTANCE,
|
||||
name="Visibility",
|
||||
native_unit_of_measurement=LENGTH_KILOMETERS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key=ATTR_API_CONDITION,
|
||||
name="Condition",
|
||||
|
@ -36,6 +36,7 @@ from .const import (
|
||||
ATTR_API_SNOW,
|
||||
ATTR_API_TEMPERATURE,
|
||||
ATTR_API_UV_INDEX,
|
||||
ATTR_API_VISIBILITY_DISTANCE,
|
||||
ATTR_API_WEATHER,
|
||||
ATTR_API_WEATHER_CODE,
|
||||
ATTR_API_WIND_BEARING,
|
||||
@ -72,6 +73,7 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator):
|
||||
)
|
||||
|
||||
async def _async_update_data(self):
|
||||
"""Update the data."""
|
||||
data = {}
|
||||
async with async_timeout.timeout(20):
|
||||
try:
|
||||
@ -137,11 +139,13 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator):
|
||||
ATTR_API_WEATHER: current_weather.detailed_status,
|
||||
ATTR_API_CONDITION: self._get_condition(current_weather.weather_code),
|
||||
ATTR_API_UV_INDEX: current_weather.uvi,
|
||||
ATTR_API_VISIBILITY_DISTANCE: current_weather.visibility_distance,
|
||||
ATTR_API_WEATHER_CODE: current_weather.weather_code,
|
||||
ATTR_API_FORECAST: forecast_weather,
|
||||
}
|
||||
|
||||
def _get_forecast_from_weather_response(self, weather_response):
|
||||
"""Extract the forecast data from the weather response."""
|
||||
forecast_arg = "forecast"
|
||||
if self._forecast_mode == FORECAST_MODE_ONECALL_HOURLY:
|
||||
forecast_arg = "forecast_hourly"
|
||||
@ -152,6 +156,7 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator):
|
||||
]
|
||||
|
||||
def _convert_forecast(self, entry):
|
||||
"""Convert the forecast data."""
|
||||
forecast = {
|
||||
ATTR_FORECAST_TIME: dt.utc_from_timestamp(
|
||||
entry.reference_time("unix")
|
||||
@ -182,6 +187,7 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator):
|
||||
|
||||
@staticmethod
|
||||
def _fmt_dewpoint(dewpoint):
|
||||
"""Format the dewpoint data."""
|
||||
if dewpoint is not None:
|
||||
return round(kelvin_to_celsius(dewpoint), 1)
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user