Skip to content

Commit

Permalink
Add built in weather to Homematic IP Cloud (home-assistant#26642)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored and MartinHjelmare committed Sep 14, 2019
1 parent 5885c3f commit 24f1ff0
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions homeassistant/components/homematicip_cloud/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
AsyncWeatherSensorPro,
)
from homematicip.aio.home import AsyncHome
from homematicip.base.enums import WeatherCondition

from homeassistant.components.weather import WeatherEntity
from homeassistant.config_entries import ConfigEntry
Expand All @@ -17,6 +18,24 @@

_LOGGER = logging.getLogger(__name__)

HOME_WEATHER_CONDITION = {
WeatherCondition.CLEAR: "sunny",
WeatherCondition.LIGHT_CLOUDY: "partlycloudy",
WeatherCondition.CLOUDY: "cloudy",
WeatherCondition.CLOUDY_WITH_RAIN: "rainy",
WeatherCondition.CLOUDY_WITH_SNOW_RAIN: "snowy-rainy",
WeatherCondition.HEAVILY_CLOUDY: "cloudy",
WeatherCondition.HEAVILY_CLOUDY_WITH_RAIN: "rainy",
WeatherCondition.HEAVILY_CLOUDY_WITH_STRONG_RAIN: "snowy-rainy",
WeatherCondition.HEAVILY_CLOUDY_WITH_SNOW: "snowy",
WeatherCondition.HEAVILY_CLOUDY_WITH_SNOW_RAIN: "snowy-rainy",
WeatherCondition.HEAVILY_CLOUDY_WITH_THUNDER: "lightning",
WeatherCondition.HEAVILY_CLOUDY_WITH_RAIN_AND_THUNDER: "lightning-rainy",
WeatherCondition.FOGGY: "fog",
WeatherCondition.STRONG_WIND: "windy",
WeatherCondition.UNKNOWN: "",
}


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the HomematicIP Cloud weather sensor."""
Expand All @@ -35,6 +54,8 @@ async def async_setup_entry(
elif isinstance(device, (AsyncWeatherSensor, AsyncWeatherSensorPlus)):
devices.append(HomematicipWeatherSensor(home, device))

devices.append(HomematicipHomeWeather(home))

if devices:
async_add_entities(devices)

Expand Down Expand Up @@ -95,3 +116,57 @@ class HomematicipWeatherSensorPro(HomematicipWeatherSensor):
def wind_bearing(self) -> float:
"""Return the wind bearing."""
return self._device.windDirection


class HomematicipHomeWeather(HomematicipGenericDevice, WeatherEntity):
"""representation of a HomematicIP Cloud home weather."""

def __init__(self, home: AsyncHome) -> None:
"""Initialize the home weather."""
home.weather.modelType = "HmIP-Home-Weather"
super().__init__(home, home)

@property
def available(self) -> bool:
"""Device available."""
return self._home.connected

@property
def name(self) -> str:
"""Return the name of the sensor."""
return f"Weather {self._home.location.city}"

@property
def temperature(self) -> float:
"""Return the platform temperature."""
return self._device.weather.temperature

@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS

@property
def humidity(self) -> int:
"""Return the humidity."""
return self._device.weather.humidity

@property
def wind_speed(self) -> float:
"""Return the wind speed."""
return round(self._device.weather.windSpeed, 1)

@property
def wind_bearing(self) -> float:
"""Return the wind bearing."""
return self._device.weather.windDirection

@property
def attribution(self) -> str:
"""Return the attribution."""
return "Powered by Homematic IP"

@property
def condition(self) -> str:
"""Return the current condition."""
return HOME_WEATHER_CONDITION.get(self._device.weather.weatherCondition)

0 comments on commit 24f1ff0

Please sign in to comment.