Fix Meteoalarm expired alerts (#56255)

pull/56298/head
Chris Browet 2021-09-16 16:07:53 +02:00 committed by GitHub
parent 28b4b5407b
commit 1609d069bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -12,6 +12,7 @@ from homeassistant.components.binary_sensor import (
)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util
_LOGGER = logging.getLogger(__name__)
@ -85,10 +86,14 @@ class MeteoAlertBinarySensor(BinarySensorEntity):
def update(self):
"""Update device state."""
self._attributes = {}
self._state = False
alert = self._api.get_alert()
if alert:
self._attributes = alert
self._state = True
else:
self._attributes = {}
self._state = False
expiration_date = dt_util.parse_datetime(alert["expires"])
now = dt_util.utcnow()
if expiration_date > now:
self._attributes = alert
self._state = True