Migrate knx weather to native_* (#74386)
parent
810b2a2bd6
commit
07f677e9e8
|
@ -6,7 +6,14 @@ from xknx.devices import Weather as XknxWeather
|
|||
|
||||
from homeassistant import config_entries
|
||||
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.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
@ -68,7 +75,9 @@ class KNXWeather(KnxEntity, WeatherEntity):
|
|||
"""Representation of a KNX weather device."""
|
||||
|
||||
_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:
|
||||
"""Initialize of a KNX sensor."""
|
||||
|
@ -77,19 +86,14 @@ class KNXWeather(KnxEntity, WeatherEntity):
|
|||
self._attr_entity_category = config.get(CONF_ENTITY_CATEGORY)
|
||||
|
||||
@property
|
||||
def temperature(self) -> float | None:
|
||||
"""Return current temperature."""
|
||||
def native_temperature(self) -> float | None:
|
||||
"""Return current temperature in C."""
|
||||
return self._device.temperature
|
||||
|
||||
@property
|
||||
def pressure(self) -> float | None:
|
||||
"""Return current air pressure."""
|
||||
# KNX returns pA - HA requires hPa
|
||||
return (
|
||||
self._device.air_pressure / 100
|
||||
if self._device.air_pressure is not None
|
||||
else None
|
||||
)
|
||||
def native_pressure(self) -> float | None:
|
||||
"""Return current air pressure in Pa."""
|
||||
return self._device.air_pressure
|
||||
|
||||
@property
|
||||
def condition(self) -> str:
|
||||
|
@ -107,11 +111,6 @@ class KNXWeather(KnxEntity, WeatherEntity):
|
|||
return self._device.wind_bearing
|
||||
|
||||
@property
|
||||
def wind_speed(self) -> float | None:
|
||||
"""Return current wind speed in km/h."""
|
||||
# KNX only supports wind speed in m/s
|
||||
return (
|
||||
self._device.wind_speed * 3.6
|
||||
if self._device.wind_speed is not None
|
||||
else None
|
||||
)
|
||||
def native_wind_speed(self) -> float | None:
|
||||
"""Return current wind speed in m/s."""
|
||||
return self._device.wind_speed
|
||||
|
|
Loading…
Reference in New Issue