mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Added new binary sensor meteoalarm to get weather alerts in Europe (#23663)
* Added new component meteoalarm * Update sensor.py * Update manifest.json * Update manifest.json * Update manifest.json * Added file CODEOWNERS * Modified some code, thanks @amelchio * removed Throttle because is not being used anymore * Update _attributes ad _state * some cleanup * Update sensor.py Change sensor to binarysensor * Rename sensor.py to binary_sensor.py rename the file * Update binary_sensor.py Removed BinarySensorDevice from class * Update binary_sensor.py Made a mistake with BinarySensorDevice * Update binary_sensor.py clean up white spaces * Update binary_sensor.py Fix BinarySensorDevice * Update binary_sensor.py cleanup the import libs * modified __init__ * fix * final fix, thanks @amelchio * forgot to change the sensor.py * correct some typo in text * fix typos * fix another typo * fix typo
This commit is contained in:
parent
1f551e5f6f
commit
c07c557298
@ -348,6 +348,7 @@ omit =
|
|||||||
homeassistant/components/message_bird/notify.py
|
homeassistant/components/message_bird/notify.py
|
||||||
homeassistant/components/met/weather.py
|
homeassistant/components/met/weather.py
|
||||||
homeassistant/components/meteo_france/*
|
homeassistant/components/meteo_france/*
|
||||||
|
homeassistant/components/meteoalarm/*
|
||||||
homeassistant/components/metoffice/sensor.py
|
homeassistant/components/metoffice/sensor.py
|
||||||
homeassistant/components/metoffice/weather.py
|
homeassistant/components/metoffice/weather.py
|
||||||
homeassistant/components/microsoft/tts.py
|
homeassistant/components/microsoft/tts.py
|
||||||
|
@ -144,6 +144,7 @@ homeassistant/components/matrix/* @tinloaf
|
|||||||
homeassistant/components/mediaroom/* @dgomes
|
homeassistant/components/mediaroom/* @dgomes
|
||||||
homeassistant/components/melissa/* @kennedyshead
|
homeassistant/components/melissa/* @kennedyshead
|
||||||
homeassistant/components/met/* @danielhiversen
|
homeassistant/components/met/* @danielhiversen
|
||||||
|
homeassistant/components/meteoalarm/* @rolfberkenbosch
|
||||||
homeassistant/components/miflora/* @danielhiversen @ChristianKuehnel
|
homeassistant/components/miflora/* @danielhiversen @ChristianKuehnel
|
||||||
homeassistant/components/mill/* @danielhiversen
|
homeassistant/components/mill/* @danielhiversen
|
||||||
homeassistant/components/min_max/* @fabaff
|
homeassistant/components/min_max/* @fabaff
|
||||||
|
1
homeassistant/components/meteoalarm/__init__.py
Normal file
1
homeassistant/components/meteoalarm/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""The meteoalarm component."""
|
99
homeassistant/components/meteoalarm/binary_sensor.py
Normal file
99
homeassistant/components/meteoalarm/binary_sensor.py
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
"""Binary Sensor for MeteoAlarm.eu."""
|
||||||
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components.binary_sensor import (
|
||||||
|
PLATFORM_SCHEMA, BinarySensorDevice)
|
||||||
|
from homeassistant.const import (
|
||||||
|
ATTR_ATTRIBUTION, CONF_NAME)
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_COUNTRY = 'country'
|
||||||
|
CONF_PROVINCE = 'province'
|
||||||
|
CONF_LANGUAGE = 'language'
|
||||||
|
|
||||||
|
ATTRIBUTION = "Information provided by MeteoAlarm."
|
||||||
|
|
||||||
|
DEFAULT_NAME = 'meteoalarm'
|
||||||
|
DEFAULT_DEVICE_CLASS = 'safety'
|
||||||
|
|
||||||
|
ICON = 'mdi:alert'
|
||||||
|
|
||||||
|
SCAN_INTERVAL = timedelta(minutes=30)
|
||||||
|
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_COUNTRY): cv.string,
|
||||||
|
vol.Required(CONF_PROVINCE): cv.string,
|
||||||
|
vol.Optional(CONF_LANGUAGE, default='en'): cv.string,
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
"""Set up the MeteoAlarm binary sensor platform."""
|
||||||
|
from meteoalertapi import Meteoalert
|
||||||
|
|
||||||
|
country = config[CONF_COUNTRY]
|
||||||
|
province = config[CONF_PROVINCE]
|
||||||
|
language = config[CONF_LANGUAGE]
|
||||||
|
name = config[CONF_NAME]
|
||||||
|
|
||||||
|
try:
|
||||||
|
api = Meteoalert(country, province, language)
|
||||||
|
except KeyError():
|
||||||
|
_LOGGER.error("Wrong country digits, or province name")
|
||||||
|
return
|
||||||
|
|
||||||
|
add_entities([MeteoAlertBinarySensor(api, name)], True)
|
||||||
|
|
||||||
|
|
||||||
|
class MeteoAlertBinarySensor(BinarySensorDevice):
|
||||||
|
"""Representation of a MeteoAlert binary sensor."""
|
||||||
|
|
||||||
|
def __init__(self, api, name):
|
||||||
|
"""Initialize the MeteoAlert binary sensor."""
|
||||||
|
self._name = name
|
||||||
|
self._attributes = {}
|
||||||
|
self._state = None
|
||||||
|
self._api = api
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the binary sensor."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self):
|
||||||
|
"""Return the status of the binary sensor."""
|
||||||
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the state attributes."""
|
||||||
|
self._attributes[ATTR_ATTRIBUTION] = ATTRIBUTION
|
||||||
|
return self._attributes
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Icon to use in the frontend."""
|
||||||
|
return ICON
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the class of this binary sensor."""
|
||||||
|
return DEFAULT_DEVICE_CLASS
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Update device state."""
|
||||||
|
alert = self._api.get_alert()
|
||||||
|
if alert:
|
||||||
|
self._attributes = alert
|
||||||
|
self._state = True
|
||||||
|
else:
|
||||||
|
self._attributes = {}
|
||||||
|
self._state = False
|
10
homeassistant/components/meteoalarm/manifest.json
Normal file
10
homeassistant/components/meteoalarm/manifest.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"domain": "meteoalarm",
|
||||||
|
"name": "meteoalarm",
|
||||||
|
"documentation": "https://www.home-assistant.io/components/meteoalarm",
|
||||||
|
"requirements": [
|
||||||
|
"meteoalertapi==0.0.8"
|
||||||
|
],
|
||||||
|
"dependencies": [],
|
||||||
|
"codeowners": ["@rolfberkenbosch"]
|
||||||
|
}
|
@ -706,6 +706,9 @@ mbddns==0.1.2
|
|||||||
# homeassistant.components.message_bird
|
# homeassistant.components.message_bird
|
||||||
messagebird==1.2.0
|
messagebird==1.2.0
|
||||||
|
|
||||||
|
# homeassistant.components.meteoalarm
|
||||||
|
meteoalertapi==0.0.8
|
||||||
|
|
||||||
# homeassistant.components.meteo_france
|
# homeassistant.components.meteo_france
|
||||||
meteofrance==0.3.4
|
meteofrance==0.3.4
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user