Meteo france (#21065)

* Move files

* Move file

* Update .coveragerc

* Sort import and update file header

* Minor changes
This commit is contained in:
Fabian Affolter 2019-02-15 10:57:47 +01:00 committed by GitHub
parent c115c89afd
commit eb573c2701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 74 deletions

View File

@ -317,6 +317,7 @@ omit =
homeassistant/components/media_player/yamaha_musiccast.py homeassistant/components/media_player/yamaha_musiccast.py
homeassistant/components/media_player/yamaha.py homeassistant/components/media_player/yamaha.py
homeassistant/components/media_player/ziggo_mediabox_xl.py homeassistant/components/media_player/ziggo_mediabox_xl.py
homeassistant/components/meteo_france/*
homeassistant/components/mochad/* homeassistant/components/mochad/*
homeassistant/components/modbus/* homeassistant/components/modbus/*
homeassistant/components/mychevy/* homeassistant/components/mychevy/*
@ -326,7 +327,6 @@ omit =
homeassistant/components/nest/* homeassistant/components/nest/*
homeassistant/components/netatmo/* homeassistant/components/netatmo/*
homeassistant/components/netgear_lte/* homeassistant/components/netgear_lte/*
homeassistant/components/meteo_france.py
homeassistant/components/notify/aws_lambda.py homeassistant/components/notify/aws_lambda.py
homeassistant/components/notify/aws_sns.py homeassistant/components/notify/aws_sns.py
homeassistant/components/notify/aws_sqs.py homeassistant/components/notify/aws_sqs.py
@ -483,7 +483,6 @@ omit =
homeassistant/components/sensor/loopenergy.py homeassistant/components/sensor/loopenergy.py
homeassistant/components/sensor/lyft.py homeassistant/components/sensor/lyft.py
homeassistant/components/sensor/magicseaweed.py homeassistant/components/sensor/magicseaweed.py
homeassistant/components/sensor/meteo_france.py
homeassistant/components/sensor/metoffice.py homeassistant/components/sensor/metoffice.py
homeassistant/components/sensor/miflora.py homeassistant/components/sensor/miflora.py
homeassistant/components/sensor/mitemp_bt.py homeassistant/components/sensor/mitemp_bt.py
@ -651,7 +650,6 @@ omit =
homeassistant/components/weather/buienradar.py homeassistant/components/weather/buienradar.py
homeassistant/components/weather/darksky.py homeassistant/components/weather/darksky.py
homeassistant/components/weather/met.py homeassistant/components/weather/met.py
homeassistant/components/weather/meteo_france.py
homeassistant/components/weather/metoffice.py homeassistant/components/weather/metoffice.py
homeassistant/components/weather/openweathermap.py homeassistant/components/weather/openweathermap.py
homeassistant/components/weather/zamg.py homeassistant/components/weather/zamg.py

View File

@ -1,29 +1,27 @@
""" """Support for Meteo-France weather data."""
Support for Meteo France weather forecast.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/meteo_france/
"""
import logging
import datetime import datetime
import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.const import ( from homeassistant.const import CONF_MONITORED_CONDITIONS, TEMP_CELSIUS
CONF_MONITORED_CONDITIONS, TEMP_CELSIUS)
from homeassistant.util import Throttle
from homeassistant.helpers.discovery import load_platform
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform
from homeassistant.util import Throttle
REQUIREMENTS = ['meteofrance==0.3.4'] REQUIREMENTS = ['meteofrance==0.3.4']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = 'meteo_france'
SCAN_INTERVAL = datetime.timedelta(minutes=5)
ATTRIBUTION = "Data provided by Météo-France" ATTRIBUTION = "Data provided by Météo-France"
CONF_CITY = 'city' CONF_CITY = 'city'
DEFAULT_WEATHER_CARD = True
DATA_METEO_FRANCE = 'data_meteo_france' DATA_METEO_FRANCE = 'data_meteo_france'
DEFAULT_WEATHER_CARD = True
DOMAIN = 'meteo_france'
SCAN_INTERVAL = datetime.timedelta(minutes=5)
SENSOR_TYPES = { SENSOR_TYPES = {
'rain_chance': ['Rain chance', '%'], 'rain_chance': ['Rain chance', '%'],
@ -93,9 +91,9 @@ def setup(hass, config):
_LOGGER.error(exp) _LOGGER.error(exp)
return return
client.need_rain_forecast = bool(CONF_MONITORED_CONDITIONS in location client.need_rain_forecast = bool(
and 'next_rain' in CONF_MONITORED_CONDITIONS in location and 'next_rain' in
location[CONF_MONITORED_CONDITIONS]) location[CONF_MONITORED_CONDITIONS])
hass.data[DATA_METEO_FRANCE][city] = MeteoFranceUpdater(client) hass.data[DATA_METEO_FRANCE][city] = MeteoFranceUpdater(client)
hass.data[DATA_METEO_FRANCE][city].update() hass.data[DATA_METEO_FRANCE][city].update()
@ -103,19 +101,11 @@ def setup(hass, config):
if CONF_MONITORED_CONDITIONS in location: if CONF_MONITORED_CONDITIONS in location:
monitored_conditions = location[CONF_MONITORED_CONDITIONS] monitored_conditions = location[CONF_MONITORED_CONDITIONS]
load_platform( load_platform(
hass, hass, 'sensor', DOMAIN, {
'sensor', CONF_CITY: city,
DOMAIN, CONF_MONITORED_CONDITIONS: monitored_conditions}, config)
{CONF_CITY: city,
CONF_MONITORED_CONDITIONS: monitored_conditions},
config)
load_platform( load_platform(hass, 'weather', DOMAIN, {CONF_CITY: city}, config)
hass,
'weather',
DOMAIN,
{CONF_CITY: city},
config)
return True return True

View File

@ -1,18 +1,9 @@
""" """Support for Meteo-France raining forecast sensor."""
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 import logging
from homeassistant.components.meteo_france import (
from homeassistant.components.meteo_france import (SENSOR_TYPES, ATTRIBUTION, CONF_CITY, DATA_METEO_FRANCE, SENSOR_TYPES)
DATA_METEO_FRANCE, from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
CONF_CITY,
ATTRIBUTION)
from homeassistant.const import (
CONF_MONITORED_CONDITIONS, ATTR_ATTRIBUTION)
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -27,19 +18,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
city = discovery_info[CONF_CITY] city = discovery_info[CONF_CITY]
monitored_conditions = discovery_info[CONF_MONITORED_CONDITIONS] monitored_conditions = discovery_info[CONF_MONITORED_CONDITIONS]
client = hass.data[DATA_METEO_FRANCE][city] client = hass.data[DATA_METEO_FRANCE][city]
add_entities([MeteoFranceSensor(variable, client) add_entities([MeteoFranceSensor(variable, client)
for variable in monitored_conditions], for variable in monitored_conditions], True)
True)
class MeteoFranceSensor(Entity): class MeteoFranceSensor(Entity):
"""Representation of a Sensor.""" """Representation of a Meteo-France sensor."""
def __init__(self, condition, client): def __init__(self, condition, client):
"""Initialize the sensor.""" """Initialize the Meteo-France sensor."""
self._condition = condition self._condition = condition
self._client = client self._client = client
self._state = None self._state = None
@ -48,8 +37,8 @@ class MeteoFranceSensor(Entity):
@property @property
def name(self): def name(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return "{} {}".format(self._data["name"], return "{} {}".format(
SENSOR_TYPES[self._condition][0]) self._data['name'], SENSOR_TYPES[self._condition][0])
@property @property
def state(self): def state(self):
@ -59,15 +48,11 @@ class MeteoFranceSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the sensor.""" """Return the state attributes of the sensor."""
if self._condition == 'next_rain' and "rain_forecast" in self._data: if self._condition == 'next_rain' and 'rain_forecast' in self._data:
return { return {
**{ **{STATE_ATTR_FORECAST: self._data['rain_forecast']},
STATE_ATTR_FORECAST: self._data["rain_forecast"], ** self._data['next_rain_intervals'],
}, **{ATTR_ATTRIBUTION: ATTRIBUTION}
** self._data["next_rain_intervals"],
**{
ATTR_ATTRIBUTION: ATTRIBUTION
}
} }
return {ATTR_ATTRIBUTION: ATTRIBUTION} return {ATTR_ATTRIBUTION: ATTRIBUTION}
@ -83,6 +68,6 @@ class MeteoFranceSensor(Entity):
self._data = self._client.get_data() self._data = self._client.get_data()
self._state = self._data[self._condition] self._state = self._data[self._condition]
except KeyError: except KeyError:
_LOGGER.error("No condition `%s` for location `%s`", _LOGGER.error("No condition %s for location %s",
self._condition, self._data["name"]) self._condition, self._data['name'])
self._state = None self._state = None

View File

@ -1,4 +1,4 @@
"""Support for Meteo france weather service.""" """Support for Meteo-France weather service."""
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
@ -18,7 +18,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
return return
city = discovery_info[CONF_CITY] city = discovery_info[CONF_CITY]
client = hass.data[DATA_METEO_FRANCE][city] client = hass.data[DATA_METEO_FRANCE][city]
add_entities([MeteoFranceWeather(client)], True) add_entities([MeteoFranceWeather(client)], True)
@ -40,21 +39,21 @@ class MeteoFranceWeather(WeatherEntity):
@property @property
def name(self): def name(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return self._data["name"] return self._data['name']
@property @property
def condition(self): def condition(self):
"""Return the current condition.""" """Return the current condition."""
return self.format_condition(self._data["weather"]) return self.format_condition(self._data['weather'])
@property @property
def temperature(self): def temperature(self):
"""Return the platform temperature.""" """Return the temperature."""
return self._data["temperature"] return self._data['temperature']
@property @property
def humidity(self): def humidity(self):
"""Return the platform temperature.""" """Return the humidity."""
return None return None
@property @property
@ -65,12 +64,12 @@ class MeteoFranceWeather(WeatherEntity):
@property @property
def wind_speed(self): def wind_speed(self):
"""Return the wind speed.""" """Return the wind speed."""
return self._data["wind_speed"] return self._data['wind_speed']
@property @property
def wind_bearing(self): def wind_bearing(self):
"""Return the wind bearing.""" """Return the wind bearing."""
return self._data["wind_bearing"] return self._data['wind_bearing']
@property @property
def attribution(self): def attribution(self):
@ -83,14 +82,14 @@ class MeteoFranceWeather(WeatherEntity):
reftime = datetime.now().replace(hour=12, minute=00) reftime = datetime.now().replace(hour=12, minute=00)
reftime += timedelta(hours=24) reftime += timedelta(hours=24)
forecast_data = [] forecast_data = []
for key in self._data["forecast"]: for key in self._data['forecast']:
value = self._data["forecast"][key] value = self._data['forecast'][key]
data_dict = { data_dict = {
ATTR_FORECAST_TIME: reftime.isoformat(), ATTR_FORECAST_TIME: reftime.isoformat(),
ATTR_FORECAST_TEMP: int(value['max_temp']), ATTR_FORECAST_TEMP: int(value['max_temp']),
ATTR_FORECAST_TEMP_LOW: int(value['min_temp']), ATTR_FORECAST_TEMP_LOW: int(value['min_temp']),
ATTR_FORECAST_CONDITION: ATTR_FORECAST_CONDITION:
self.format_condition(value["weather"]) self.format_condition(value['weather'])
} }
reftime = reftime + timedelta(hours=24) reftime = reftime + timedelta(hours=24)
forecast_data.append(data_dict) forecast_data.append(data_dict)