mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Guard for unparsable date time (#55108)
This commit is contained in:
parent
c8f584f4ef
commit
9fc96818df
@ -60,10 +60,17 @@ class HueEvent(GenericHueDevice):
|
|||||||
self.sensor.last_event is not None
|
self.sensor.last_event is not None
|
||||||
and self.sensor.last_event["type"] != EVENT_BUTTON
|
and self.sensor.last_event["type"] != EVENT_BUTTON
|
||||||
)
|
)
|
||||||
or
|
):
|
||||||
# Filter out old states. Can happen when events fire while refreshing
|
return
|
||||||
dt_util.parse_datetime(self.sensor.state["lastupdated"])
|
|
||||||
<= dt_util.parse_datetime(self._last_state["lastupdated"])
|
# Filter out old states. Can happen when events fire while refreshing
|
||||||
|
now_updated = dt_util.parse_datetime(self.sensor.state["lastupdated"])
|
||||||
|
last_updated = dt_util.parse_datetime(self._last_state["lastupdated"])
|
||||||
|
|
||||||
|
if (
|
||||||
|
now_updated is not None
|
||||||
|
and last_updated is not None
|
||||||
|
and now_updated <= last_updated
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ async def test_get_triggers(hass, mock_bridge, device_reg):
|
|||||||
"type": t_type,
|
"type": t_type,
|
||||||
"subtype": t_subtype,
|
"subtype": t_subtype,
|
||||||
}
|
}
|
||||||
for t_type, t_subtype in device_trigger.HUE_TAP_REMOTE.keys()
|
for t_type, t_subtype in device_trigger.HUE_TAP_REMOTE
|
||||||
]
|
]
|
||||||
assert_lists_same(triggers, expected_triggers)
|
assert_lists_same(triggers, expected_triggers)
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ async def test_get_triggers(hass, mock_bridge, device_reg):
|
|||||||
"type": t_type,
|
"type": t_type,
|
||||||
"subtype": t_subtype,
|
"subtype": t_subtype,
|
||||||
}
|
}
|
||||||
for t_type, t_subtype in device_trigger.HUE_DIMMER_REMOTE.keys()
|
for t_type, t_subtype in device_trigger.HUE_DIMMER_REMOTE
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
assert_lists_same(triggers, expected_triggers)
|
assert_lists_same(triggers, expected_triggers)
|
||||||
@ -140,6 +140,7 @@ async def test_if_fires_on_state_change(hass, mock_bridge, device_reg, calls):
|
|||||||
|
|
||||||
# Fake that the remote is being pressed.
|
# Fake that the remote is being pressed.
|
||||||
new_sensor_response = dict(REMOTES_RESPONSE)
|
new_sensor_response = dict(REMOTES_RESPONSE)
|
||||||
|
new_sensor_response["7"] = dict(new_sensor_response["7"])
|
||||||
new_sensor_response["7"]["state"] = {
|
new_sensor_response["7"]["state"] = {
|
||||||
"buttonevent": 18,
|
"buttonevent": 18,
|
||||||
"lastupdated": "2019-12-28T22:58:02",
|
"lastupdated": "2019-12-28T22:58:02",
|
||||||
@ -156,7 +157,7 @@ async def test_if_fires_on_state_change(hass, mock_bridge, device_reg, calls):
|
|||||||
assert calls[0].data["some"] == "B4 - 18"
|
assert calls[0].data["some"] == "B4 - 18"
|
||||||
|
|
||||||
# Fake another button press.
|
# Fake another button press.
|
||||||
new_sensor_response = dict(REMOTES_RESPONSE)
|
new_sensor_response["7"] = dict(new_sensor_response["7"])
|
||||||
new_sensor_response["7"]["state"] = {
|
new_sensor_response["7"]["state"] = {
|
||||||
"buttonevent": 34,
|
"buttonevent": 34,
|
||||||
"lastupdated": "2019-12-28T22:58:05",
|
"lastupdated": "2019-12-28T22:58:05",
|
||||||
|
@ -450,6 +450,7 @@ async def test_hue_events(hass, mock_bridge):
|
|||||||
mock_bridge.api.sensors["8"].last_event = {"type": "button"}
|
mock_bridge.api.sensors["8"].last_event = {"type": "button"}
|
||||||
|
|
||||||
new_sensor_response = dict(SENSOR_RESPONSE)
|
new_sensor_response = dict(SENSOR_RESPONSE)
|
||||||
|
new_sensor_response["7"] = dict(new_sensor_response["7"])
|
||||||
new_sensor_response["7"]["state"] = {
|
new_sensor_response["7"]["state"] = {
|
||||||
"buttonevent": 18,
|
"buttonevent": 18,
|
||||||
"lastupdated": "2019-12-28T22:58:03",
|
"lastupdated": "2019-12-28T22:58:03",
|
||||||
@ -473,6 +474,7 @@ async def test_hue_events(hass, mock_bridge):
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_sensor_response = dict(new_sensor_response)
|
new_sensor_response = dict(new_sensor_response)
|
||||||
|
new_sensor_response["8"] = dict(new_sensor_response["8"])
|
||||||
new_sensor_response["8"]["state"] = {
|
new_sensor_response["8"]["state"] = {
|
||||||
"buttonevent": 3002,
|
"buttonevent": 3002,
|
||||||
"lastupdated": "2019-12-28T22:58:03",
|
"lastupdated": "2019-12-28T22:58:03",
|
||||||
@ -497,6 +499,7 @@ async def test_hue_events(hass, mock_bridge):
|
|||||||
|
|
||||||
# Fire old event, it should be ignored
|
# Fire old event, it should be ignored
|
||||||
new_sensor_response = dict(new_sensor_response)
|
new_sensor_response = dict(new_sensor_response)
|
||||||
|
new_sensor_response["8"] = dict(new_sensor_response["8"])
|
||||||
new_sensor_response["8"]["state"] = {
|
new_sensor_response["8"]["state"] = {
|
||||||
"buttonevent": 18,
|
"buttonevent": 18,
|
||||||
"lastupdated": "2019-12-28T22:58:02",
|
"lastupdated": "2019-12-28T22:58:02",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user