mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Migrate knx weather to native_* (#74386)
This commit is contained in:
parent
810b2a2bd6
commit
07f677e9e8
@ -6,7 +6,14 @@ from xknx.devices import Weather as XknxWeather
|
|||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.weather import WeatherEntity
|
from homeassistant.components.weather import WeatherEntity
|
||||||
from homeassistant.const import CONF_ENTITY_CATEGORY, CONF_NAME, TEMP_CELSIUS, Platform
|
from homeassistant.const import (
|
||||||
|
CONF_ENTITY_CATEGORY,
|
||||||
|
CONF_NAME,
|
||||||
|
PRESSURE_PA,
|
||||||
|
SPEED_METERS_PER_SECOND,
|
||||||
|
TEMP_CELSIUS,
|
||||||
|
Platform,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
@ -68,7 +75,9 @@ class KNXWeather(KnxEntity, WeatherEntity):
|
|||||||
"""Representation of a KNX weather device."""
|
"""Representation of a KNX weather device."""
|
||||||
|
|
||||||
_device: XknxWeather
|
_device: XknxWeather
|
||||||
_attr_temperature_unit = TEMP_CELSIUS
|
_attr_native_pressure_unit = PRESSURE_PA
|
||||||
|
_attr_native_temperature_unit = TEMP_CELSIUS
|
||||||
|
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
||||||
|
|
||||||
def __init__(self, xknx: XKNX, config: ConfigType) -> None:
|
def __init__(self, xknx: XKNX, config: ConfigType) -> None:
|
||||||
"""Initialize of a KNX sensor."""
|
"""Initialize of a KNX sensor."""
|
||||||
@ -77,19 +86,14 @@ class KNXWeather(KnxEntity, WeatherEntity):
|
|||||||
self._attr_entity_category = config.get(CONF_ENTITY_CATEGORY)
|
self._attr_entity_category = config.get(CONF_ENTITY_CATEGORY)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self) -> float | None:
|
def native_temperature(self) -> float | None:
|
||||||
"""Return current temperature."""
|
"""Return current temperature in C."""
|
||||||
return self._device.temperature
|
return self._device.temperature
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pressure(self) -> float | None:
|
def native_pressure(self) -> float | None:
|
||||||
"""Return current air pressure."""
|
"""Return current air pressure in Pa."""
|
||||||
# KNX returns pA - HA requires hPa
|
return self._device.air_pressure
|
||||||
return (
|
|
||||||
self._device.air_pressure / 100
|
|
||||||
if self._device.air_pressure is not None
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def condition(self) -> str:
|
def condition(self) -> str:
|
||||||
@ -107,11 +111,6 @@ class KNXWeather(KnxEntity, WeatherEntity):
|
|||||||
return self._device.wind_bearing
|
return self._device.wind_bearing
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wind_speed(self) -> float | None:
|
def native_wind_speed(self) -> float | None:
|
||||||
"""Return current wind speed in km/h."""
|
"""Return current wind speed in m/s."""
|
||||||
# KNX only supports wind speed in m/s
|
return self._device.wind_speed
|
||||||
return (
|
|
||||||
self._device.wind_speed * 3.6
|
|
||||||
if self._device.wind_speed is not None
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user