Fix Meteoalarm expired alerts (#56255)
parent
28b4b5407b
commit
1609d069bb
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue