Add Météo France icons + device_class (#26441)
* Add Météo France icons * Add Météo France device_class (temperature) + use constants * Fix weather alert info log * Use new f"{...} {...}" format for sensor namepull/26554/head
parent
adf6852acc
commit
d746035a91
|
@ -4,70 +4,17 @@ import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_MONITORED_CONDITIONS, TEMP_CELSIUS
|
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.discovery import load_platform
|
from homeassistant.helpers.discovery import load_platform
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
|
from .const import DOMAIN, CONF_CITY, SENSOR_TYPES, DATA_METEO_FRANCE
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by Météo-France"
|
|
||||||
|
|
||||||
CONF_CITY = "city"
|
|
||||||
|
|
||||||
DATA_METEO_FRANCE = "data_meteo_france"
|
|
||||||
DEFAULT_WEATHER_CARD = True
|
|
||||||
DOMAIN = "meteo_france"
|
|
||||||
|
|
||||||
SCAN_INTERVAL = datetime.timedelta(minutes=5)
|
SCAN_INTERVAL = datetime.timedelta(minutes=5)
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
|
||||||
"rain_chance": ["Rain chance", "%"],
|
|
||||||
"freeze_chance": ["Freeze chance", "%"],
|
|
||||||
"thunder_chance": ["Thunder chance", "%"],
|
|
||||||
"snow_chance": ["Snow chance", "%"],
|
|
||||||
"weather": ["Weather", None],
|
|
||||||
"wind_speed": ["Wind Speed", "km/h"],
|
|
||||||
"next_rain": ["Next rain", "min"],
|
|
||||||
"temperature": ["Temperature", TEMP_CELSIUS],
|
|
||||||
"uv": ["UV", None],
|
|
||||||
"weather_alert": ["Weather Alert", None],
|
|
||||||
}
|
|
||||||
|
|
||||||
CONDITION_CLASSES = {
|
|
||||||
"clear-night": ["Nuit Claire"],
|
|
||||||
"cloudy": ["Très nuageux"],
|
|
||||||
"fog": ["Brume ou bancs de brouillard", "Brouillard", "Brouillard givrant"],
|
|
||||||
"hail": ["Risque de grêle"],
|
|
||||||
"lightning": ["Risque d'orages", "Orages"],
|
|
||||||
"lightning-rainy": ["Pluie orageuses", "Pluies orageuses", "Averses orageuses"],
|
|
||||||
"partlycloudy": ["Ciel voilé", "Ciel voilé nuit", "Éclaircies"],
|
|
||||||
"pouring": ["Pluie forte"],
|
|
||||||
"rainy": [
|
|
||||||
"Bruine / Pluie faible",
|
|
||||||
"Bruine",
|
|
||||||
"Pluie faible",
|
|
||||||
"Pluies éparses / Rares averses",
|
|
||||||
"Pluies éparses",
|
|
||||||
"Rares averses",
|
|
||||||
"Pluie / Averses",
|
|
||||||
"Averses",
|
|
||||||
"Pluie",
|
|
||||||
],
|
|
||||||
"snowy": [
|
|
||||||
"Neige / Averses de neige",
|
|
||||||
"Neige",
|
|
||||||
"Averses de neige",
|
|
||||||
"Neige forte",
|
|
||||||
"Quelques flocons",
|
|
||||||
],
|
|
||||||
"snowy-rainy": ["Pluie et neige", "Pluie verglaçante"],
|
|
||||||
"sunny": ["Ensoleillé"],
|
|
||||||
"windy": [],
|
|
||||||
"windy-variant": [],
|
|
||||||
"exceptional": [],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def has_all_unique_cities(value):
|
def has_all_unique_cities(value):
|
||||||
"""Validate that all cities are unique."""
|
"""Validate that all cities are unique."""
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
"""Meteo-France component constants."""
|
||||||
|
|
||||||
|
from homeassistant.const import TEMP_CELSIUS
|
||||||
|
|
||||||
|
DOMAIN = "meteo_france"
|
||||||
|
DATA_METEO_FRANCE = "data_meteo_france"
|
||||||
|
ATTRIBUTION = "Data provided by Météo-France"
|
||||||
|
|
||||||
|
CONF_CITY = "city"
|
||||||
|
|
||||||
|
DEFAULT_WEATHER_CARD = True
|
||||||
|
|
||||||
|
SENSOR_TYPE_NAME = "name"
|
||||||
|
SENSOR_TYPE_UNIT = "unit"
|
||||||
|
SENSOR_TYPE_ICON = "icon"
|
||||||
|
SENSOR_TYPE_CLASS = "device_class"
|
||||||
|
SENSOR_TYPES = {
|
||||||
|
"rain_chance": {
|
||||||
|
SENSOR_TYPE_NAME: "Rain chance",
|
||||||
|
SENSOR_TYPE_UNIT: "%",
|
||||||
|
SENSOR_TYPE_ICON: "mdi:weather-rainy",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
"freeze_chance": {
|
||||||
|
SENSOR_TYPE_NAME: "Freeze chance",
|
||||||
|
SENSOR_TYPE_UNIT: "%",
|
||||||
|
SENSOR_TYPE_ICON: "mdi:snowflake",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
"thunder_chance": {
|
||||||
|
SENSOR_TYPE_NAME: "Thunder chance",
|
||||||
|
SENSOR_TYPE_UNIT: "%",
|
||||||
|
SENSOR_TYPE_ICON: "mdi:weather-lightning",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
"snow_chance": {
|
||||||
|
SENSOR_TYPE_NAME: "Snow chance",
|
||||||
|
SENSOR_TYPE_UNIT: "%",
|
||||||
|
SENSOR_TYPE_ICON: "mdi:weather-snowy",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
"weather": {
|
||||||
|
SENSOR_TYPE_NAME: "Weather",
|
||||||
|
SENSOR_TYPE_UNIT: None,
|
||||||
|
SENSOR_TYPE_ICON: "mdi:weather-partly-cloudy",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
"wind_speed": {
|
||||||
|
SENSOR_TYPE_NAME: "Wind Speed",
|
||||||
|
SENSOR_TYPE_UNIT: "km/h",
|
||||||
|
SENSOR_TYPE_ICON: "mdi:weather-windy",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
"next_rain": {
|
||||||
|
SENSOR_TYPE_NAME: "Next rain",
|
||||||
|
SENSOR_TYPE_UNIT: "min",
|
||||||
|
SENSOR_TYPE_ICON: "mdi:weather-rainy",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
"temperature": {
|
||||||
|
SENSOR_TYPE_NAME: "Temperature",
|
||||||
|
SENSOR_TYPE_UNIT: TEMP_CELSIUS,
|
||||||
|
SENSOR_TYPE_ICON: "mdi:thermometer",
|
||||||
|
SENSOR_TYPE_CLASS: "temperature",
|
||||||
|
},
|
||||||
|
"uv": {
|
||||||
|
SENSOR_TYPE_NAME: "UV",
|
||||||
|
SENSOR_TYPE_UNIT: None,
|
||||||
|
SENSOR_TYPE_ICON: "mdi:sunglasses",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
"weather_alert": {
|
||||||
|
SENSOR_TYPE_NAME: "Weather Alert",
|
||||||
|
SENSOR_TYPE_UNIT: None,
|
||||||
|
SENSOR_TYPE_ICON: "mdi:weather-cloudy-alert",
|
||||||
|
SENSOR_TYPE_CLASS: None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
CONDITION_CLASSES = {
|
||||||
|
"clear-night": ["Nuit Claire"],
|
||||||
|
"cloudy": ["Très nuageux"],
|
||||||
|
"fog": ["Brume ou bancs de brouillard", "Brouillard", "Brouillard givrant"],
|
||||||
|
"hail": ["Risque de grêle"],
|
||||||
|
"lightning": ["Risque d'orages", "Orages"],
|
||||||
|
"lightning-rainy": ["Pluie orageuses", "Pluies orageuses", "Averses orageuses"],
|
||||||
|
"partlycloudy": ["Ciel voilé", "Ciel voilé nuit", "Éclaircies"],
|
||||||
|
"pouring": ["Pluie forte"],
|
||||||
|
"rainy": [
|
||||||
|
"Bruine / Pluie faible",
|
||||||
|
"Bruine",
|
||||||
|
"Pluie faible",
|
||||||
|
"Pluies éparses / Rares averses",
|
||||||
|
"Pluies éparses",
|
||||||
|
"Rares averses",
|
||||||
|
"Pluie / Averses",
|
||||||
|
"Averses",
|
||||||
|
"Pluie",
|
||||||
|
],
|
||||||
|
"snowy": [
|
||||||
|
"Neige / Averses de neige",
|
||||||
|
"Neige",
|
||||||
|
"Averses de neige",
|
||||||
|
"Neige forte",
|
||||||
|
"Quelques flocons",
|
||||||
|
],
|
||||||
|
"snowy-rainy": ["Pluie et neige", "Pluie verglaçante"],
|
||||||
|
"sunny": ["Ensoleillé"],
|
||||||
|
"windy": [],
|
||||||
|
"windy-variant": [],
|
||||||
|
"exceptional": [],
|
||||||
|
}
|
|
@ -4,7 +4,16 @@ import logging
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
|
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from . import ATTRIBUTION, CONF_CITY, DATA_METEO_FRANCE, SENSOR_TYPES
|
from .const import (
|
||||||
|
ATTRIBUTION,
|
||||||
|
CONF_CITY,
|
||||||
|
DATA_METEO_FRANCE,
|
||||||
|
SENSOR_TYPES,
|
||||||
|
SENSOR_TYPE_ICON,
|
||||||
|
SENSOR_TYPE_NAME,
|
||||||
|
SENSOR_TYPE_UNIT,
|
||||||
|
SENSOR_TYPE_CLASS,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -44,7 +53,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
alert_watcher = None
|
alert_watcher = None
|
||||||
else:
|
else:
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Weather alert watcher added for %s" "in department %s",
|
"Weather alert watcher added for %s in department %s",
|
||||||
city,
|
city,
|
||||||
datas["dept"],
|
datas["dept"],
|
||||||
)
|
)
|
||||||
|
@ -79,7 +88,7 @@ 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"], SENSOR_TYPES[self._condition][0])
|
return f"{self._data['name']} {SENSOR_TYPES[self._condition][SENSOR_TYPE_NAME]}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
@ -111,7 +120,17 @@ class MeteoFranceSensor(Entity):
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return SENSOR_TYPES[self._condition][1]
|
return SENSOR_TYPES[self._condition][SENSOR_TYPE_UNIT]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Return the icon."""
|
||||||
|
return SENSOR_TYPES[self._condition][SENSOR_TYPE_ICON]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class of the sensor."""
|
||||||
|
return SENSOR_TYPES[self._condition][SENSOR_TYPE_CLASS]
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for the sensor."""
|
"""Fetch new state data for the sensor."""
|
||||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.components.weather import (
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.const import TEMP_CELSIUS
|
from homeassistant.const import TEMP_CELSIUS
|
||||||
|
|
||||||
from . import ATTRIBUTION, CONDITION_CLASSES, CONF_CITY, DATA_METEO_FRANCE
|
from .const import ATTRIBUTION, CONDITION_CLASSES, CONF_CITY, DATA_METEO_FRANCE
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue