Add Stookalert integration (#30306)
* Added Stookalert integration * Added Stookalert integration * Added Stookalert integration * Solved comments * Flake8 change * Bump stookalert to version 1.1.2 * Fixed attributes and state * Get method for private variables * Update to stookalert 0.1.4 * Code optimization * Update requirements
This commit is contained in:
parent
d659807b6f
commit
498bec4a61
6 changed files with 93 additions and 0 deletions
79
homeassistant/components/stookalert/binary_sensor.py
Normal file
79
homeassistant/components/stookalert/binary_sensor.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
"""This component provides support for Stookalert Binary Sensor."""
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
import stookalert
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorDevice
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=60)
|
||||
CONF_PROVINCE = "province"
|
||||
DEFAULT_NAME = "Stookalert"
|
||||
ATTRIBUTION = "Data provided by rivm.nl"
|
||||
PROVINCES = [
|
||||
"Drenthe",
|
||||
"Flevoland",
|
||||
"Friesland",
|
||||
"Gelderland",
|
||||
"Groningen",
|
||||
"Limburg",
|
||||
"Noord-Brabant",
|
||||
"Noord-Holland",
|
||||
"Overijssel",
|
||||
"Utrecht",
|
||||
"Zeeland",
|
||||
"Zuid-Holland",
|
||||
]
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_PROVINCE): vol.In(PROVINCES),
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Stookalert binary sensor platform."""
|
||||
province = config[CONF_PROVINCE]
|
||||
name = config[CONF_NAME]
|
||||
api_handler = stookalert.stookalert(province)
|
||||
add_entities([StookalertBinarySensor(name, api_handler)], update_before_add=True)
|
||||
|
||||
|
||||
class StookalertBinarySensor(BinarySensorDevice):
|
||||
"""An implementation of RIVM Stookalert."""
|
||||
|
||||
def __init__(self, name, api_handler):
|
||||
"""Initialize a Stookalert device."""
|
||||
self._name = name
|
||||
self._api_handler = api_handler
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the attribute(s) of the sensor."""
|
||||
state_attr = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
|
||||
if self._api_handler.last_updated is not None:
|
||||
state_attr["last_updated"] = self._api_handler.last_updated.isoformat()
|
||||
|
||||
return state_attr
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return True if the Alert is active."""
|
||||
return self._api_handler.state == 1
|
||||
|
||||
def update(self):
|
||||
"""Update the data from the Stookalert handler."""
|
||||
self._api_handler.get_alerts()
|
Loading…
Add table
Add a link
Reference in a new issue