mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Fix Meteoalarm expired alerts (#56255)
This commit is contained in:
parent
28b4b5407b
commit
1609d069bb
@ -12,6 +12,7 @@ from homeassistant.components.binary_sensor import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
|
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -85,10 +86,14 @@ class MeteoAlertBinarySensor(BinarySensorEntity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update device state."""
|
"""Update device state."""
|
||||||
|
self._attributes = {}
|
||||||
|
self._state = False
|
||||||
|
|
||||||
alert = self._api.get_alert()
|
alert = self._api.get_alert()
|
||||||
if alert:
|
if alert:
|
||||||
self._attributes = alert
|
expiration_date = dt_util.parse_datetime(alert["expires"])
|
||||||
self._state = True
|
now = dt_util.utcnow()
|
||||||
else:
|
|
||||||
self._attributes = {}
|
if expiration_date > now:
|
||||||
self._state = False
|
self._attributes = alert
|
||||||
|
self._state = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user