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

View File

@ -1,29 +1,27 @@
"""
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
"""Support for Meteo-France weather data."""
import datetime
import logging
import voluptuous as vol
from homeassistant.const import (
CONF_MONITORED_CONDITIONS, TEMP_CELSIUS)
from homeassistant.util import Throttle
from homeassistant.helpers.discovery import load_platform
from homeassistant.const import CONF_MONITORED_CONDITIONS, TEMP_CELSIUS
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform
from homeassistant.util import Throttle
REQUIREMENTS = ['meteofrance==0.3.4']
_LOGGER = logging.getLogger(__name__)
DOMAIN = 'meteo_france'
SCAN_INTERVAL = datetime.timedelta(minutes=5)
ATTRIBUTION = "Data provided by Météo-France"
CONF_CITY = 'city'
DEFAULT_WEATHER_CARD = True
DATA_METEO_FRANCE = 'data_meteo_france'
DEFAULT_WEATHER_CARD = True
DOMAIN = 'meteo_france'
SCAN_INTERVAL = datetime.timedelta(minutes=5)
SENSOR_TYPES = {
'rain_chance': ['Rain chance', '%'],
@ -93,8 +91,8 @@ def setup(hass, config):
_LOGGER.error(exp)
return
client.need_rain_forecast = bool(CONF_MONITORED_CONDITIONS in location
and 'next_rain' in
client.need_rain_forecast = bool(
CONF_MONITORED_CONDITIONS in location and 'next_rain' in
location[CONF_MONITORED_CONDITIONS])
hass.data[DATA_METEO_FRANCE][city] = MeteoFranceUpdater(client)
@ -103,19 +101,11 @@ def setup(hass, config):
if CONF_MONITORED_CONDITIONS in location:
monitored_conditions = location[CONF_MONITORED_CONDITIONS]
load_platform(
hass,
'sensor',
DOMAIN,
{CONF_CITY: city,
CONF_MONITORED_CONDITIONS: monitored_conditions},
config)
hass, 'sensor', DOMAIN, {
CONF_CITY: city,
CONF_MONITORED_CONDITIONS: monitored_conditions}, config)
load_platform(
hass,
'weather',
DOMAIN,
{CONF_CITY: city},
config)
load_platform(hass, 'weather', DOMAIN, {CONF_CITY: city}, config)
return True

View File

@ -1,18 +1,9 @@
"""
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/
"""
"""Support for Meteo-France raining forecast sensor."""
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.components.meteo_france import (
ATTRIBUTION, CONF_CITY, DATA_METEO_FRANCE, SENSOR_TYPES)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
@ -27,19 +18,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
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)
for variable in monitored_conditions], True)
class MeteoFranceSensor(Entity):
"""Representation of a Sensor."""
"""Representation of a Meteo-France sensor."""
def __init__(self, condition, client):
"""Initialize the sensor."""
"""Initialize the Meteo-France sensor."""
self._condition = condition
self._client = client
self._state = None
@ -48,8 +37,8 @@ class MeteoFranceSensor(Entity):
@property
def name(self):
"""Return the name of the sensor."""
return "{} {}".format(self._data["name"],
SENSOR_TYPES[self._condition][0])
return "{} {}".format(
self._data['name'], SENSOR_TYPES[self._condition][0])
@property
def state(self):
@ -59,15 +48,11 @@ class MeteoFranceSensor(Entity):
@property
def device_state_attributes(self):
"""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 {
**{
STATE_ATTR_FORECAST: self._data["rain_forecast"],
},
** self._data["next_rain_intervals"],
**{
ATTR_ATTRIBUTION: ATTRIBUTION
}
**{STATE_ATTR_FORECAST: self._data['rain_forecast']},
** self._data['next_rain_intervals'],
**{ATTR_ATTRIBUTION: ATTRIBUTION}
}
return {ATTR_ATTRIBUTION: ATTRIBUTION}
@ -83,6 +68,6 @@ class MeteoFranceSensor(Entity):
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"])
_LOGGER.error("No condition %s for location %s",
self._condition, self._data['name'])
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
import logging
@ -18,7 +18,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
return
city = discovery_info[CONF_CITY]
client = hass.data[DATA_METEO_FRANCE][city]
add_entities([MeteoFranceWeather(client)], True)
@ -40,21 +39,21 @@ class MeteoFranceWeather(WeatherEntity):
@property
def name(self):
"""Return the name of the sensor."""
return self._data["name"]
return self._data['name']
@property
def condition(self):
"""Return the current condition."""
return self.format_condition(self._data["weather"])
return self.format_condition(self._data['weather'])
@property
def temperature(self):
"""Return the platform temperature."""
return self._data["temperature"]
"""Return the temperature."""
return self._data['temperature']
@property
def humidity(self):
"""Return the platform temperature."""
"""Return the humidity."""
return None
@property
@ -65,12 +64,12 @@ class MeteoFranceWeather(WeatherEntity):
@property
def wind_speed(self):
"""Return the wind speed."""
return self._data["wind_speed"]
return self._data['wind_speed']
@property
def wind_bearing(self):
"""Return the wind bearing."""
return self._data["wind_bearing"]
return self._data['wind_bearing']
@property
def attribution(self):
@ -83,14 +82,14 @@ class MeteoFranceWeather(WeatherEntity):
reftime = datetime.now().replace(hour=12, minute=00)
reftime += timedelta(hours=24)
forecast_data = []
for key in self._data["forecast"]:
value = self._data["forecast"][key]
for key in self._data['forecast']:
value = self._data['forecast'][key]
data_dict = {
ATTR_FORECAST_TIME: reftime.isoformat(),
ATTR_FORECAST_TEMP: int(value['max_temp']),
ATTR_FORECAST_TEMP_LOW: int(value['min_temp']),
ATTR_FORECAST_CONDITION:
self.format_condition(value["weather"])
self.format_condition(value['weather'])
}
reftime = reftime + timedelta(hours=24)
forecast_data.append(data_dict)