Migrate homematicip_cloud to native_* (#74385)

pull/75147/head
Erik Montnemery 2022-07-11 10:58:57 +02:00 committed by Paulus Schoutsen
parent 8259ce9868
commit 5e7174a5f4
1 changed files with 11 additions and 15 deletions

View File

@ -22,7 +22,7 @@ from homeassistant.components.weather import (
WeatherEntity, WeatherEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -71,6 +71,9 @@ async def async_setup_entry(
class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity): class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity):
"""Representation of the HomematicIP weather sensor plus & basic.""" """Representation of the HomematicIP weather sensor plus & basic."""
_attr_native_temperature_unit = TEMP_CELSIUS
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the weather sensor.""" """Initialize the weather sensor."""
super().__init__(hap, device) super().__init__(hap, device)
@ -81,22 +84,17 @@ class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity):
return self._device.label return self._device.label
@property @property
def temperature(self) -> float: def native_temperature(self) -> float:
"""Return the platform temperature.""" """Return the platform temperature."""
return self._device.actualTemperature return self._device.actualTemperature
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def humidity(self) -> int: def humidity(self) -> int:
"""Return the humidity.""" """Return the humidity."""
return self._device.humidity return self._device.humidity
@property @property
def wind_speed(self) -> float: def native_wind_speed(self) -> float:
"""Return the wind speed.""" """Return the wind speed."""
return self._device.windSpeed return self._device.windSpeed
@ -129,6 +127,9 @@ class HomematicipWeatherSensorPro(HomematicipWeatherSensor):
class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity): class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity):
"""Representation of the HomematicIP home weather.""" """Representation of the HomematicIP home weather."""
_attr_native_temperature_unit = TEMP_CELSIUS
_attr_native_wind_speed_unit = SPEED_KILOMETERS_PER_HOUR
def __init__(self, hap: HomematicipHAP) -> None: def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize the home weather.""" """Initialize the home weather."""
hap.home.modelType = "HmIP-Home-Weather" hap.home.modelType = "HmIP-Home-Weather"
@ -145,22 +146,17 @@ class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity):
return f"Weather {self._home.location.city}" return f"Weather {self._home.location.city}"
@property @property
def temperature(self) -> float: def native_temperature(self) -> float:
"""Return the temperature.""" """Return the temperature."""
return self._device.weather.temperature return self._device.weather.temperature
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property @property
def humidity(self) -> int: def humidity(self) -> int:
"""Return the humidity.""" """Return the humidity."""
return self._device.weather.humidity return self._device.weather.humidity
@property @property
def wind_speed(self) -> float: def native_wind_speed(self) -> float:
"""Return the wind speed.""" """Return the wind speed."""
return round(self._device.weather.windSpeed, 1) return round(self._device.weather.windSpeed, 1)