mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Fix flaky ZHA tests (#70956)
This commit is contained in:
parent
f3a18bc8f2
commit
e41490f8ba
@ -1,5 +1,6 @@
|
|||||||
"""Test ZHA Gateway."""
|
"""Test ZHA Gateway."""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import math
|
||||||
import time
|
import time
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@ -207,14 +208,14 @@ async def test_updating_device_store(hass, zigpy_dev_basic, zha_dev_basic):
|
|||||||
|
|
||||||
assert zha_dev_basic.last_seen is not None
|
assert zha_dev_basic.last_seen is not None
|
||||||
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
||||||
assert entry.last_seen == zha_dev_basic.last_seen
|
assert math.isclose(entry.last_seen, zha_dev_basic.last_seen, rel_tol=1e-06)
|
||||||
|
|
||||||
assert zha_dev_basic.last_seen is not None
|
assert zha_dev_basic.last_seen is not None
|
||||||
last_seen = zha_dev_basic.last_seen
|
last_seen = zha_dev_basic.last_seen
|
||||||
|
|
||||||
# test that we can't set None as last seen any more
|
# test that we can't set None as last seen any more
|
||||||
zha_dev_basic.async_update_last_seen(None)
|
zha_dev_basic.async_update_last_seen(None)
|
||||||
assert last_seen == zha_dev_basic.last_seen
|
assert math.isclose(last_seen, zha_dev_basic.last_seen, rel_tol=1e-06)
|
||||||
|
|
||||||
# test that we won't put None in storage
|
# test that we won't put None in storage
|
||||||
zigpy_dev_basic.last_seen = None
|
zigpy_dev_basic.last_seen = None
|
||||||
@ -222,18 +223,18 @@ async def test_updating_device_store(hass, zigpy_dev_basic, zha_dev_basic):
|
|||||||
await zha_gateway.async_update_device_storage()
|
await zha_gateway.async_update_device_storage()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
||||||
assert entry.last_seen == last_seen
|
assert math.isclose(entry.last_seen, last_seen, rel_tol=1e-06)
|
||||||
|
|
||||||
# test that we can still set a good last_seen
|
# test that we can still set a good last_seen
|
||||||
last_seen = time.time()
|
last_seen = time.time()
|
||||||
zha_dev_basic.async_update_last_seen(last_seen)
|
zha_dev_basic.async_update_last_seen(last_seen)
|
||||||
assert last_seen == zha_dev_basic.last_seen
|
assert math.isclose(last_seen, zha_dev_basic.last_seen, rel_tol=1e-06)
|
||||||
|
|
||||||
# test that we still put good values in storage
|
# test that we still put good values in storage
|
||||||
await zha_gateway.async_update_device_storage()
|
await zha_gateway.async_update_device_storage()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
||||||
assert entry.last_seen == last_seen
|
assert math.isclose(entry.last_seen, last_seen, rel_tol=1e-06)
|
||||||
|
|
||||||
|
|
||||||
async def test_cleaning_up_storage(hass, zigpy_dev_basic, zha_dev_basic, hass_storage):
|
async def test_cleaning_up_storage(hass, zigpy_dev_basic, zha_dev_basic, hass_storage):
|
||||||
|
@ -193,7 +193,11 @@ async def test_on_off_select(hass, light, zha_device_joined_restored):
|
|||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_UNKNOWN
|
if zha_device_joined_restored.name == "zha_device_joined":
|
||||||
|
assert state.state == general.OnOff.StartUpOnOff.On.name
|
||||||
|
else:
|
||||||
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
assert state.attributes["options"] == ["Off", "On", "Toggle", "PreviousValue"]
|
assert state.attributes["options"] == ["Off", "On", "Toggle", "PreviousValue"]
|
||||||
|
|
||||||
entity_entry = entity_registry.async_get(entity_id)
|
entity_entry = entity_registry.async_get(entity_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user