Meteo france (#21065)

* Move files

* Move file

* Update .coveragerc

* Sort import and update file header

* Minor changes
This commit is contained in:
Fabian Affolter authored and GitHub committed 2019-02-15 10:57:47 +01:00
1 parent c115c89afd
commit eb573c2701
4 files changed
+46 -74

No files matched your search

@@ -1,88 +0,0 @@
"""
Support for Meteo France raining forecast.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.meteo_france/
"""
import logging
from homeassistant.components.meteo_france import (SENSOR_TYPES,
DATA_METEO_FRANCE,
CONF_CITY,
ATTRIBUTION)
from homeassistant.const import (
CONF_MONITORED_CONDITIONS, ATTR_ATTRIBUTION)
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
STATE_ATTR_FORECAST = '1h rain forecast'
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Meteo-France sensor."""
if discovery_info is None:
return
city = discovery_info[CONF_CITY]
monitored_conditions = discovery_info[CONF_MONITORED_CONDITIONS]
client = hass.data[DATA_METEO_FRANCE][city]
add_entities([MeteoFranceSensor(variable, client)
for variable in monitored_conditions],
True)
class MeteoFranceSensor(Entity):
"""Representation of a Sensor."""
def __init__(self, condition, client):
"""Initialize the sensor."""
self._condition = condition
self._client = client
self._state = None
self._data = {}
@property
def name(self):
"""Return the name of the sensor."""
return "{} {}".format(self._data["name"],
SENSOR_TYPES[self._condition][0])
@property
def state(self):
"""Return the state of the sensor."""
return self._state
@property
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
if self._condition == 'next_rain' and "rain_forecast" in self._data:
return {
**{
STATE_ATTR_FORECAST: self._data["rain_forecast"],
},
** self._data["next_rain_intervals"],
**{
ATTR_ATTRIBUTION: ATTRIBUTION
}
}
return {ATTR_ATTRIBUTION: ATTRIBUTION}
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return SENSOR_TYPES[self._condition][1]
def update(self):
"""Fetch new state data for the sensor."""
try:
self._client.update()
self._data = self._client.get_data()
self._state = self._data[self._condition]
except KeyError:
_LOGGER.error("No condition `%s` for location `%s`",
self._condition, self._data["name"])
self._state = None