Miscellaneous ZHA code cleanup (#33395)
* cleanup state change listener * update group id handling and unique id * update test * add guards for last_seen updates
This commit is contained in:
1 parent
ffafcf27a8
commit
188ca630de
7 files changed
+62
-27
No files matched your search
@@ -159,9 +159,7 @@ async def find_entity_id(domain, zha_device, hass):
|
||||
|
||||
def async_find_group_entity_id(hass, domain, group):
|
||||
"""Find the group entity id under test."""
|
||||
entity_id = (
|
||||
f"{domain}.{group.name.lower().replace(' ','_')}_group_0x{group.group_id:04x}"
|
||||
)
|
||||
entity_id = f"{domain}.{group.name.lower().replace(' ','_')}_zha_group_0x{group.group_id:04x}"
|
||||
|
||||
entity_ids = hass.states.async_entity_ids(domain)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Test ZHA Gateway."""
|
||||
import logging
|
||||
import time
|
||||
|
||||
import pytest
|
||||
import zigpy.profiles.zha as zha
|
||||
@@ -167,3 +168,40 @@ async def test_gateway_group_methods(hass, device_light_1, device_light_2, coord
|
||||
|
||||
# the group entity should not have been cleaned up
|
||||
assert entity_id not in hass.states.async_entity_ids(LIGHT_DOMAIN)
|
||||
|
||||
|
||||
async def test_updating_device_store(hass, zigpy_dev_basic, zha_dev_basic):
|
||||
"""Test saving data after a delay."""
|
||||
zha_gateway = get_zha_gateway(hass)
|
||||
assert zha_gateway is not None
|
||||
await async_enable_traffic(hass, [zha_dev_basic])
|
||||
|
||||
assert zha_dev_basic.last_seen is not None
|
||||
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
||||
assert entry.last_seen == zha_dev_basic.last_seen
|
||||
|
||||
assert zha_dev_basic.last_seen is not None
|
||||
last_seen = zha_dev_basic.last_seen
|
||||
|
||||
# test that we can't set None as last seen any more
|
||||
zha_dev_basic.async_update_last_seen(None)
|
||||
assert last_seen == zha_dev_basic.last_seen
|
||||
|
||||
# test that we won't put None in storage
|
||||
zigpy_dev_basic.last_seen = None
|
||||
assert zha_dev_basic.last_seen is None
|
||||
await zha_gateway.async_update_device_storage()
|
||||
await hass.async_block_till_done()
|
||||
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
||||
assert entry.last_seen == last_seen
|
||||
|
||||
# test that we can still set a good last_seen
|
||||
last_seen = time.time()
|
||||
zha_dev_basic.async_update_last_seen(last_seen)
|
||||
assert last_seen == zha_dev_basic.last_seen
|
||||
|
||||
# test that we still put good values in storage
|
||||
await zha_gateway.async_update_device_storage()
|
||||
await hass.async_block_till_done()
|
||||
entry = zha_gateway.zha_storage.async_get_or_create_device(zha_dev_basic)
|
||||
assert entry.last_seen == last_seen
|
||||
Reference in new issue
Block a user