mirror of
https://github.com/elisspace/core.git
synced 2026-09-30 14:29:54 +00:00
Remove unnecessary update_before_add from ZHA (#71010)
* Additional streamlining for ZHA entity init * fix tests
This commit is contained in:
committed by
Paulus Schoutsen
parent
dea9ff4f18
commit
53181b409f
@@ -104,17 +104,14 @@ def zigpy_keen_vent(zigpy_device_mock):
|
||||
)
|
||||
|
||||
|
||||
@patch(
|
||||
"homeassistant.components.zha.core.channels.closures.WindowCovering.async_initialize"
|
||||
)
|
||||
async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device):
|
||||
async def test_cover(hass, zha_device_joined_restored, zigpy_cover_device):
|
||||
"""Test zha cover platform."""
|
||||
|
||||
# load up cover domain
|
||||
cluster = zigpy_cover_device.endpoints.get(1).window_covering
|
||||
cluster.PLUGGED_ATTR_READS = {"current_position_lift_percentage": 100}
|
||||
zha_device = await zha_device_joined_restored(zigpy_cover_device)
|
||||
assert cluster.read_attributes.call_count == 2
|
||||
assert cluster.read_attributes.call_count == 1
|
||||
assert "current_position_lift_percentage" in cluster.read_attributes.call_args[0][0]
|
||||
|
||||
entity_id = await find_entity_id(Platform.COVER, zha_device, hass)
|
||||
@@ -193,6 +190,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device):
|
||||
assert cluster.request.call_args[1]["expect_reply"] is True
|
||||
|
||||
# test rejoin
|
||||
cluster.PLUGGED_ATTR_READS = {"current_position_lift_percentage": 0}
|
||||
await async_test_rejoin(hass, zigpy_cover_device, [cluster], (1,))
|
||||
assert hass.states.get(entity_id).state == STATE_OPEN
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ async def test_device_tracker(hass, zha_device_joined_restored, zigpy_device_dt)
|
||||
entity_id = await find_entity_id(Platform.DEVICE_TRACKER, zha_device, hass)
|
||||
assert entity_id is not None
|
||||
|
||||
assert hass.states.get(entity_id).state == STATE_HOME
|
||||
assert hass.states.get(entity_id).state == STATE_NOT_HOME
|
||||
await async_enable_traffic(hass, [zha_device], enabled=False)
|
||||
# test that the device tracker was created and that it is unavailable
|
||||
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Test ZHA select entities."""
|
||||
|
||||
from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
from zigpy.const import SIG_EP_PROFILE
|
||||
import zigpy.profiles.zha as zha
|
||||
@@ -50,6 +52,7 @@ async def light(hass, zigpy_device_mock):
|
||||
SIG_EP_OUTPUT: [general.Ota.cluster_id],
|
||||
}
|
||||
},
|
||||
node_descriptor=b"\x02@\x84_\x11\x7fd\x00\x00,d\x00\x00",
|
||||
)
|
||||
|
||||
return zigpy_device
|
||||
@@ -173,15 +176,15 @@ async def test_select_restore_state(
|
||||
assert state.state == security.IasWd.Warning.WarningMode.Burglar.name
|
||||
|
||||
|
||||
async def test_on_off_select(hass, light, zha_device_joined_restored):
|
||||
"""Test zha on off select."""
|
||||
async def test_on_off_select_new_join(hass, light, zha_device_joined):
|
||||
"""Test zha on off select - new join."""
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
on_off_cluster = light.endpoints[1].on_off
|
||||
on_off_cluster.PLUGGED_ATTR_READS = {
|
||||
"start_up_on_off": general.OnOff.StartUpOnOff.On
|
||||
}
|
||||
zha_device = await zha_device_joined_restored(light)
|
||||
zha_device = await zha_device_joined(light)
|
||||
select_name = general.OnOff.StartUpOnOff.__name__
|
||||
entity_id = await find_entity_id(
|
||||
Platform.SELECT,
|
||||
@@ -191,12 +194,19 @@ async def test_on_off_select(hass, light, zha_device_joined_restored):
|
||||
)
|
||||
assert entity_id is not None
|
||||
|
||||
assert on_off_cluster.read_attributes.call_count == 2
|
||||
assert (
|
||||
call(["start_up_on_off"], allow_cache=True, only_cache=False, manufacturer=None)
|
||||
in on_off_cluster.read_attributes.call_args_list
|
||||
)
|
||||
assert (
|
||||
call(["on_off"], allow_cache=False, only_cache=False, manufacturer=None)
|
||||
in on_off_cluster.read_attributes.call_args_list
|
||||
)
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
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.state == general.OnOff.StartUpOnOff.On.name
|
||||
|
||||
assert state.attributes["options"] == ["Off", "On", "Toggle", "PreviousValue"]
|
||||
|
||||
@@ -225,6 +235,58 @@ async def test_on_off_select(hass, light, zha_device_joined_restored):
|
||||
assert state.state == general.OnOff.StartUpOnOff.Off.name
|
||||
|
||||
|
||||
async def test_on_off_select_restored(hass, light, zha_device_restored):
|
||||
"""Test zha on off select - restored."""
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
on_off_cluster = light.endpoints[1].on_off
|
||||
on_off_cluster.PLUGGED_ATTR_READS = {
|
||||
"start_up_on_off": general.OnOff.StartUpOnOff.On
|
||||
}
|
||||
zha_device = await zha_device_restored(light)
|
||||
|
||||
assert zha_device.is_mains_powered
|
||||
|
||||
assert on_off_cluster.read_attributes.call_count == 4
|
||||
# first 2 calls hit cache only
|
||||
assert (
|
||||
call(["start_up_on_off"], allow_cache=True, only_cache=True, manufacturer=None)
|
||||
in on_off_cluster.read_attributes.call_args_list
|
||||
)
|
||||
assert (
|
||||
call(["on_off"], allow_cache=True, only_cache=True, manufacturer=None)
|
||||
in on_off_cluster.read_attributes.call_args_list
|
||||
)
|
||||
|
||||
# 2nd set of calls can actually read from the device
|
||||
assert (
|
||||
call(["start_up_on_off"], allow_cache=True, only_cache=False, manufacturer=None)
|
||||
in on_off_cluster.read_attributes.call_args_list
|
||||
)
|
||||
assert (
|
||||
call(["on_off"], allow_cache=False, only_cache=False, manufacturer=None)
|
||||
in on_off_cluster.read_attributes.call_args_list
|
||||
)
|
||||
|
||||
select_name = general.OnOff.StartUpOnOff.__name__
|
||||
entity_id = await find_entity_id(
|
||||
Platform.SELECT,
|
||||
zha_device,
|
||||
hass,
|
||||
qualifier=select_name.lower(),
|
||||
)
|
||||
assert entity_id is not None
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == general.OnOff.StartUpOnOff.On.name
|
||||
assert state.attributes["options"] == ["Off", "On", "Toggle", "PreviousValue"]
|
||||
|
||||
entity_entry = entity_registry.async_get(entity_id)
|
||||
assert entity_entry
|
||||
assert entity_entry.entity_category == ENTITY_CATEGORY_CONFIG
|
||||
|
||||
|
||||
async def test_on_off_select_unsupported(hass, light, zha_device_joined_restored):
|
||||
"""Test zha on off select unsupported."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user