1 """Support for HomematicIP Cloud weather devices."""
3 from __future__
import annotations
5 from homematicip.aio.device
import (
7 AsyncWeatherSensorPlus,
10 from homematicip.base.enums
import WeatherCondition
13 ATTR_CONDITION_CLOUDY,
15 ATTR_CONDITION_LIGHTNING,
16 ATTR_CONDITION_LIGHTNING_RAINY,
17 ATTR_CONDITION_PARTLYCLOUDY,
20 ATTR_CONDITION_SNOWY_RAINY,
30 from .const
import DOMAIN
31 from .entity
import HomematicipGenericEntity
32 from .hap
import HomematicipHAP
34 HOME_WEATHER_CONDITION = {
35 WeatherCondition.CLEAR: ATTR_CONDITION_SUNNY,
36 WeatherCondition.LIGHT_CLOUDY: ATTR_CONDITION_PARTLYCLOUDY,
37 WeatherCondition.CLOUDY: ATTR_CONDITION_CLOUDY,
38 WeatherCondition.CLOUDY_WITH_RAIN: ATTR_CONDITION_RAINY,
39 WeatherCondition.CLOUDY_WITH_SNOW_RAIN: ATTR_CONDITION_SNOWY_RAINY,
40 WeatherCondition.HEAVILY_CLOUDY: ATTR_CONDITION_CLOUDY,
41 WeatherCondition.HEAVILY_CLOUDY_WITH_RAIN: ATTR_CONDITION_RAINY,
42 WeatherCondition.HEAVILY_CLOUDY_WITH_STRONG_RAIN: ATTR_CONDITION_SNOWY_RAINY,
43 WeatherCondition.HEAVILY_CLOUDY_WITH_SNOW: ATTR_CONDITION_SNOWY,
44 WeatherCondition.HEAVILY_CLOUDY_WITH_SNOW_RAIN: ATTR_CONDITION_SNOWY_RAINY,
45 WeatherCondition.HEAVILY_CLOUDY_WITH_THUNDER: ATTR_CONDITION_LIGHTNING,
46 WeatherCondition.HEAVILY_CLOUDY_WITH_RAIN_AND_THUNDER: ATTR_CONDITION_LIGHTNING_RAINY,
47 WeatherCondition.FOGGY: ATTR_CONDITION_FOG,
48 WeatherCondition.STRONG_WIND: ATTR_CONDITION_WINDY,
49 WeatherCondition.UNKNOWN:
"",
55 config_entry: ConfigEntry,
56 async_add_entities: AddEntitiesCallback,
58 """Set up the HomematicIP weather sensor from a config entry."""
59 hap = hass.data[DOMAIN][config_entry.unique_id]
60 entities: list[HomematicipGenericEntity] = []
61 for device
in hap.home.devices:
62 if isinstance(device, AsyncWeatherSensorPro):
64 elif isinstance(device, (AsyncWeatherSensor, AsyncWeatherSensorPlus)):
73 """Representation of the HomematicIP weather sensor plus & basic."""
75 _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
76 _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
77 _attr_attribution =
"Powered by Homematic IP"
79 def __init__(self, hap: HomematicipHAP, device) ->
None:
80 """Initialize the weather sensor."""
85 """Return the name of the sensor."""
86 return self.
_device_device.label
90 """Return the platform temperature."""
91 return self.
_device_device.actualTemperature
95 """Return the humidity."""
96 return self.
_device_device.humidity
100 """Return the wind speed."""
101 return self.
_device_device.windSpeed
105 """Return the current condition."""
106 if getattr(self.
_device_device,
"raining",
None):
107 return ATTR_CONDITION_RAINY
109 return ATTR_CONDITION_WINDY
110 if self.
_device_device.sunshine:
111 return ATTR_CONDITION_SUNNY
116 """Representation of the HomematicIP weather sensor pro."""
120 """Return the wind bearing."""
121 return self.
_device_device.windDirection
125 """Representation of the HomematicIP home weather."""
127 _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
128 _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
129 _attr_attribution =
"Powered by Homematic IP"
132 """Initialize the home weather."""
133 hap.home.modelType =
"HmIP-Home-Weather"
138 """Return if weather entity is available."""
139 return self._home.connected
143 """Return the name of the sensor."""
144 return f
"Weather {self._home.location.city}"
148 """Return the temperature."""
149 return self.
_device_device.weather.temperature
153 """Return the humidity."""
154 return self.
_device_device.weather.humidity
158 """Return the wind speed."""
159 return round(self.
_device_device.weather.windSpeed, 1)
163 """Return the wind bearing."""
164 return self.
_device_device.weather.windDirection
168 """Return the current condition."""
169 return HOME_WEATHER_CONDITION.get(self.
_device_device.weather.weatherCondition)
float native_temperature(self)
None __init__(self, HomematicipHAP hap)
float native_wind_speed(self)
None __init__(self, HomematicipHAP hap, device)
float native_temperature(self)
float native_wind_speed(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)