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
|
@ -665,6 +665,7 @@ omit =
|
||||||
homeassistant/components/starlingbank/sensor.py
|
homeassistant/components/starlingbank/sensor.py
|
||||||
homeassistant/components/steam_online/sensor.py
|
homeassistant/components/steam_online/sensor.py
|
||||||
homeassistant/components/stiebel_eltron/*
|
homeassistant/components/stiebel_eltron/*
|
||||||
|
homeassistant/components/stookalert/*
|
||||||
homeassistant/components/streamlabswater/*
|
homeassistant/components/streamlabswater/*
|
||||||
homeassistant/components/suez_water/*
|
homeassistant/components/suez_water/*
|
||||||
homeassistant/components/supervisord/sensor.py
|
homeassistant/components/supervisord/sensor.py
|
||||||
|
|
|
@ -311,6 +311,7 @@ homeassistant/components/sql/* @dgomes
|
||||||
homeassistant/components/starline/* @anonym-tsk
|
homeassistant/components/starline/* @anonym-tsk
|
||||||
homeassistant/components/statistics/* @fabaff
|
homeassistant/components/statistics/* @fabaff
|
||||||
homeassistant/components/stiebel_eltron/* @fucm
|
homeassistant/components/stiebel_eltron/* @fucm
|
||||||
|
homeassistant/components/stookalert/* @fwestenberg
|
||||||
homeassistant/components/stream/* @hunterjm
|
homeassistant/components/stream/* @hunterjm
|
||||||
homeassistant/components/stt/* @pvizeli
|
homeassistant/components/stt/* @pvizeli
|
||||||
homeassistant/components/suez_water/* @ooii
|
homeassistant/components/suez_water/* @ooii
|
||||||
|
|
1
homeassistant/components/stookalert/__init__.py
Normal file
1
homeassistant/components/stookalert/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
"""The Stookalert component."""
|
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()
|
8
homeassistant/components/stookalert/manifest.json
Normal file
8
homeassistant/components/stookalert/manifest.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"domain": "stookalert",
|
||||||
|
"name": "RIVM Stookalert",
|
||||||
|
"documentation": "https://www.home-assistant.io/integrations/stookalert",
|
||||||
|
"dependencies": [],
|
||||||
|
"codeowners": ["@fwestenberg"],
|
||||||
|
"requirements": ["stookalert==0.1.4"]
|
||||||
|
}
|
|
@ -1902,6 +1902,9 @@ statsd==3.2.1
|
||||||
# homeassistant.components.steam_online
|
# homeassistant.components.steam_online
|
||||||
steamodd==4.21
|
steamodd==4.21
|
||||||
|
|
||||||
|
# homeassistant.components.stookalert
|
||||||
|
stookalert==0.1.4
|
||||||
|
|
||||||
# homeassistant.components.streamlabswater
|
# homeassistant.components.streamlabswater
|
||||||
streamlabswater==1.0.1
|
streamlabswater==1.0.1
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue