Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new sensor meteoalarm to get weather alerts in Europe #23663

Merged
merged 25 commits into from May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -347,6 +347,7 @@ omit =
homeassistant/components/message_bird/notify.py
homeassistant/components/met/weather.py
homeassistant/components/meteo_france/*
homeassistant/components/meteoalarm/sensor.py
rolfberkenbosch marked this conversation as resolved.
Show resolved Hide resolved
homeassistant/components/metoffice/sensor.py
homeassistant/components/metoffice/weather.py
homeassistant/components/microsoft/tts.py
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -143,6 +143,7 @@ homeassistant/components/matrix/* @tinloaf
homeassistant/components/mediaroom/* @dgomes
homeassistant/components/melissa/* @kennedyshead
homeassistant/components/met/* @danielhiversen
homeassistant/components/meteoalarm/* @rolfberkenbosch
homeassistant/components/miflora/* @danielhiversen @ChristianKuehnel
homeassistant/components/mill/* @danielhiversen
homeassistant/components/min_max/* @fabaff
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/meteoalarm/__init__.py
@@ -0,0 +1 @@
"""The meteoalarm component."""
10 changes: 10 additions & 0 deletions homeassistant/components/meteoalarm/manifest.json
@@ -0,0 +1,10 @@
{
"domain": "meteoalarm",
"name": "meteoalarm",
"documentation": "https://www.home-assistant.io/components/meteoalarm",
"requirements": [
"meteoalertapi==0.0.8"
],
"dependencies": [],
"codeowners": ["@rolfberkenbosch"]
}
93 changes: 93 additions & 0 deletions homeassistant/components/meteoalarm/sensor.py
@@ -0,0 +1,93 @@
"""Sensor for MeteoAlarm.eu."""
from datetime import timedelta
import logging

import voluptuous as vol

from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
ATTR_ATTRIBUTION, CONF_NAME)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)

CONF_COUNTRY = 'country'
CONF_PROVINCE = 'province'
CONF_LANGUAGE = 'language'

ATTRIBUTION = ("Information provided by MeteoAlarm.")

DEFAULT_NAME = 'meteoalarm'

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 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([MeteoAlertSensor(api, name)], True)


class MeteoAlertSensor(Entity):
"""Representation of a MeteoAlert sensor."""

def __init__(self, api, name):
"""Initialize the MeteoAlert sensor."""
self._name = name
self._attributes = {}
self._state = None
self._api = api

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def state(self):
"""Return the state of the sensor."""
return self._state

@property
def device_state_attributes(self):
"""Return the state attributes."""
self._attributes[ATTR_ATTRIBUTION] = ATTRIBUTION
return self._attributes
rolfberkenbosch marked this conversation as resolved.
Show resolved Hide resolved

@property
def icon(self):
"""Icon to use in the frontend."""
return ICON

def update(self):
"""Update device state."""
alert = self._api.get_alert()
rolfberkenbosch marked this conversation as resolved.
Show resolved Hide resolved
if alert:
self._attributes = alert
self._state = alert.pop('headline')
else:
self._attributes = {}
self._state = 'no warnings'
rolfberkenbosch marked this conversation as resolved.
Show resolved Hide resolved
rolfberkenbosch marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions requirements_all.txt
Expand Up @@ -703,6 +703,9 @@ mbddns==0.1.2
# homeassistant.components.message_bird
messagebird==1.2.0

# homeassistant.components.meteoalarm
meteoalertapi==0.0.8

# homeassistant.components.meteo_france
meteofrance==0.3.4

Expand Down