Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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', '%'],
Expand Down Expand Up @@ -93,29 +91,21 @@ def setup(hass, config):
_LOGGER.error(exp)
return

client.need_rain_forecast = bool(CONF_MONITORED_CONDITIONS in location
and 'next_rain' in
location[CONF_MONITORED_CONDITIONS])
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)
hass.data[DATA_METEO_FRANCE][city].update()

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)

load_platform(
hass,
'weather',
DOMAIN,
{CONF_CITY: city},
config)
hass, 'sensor', DOMAIN, {
CONF_CITY: city,
CONF_MONITORED_CONDITIONS: monitored_conditions}, config)

load_platform(hass, 'weather', DOMAIN, {CONF_CITY: city}, config)

return True

Expand Down
Original file line number Diff line number Diff line change
@@ -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__)
Expand All @@ -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
Expand All @@ -48,8 +37,8 @@ def __init__(self, condition, client):
@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):
Expand All @@ -59,15 +48,11 @@ def state(self):
@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}

Expand All @@ -83,6 +68,6 @@ def update(self):
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Support for Meteo france weather service."""
"""Support for Meteo-France weather service."""
from datetime import datetime, timedelta
import logging

Expand All @@ -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)
Expand All @@ -40,21 +39,21 @@ def update(self):
@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
Expand All @@ -65,12 +64,12 @@ def temperature_unit(self):
@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):
Expand All @@ -83,14 +82,14 @@ def forecast(self):
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)
Expand Down