mirror of
https://github.com/home-assistant/core.git
synced 2026-11-23 14:17:19 -04:00
Bump zigpy to 0.44.1 and zha-quirks to 0.0.69 (#68921)
* Make unit tests pass * Flip response type check to not rely on it being a list https://github.com/zigpy/zigpy/pull/716#issuecomment-1025236190 * Bump zigpy and quirks versions to ZCLR8 releases * Fix renamed zigpy cluster attributes * Handle the default response for ZLL `get_group_identifiers` * Add more error context to `stage failed` errors * Fix unit test returning lists as ZCL request responses * Always load quirks when testing ZHA * Bump zha-quirks to 0.0.69
This commit is contained in:
@@ -20,8 +20,10 @@ def patch_cluster(cluster):
|
||||
value = cluster.PLUGGED_ATTR_READS.get(attr_id)
|
||||
if value is None:
|
||||
# try converting attr_id to attr_name and lookup the plugs again
|
||||
attr_name = cluster.attributes.get(attr_id)
|
||||
value = attr_name and cluster.PLUGGED_ATTR_READS.get(attr_name[0])
|
||||
attr = cluster.attributes.get(attr_id)
|
||||
|
||||
if attr is not None:
|
||||
value = cluster.PLUGGED_ATTR_READS.get(attr.name)
|
||||
if value is not None:
|
||||
result.append(
|
||||
zcl_f.ReadAttributeRecord(
|
||||
@@ -58,14 +60,23 @@ def patch_cluster(cluster):
|
||||
|
||||
def update_attribute_cache(cluster):
|
||||
"""Update attribute cache based on plugged attributes."""
|
||||
if cluster.PLUGGED_ATTR_READS:
|
||||
attrs = [
|
||||
make_attribute(cluster.attridx.get(attr, attr), value)
|
||||
for attr, value in cluster.PLUGGED_ATTR_READS.items()
|
||||
]
|
||||
hdr = make_zcl_header(zcl_f.Command.Report_Attributes)
|
||||
hdr.frame_control.disable_default_response = True
|
||||
cluster.handle_message(hdr, [attrs])
|
||||
if not cluster.PLUGGED_ATTR_READS:
|
||||
return
|
||||
|
||||
attrs = []
|
||||
for attrid, value in cluster.PLUGGED_ATTR_READS.items():
|
||||
if isinstance(attrid, str):
|
||||
attrid = cluster.attributes_by_name[attrid].id
|
||||
else:
|
||||
attrid = zigpy.types.uint16_t(attrid)
|
||||
attrs.append(make_attribute(attrid, value))
|
||||
|
||||
hdr = make_zcl_header(zcl_f.Command.Report_Attributes)
|
||||
hdr.frame_control.disable_default_response = True
|
||||
msg = zcl_f.GENERAL_COMMANDS[zcl_f.GeneralCommand.Report_Attributes].schema(
|
||||
attribute_reports=attrs
|
||||
)
|
||||
cluster.handle_message(hdr, msg)
|
||||
|
||||
|
||||
def get_zha_gateway(hass):
|
||||
@@ -96,13 +107,23 @@ async def send_attributes_report(hass, cluster: zigpy.zcl.Cluster, attributes: d
|
||||
This is to simulate the normal device communication that happens when a
|
||||
device is paired to the zigbee network.
|
||||
"""
|
||||
attrs = [
|
||||
make_attribute(cluster.attridx.get(attr, attr), value)
|
||||
for attr, value in attributes.items()
|
||||
]
|
||||
hdr = make_zcl_header(zcl_f.Command.Report_Attributes)
|
||||
attrs = []
|
||||
|
||||
for attrid, value in attributes.items():
|
||||
if isinstance(attrid, str):
|
||||
attrid = cluster.attributes_by_name[attrid].id
|
||||
else:
|
||||
attrid = zigpy.types.uint16_t(attrid)
|
||||
|
||||
attrs.append(make_attribute(attrid, value))
|
||||
|
||||
msg = zcl_f.GENERAL_COMMANDS[zcl_f.GeneralCommand.Report_Attributes].schema(
|
||||
attribute_reports=attrs
|
||||
)
|
||||
|
||||
hdr = make_zcl_header(zcl_f.GeneralCommand.Report_Attributes)
|
||||
hdr.frame_control.disable_default_response = True
|
||||
cluster.handle_message(hdr, [attrs])
|
||||
cluster.handle_message(hdr, msg)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,20 @@ FIXTURE_GRP_ID = 0x1001
|
||||
FIXTURE_GRP_NAME = "fixture group"
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def globally_load_quirks():
|
||||
"""Load quirks automatically so that ZHA tests run deterministically in isolation.
|
||||
|
||||
If portions of the ZHA test suite that do not happen to load quirks are run
|
||||
independently, bugs can emerge that will show up only when more of the test suite is
|
||||
run.
|
||||
"""
|
||||
|
||||
import zhaquirks
|
||||
|
||||
zhaquirks.setup()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def zigpy_app_controller():
|
||||
"""Zigpy ApplicationController fixture."""
|
||||
|
||||
@@ -145,7 +145,7 @@ async def test_device_cluster_attributes(zha_client):
|
||||
msg = await zha_client.receive_json()
|
||||
|
||||
attributes = msg["result"]
|
||||
assert len(attributes) == 5
|
||||
assert len(attributes) == 7
|
||||
|
||||
for attribute in attributes:
|
||||
assert attribute[ID] is not None
|
||||
|
||||
@@ -130,7 +130,7 @@ async def poll_control_device(zha_device_restored, zigpy_device_mock):
|
||||
0x0201,
|
||||
1,
|
||||
{
|
||||
"local_temp",
|
||||
"local_temperature",
|
||||
"occupied_cooling_setpoint",
|
||||
"occupied_heating_setpoint",
|
||||
"unoccupied_cooling_setpoint",
|
||||
@@ -586,13 +586,23 @@ async def test_zll_device_groups(
|
||||
cluster = zigpy_zll_device.endpoints[1].lightlink
|
||||
channel = zha_channels.lightlink.LightLink(cluster, channel_pool)
|
||||
|
||||
get_group_identifiers_rsp = zigpy.zcl.clusters.lightlink.LightLink.commands_by_name[
|
||||
"get_group_identifiers_rsp"
|
||||
].schema
|
||||
|
||||
with patch.object(
|
||||
cluster, "command", AsyncMock(return_value=[1, 0, []])
|
||||
cluster,
|
||||
"command",
|
||||
AsyncMock(
|
||||
return_value=get_group_identifiers_rsp(
|
||||
total=0, start_index=0, group_info_records=[]
|
||||
)
|
||||
),
|
||||
) as cmd_mock:
|
||||
await channel.async_configure()
|
||||
assert cmd_mock.await_count == 1
|
||||
assert (
|
||||
cluster.server_commands[cmd_mock.await_args[0][0]][0]
|
||||
cluster.server_commands[cmd_mock.await_args[0][0]].name
|
||||
== "get_group_identifiers"
|
||||
)
|
||||
assert cluster.bind.call_count == 0
|
||||
@@ -603,12 +613,18 @@ async def test_zll_device_groups(
|
||||
group_1 = zigpy.zcl.clusters.lightlink.GroupInfoRecord(0xABCD, 0x00)
|
||||
group_2 = zigpy.zcl.clusters.lightlink.GroupInfoRecord(0xAABB, 0x00)
|
||||
with patch.object(
|
||||
cluster, "command", AsyncMock(return_value=[1, 0, [group_1, group_2]])
|
||||
cluster,
|
||||
"command",
|
||||
AsyncMock(
|
||||
return_value=get_group_identifiers_rsp(
|
||||
total=2, start_index=0, group_info_records=[group_1, group_2]
|
||||
)
|
||||
),
|
||||
) as cmd_mock:
|
||||
await channel.async_configure()
|
||||
assert cmd_mock.await_count == 1
|
||||
assert (
|
||||
cluster.server_commands[cmd_mock.await_args[0][0]][0]
|
||||
cluster.server_commands[cmd_mock.await_args[0][0]].name
|
||||
== "get_group_identifiers"
|
||||
)
|
||||
assert cluster.bind.call_count == 0
|
||||
|
||||
@@ -6,6 +6,7 @@ import pytest
|
||||
import zhaquirks.sinope.thermostat
|
||||
import zhaquirks.tuya.ts0601_trv
|
||||
import zigpy.profiles
|
||||
import zigpy.types
|
||||
import zigpy.zcl.clusters
|
||||
from zigpy.zcl.clusters.hvac import Thermostat
|
||||
import zigpy.zcl.foundation as zcl_f
|
||||
@@ -162,8 +163,8 @@ ZCL_ATTR_PLUG = {
|
||||
"abs_max_heat_setpoint_limit": 3000,
|
||||
"abs_min_cool_setpoint_limit": 2000,
|
||||
"abs_max_cool_setpoint_limit": 4000,
|
||||
"ctrl_seqe_of_oper": Thermostat.ControlSequenceOfOperation.Cooling_and_Heating,
|
||||
"local_temp": None,
|
||||
"ctrl_sequence_of_oper": Thermostat.ControlSequenceOfOperation.Cooling_and_Heating,
|
||||
"local_temperature": None,
|
||||
"max_cool_setpoint_limit": 3900,
|
||||
"max_heat_setpoint_limit": 2900,
|
||||
"min_cool_setpoint_limit": 2100,
|
||||
@@ -268,7 +269,7 @@ def test_sequence_mappings():
|
||||
assert Thermostat.SystemMode(HVAC_MODE_2_SYSTEM[hvac_mode]) is not None
|
||||
|
||||
|
||||
async def test_climate_local_temp(hass, device_climate):
|
||||
async def test_climate_local_temperature(hass, device_climate):
|
||||
"""Test local temperature."""
|
||||
|
||||
thrm_cluster = device_climate.device.endpoints[1].thermostat
|
||||
@@ -517,7 +518,7 @@ async def test_hvac_modes(hass, device_climate_mock, seq_of_op, modes):
|
||||
"""Test HVAC modes from sequence of operations."""
|
||||
|
||||
device_climate = await device_climate_mock(
|
||||
CLIMATE, {"ctrl_seqe_of_oper": seq_of_op}
|
||||
CLIMATE, {"ctrl_sequence_of_oper": seq_of_op}
|
||||
)
|
||||
entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass)
|
||||
state = hass.states.get(entity_id)
|
||||
@@ -1119,7 +1120,7 @@ async def test_occupancy_reset(hass, device_climate_sinope):
|
||||
assert state.attributes[ATTR_PRESET_MODE] == PRESET_AWAY
|
||||
|
||||
await send_attributes_report(
|
||||
hass, thrm_cluster, {"occupied_heating_setpoint": 1950}
|
||||
hass, thrm_cluster, {"occupied_heating_setpoint": zigpy.types.uint16_t(1950)}
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE
|
||||
|
||||
@@ -146,7 +146,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device):
|
||||
assert cluster.request.call_count == 1
|
||||
assert cluster.request.call_args[0][0] is False
|
||||
assert cluster.request.call_args[0][1] == 0x01
|
||||
assert cluster.request.call_args[0][2] == ()
|
||||
assert cluster.request.call_args[0][2].command.name == "down_close"
|
||||
assert cluster.request.call_args[1]["expect_reply"] is True
|
||||
|
||||
# open from UI
|
||||
@@ -159,7 +159,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device):
|
||||
assert cluster.request.call_count == 1
|
||||
assert cluster.request.call_args[0][0] is False
|
||||
assert cluster.request.call_args[0][1] == 0x00
|
||||
assert cluster.request.call_args[0][2] == ()
|
||||
assert cluster.request.call_args[0][2].command.name == "up_open"
|
||||
assert cluster.request.call_args[1]["expect_reply"] is True
|
||||
|
||||
# set position UI
|
||||
@@ -175,7 +175,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device):
|
||||
assert cluster.request.call_count == 1
|
||||
assert cluster.request.call_args[0][0] is False
|
||||
assert cluster.request.call_args[0][1] == 0x05
|
||||
assert cluster.request.call_args[0][2] == (zigpy.types.uint8_t,)
|
||||
assert cluster.request.call_args[0][2].command.name == "go_to_lift_percentage"
|
||||
assert cluster.request.call_args[0][3] == 53
|
||||
assert cluster.request.call_args[1]["expect_reply"] is True
|
||||
|
||||
@@ -189,7 +189,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device):
|
||||
assert cluster.request.call_count == 1
|
||||
assert cluster.request.call_args[0][0] is False
|
||||
assert cluster.request.call_args[0][1] == 0x02
|
||||
assert cluster.request.call_args[0][2] == ()
|
||||
assert cluster.request.call_args[0][2].command.name == "stop"
|
||||
assert cluster.request.call_args[1]["expect_reply"] is True
|
||||
|
||||
# test rejoin
|
||||
|
||||
@@ -120,7 +120,7 @@ async def test_devices(
|
||||
assert cluster_identify.request.call_args == mock.call(
|
||||
False,
|
||||
64,
|
||||
(zigpy.types.uint8_t, zigpy.types.uint8_t),
|
||||
cluster_identify.commands_by_name["trigger_effect"].schema,
|
||||
2,
|
||||
0,
|
||||
expect_reply=True,
|
||||
|
||||
@@ -4,7 +4,6 @@ from unittest.mock import AsyncMock, call, patch, sentinel
|
||||
|
||||
import pytest
|
||||
import zigpy.profiles.zha as zha
|
||||
import zigpy.types
|
||||
import zigpy.zcl.clusters.general as general
|
||||
import zigpy.zcl.clusters.lighting as lighting
|
||||
import zigpy.zcl.foundation as zcl_f
|
||||
@@ -336,7 +335,13 @@ async def async_test_on_off_from_hass(hass, cluster, entity_id):
|
||||
assert cluster.request.call_count == 1
|
||||
assert cluster.request.await_count == 1
|
||||
assert cluster.request.call_args == call(
|
||||
False, ON, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
||||
False,
|
||||
ON,
|
||||
cluster.commands_by_name["on"].schema,
|
||||
expect_reply=True,
|
||||
manufacturer=None,
|
||||
tries=1,
|
||||
tsn=None,
|
||||
)
|
||||
|
||||
await async_test_off_from_hass(hass, cluster, entity_id)
|
||||
@@ -353,7 +358,13 @@ async def async_test_off_from_hass(hass, cluster, entity_id):
|
||||
assert cluster.request.call_count == 1
|
||||
assert cluster.request.await_count == 1
|
||||
assert cluster.request.call_args == call(
|
||||
False, OFF, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
||||
False,
|
||||
OFF,
|
||||
cluster.commands_by_name["off"].schema,
|
||||
expect_reply=True,
|
||||
manufacturer=None,
|
||||
tries=1,
|
||||
tsn=None,
|
||||
)
|
||||
|
||||
|
||||
@@ -373,7 +384,13 @@ async def async_test_level_on_off_from_hass(
|
||||
assert level_cluster.request.call_count == 0
|
||||
assert level_cluster.request.await_count == 0
|
||||
assert on_off_cluster.request.call_args == call(
|
||||
False, ON, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
||||
False,
|
||||
ON,
|
||||
on_off_cluster.commands_by_name["on"].schema,
|
||||
expect_reply=True,
|
||||
manufacturer=None,
|
||||
tries=1,
|
||||
tsn=None,
|
||||
)
|
||||
on_off_cluster.request.reset_mock()
|
||||
level_cluster.request.reset_mock()
|
||||
@@ -389,12 +406,18 @@ async def async_test_level_on_off_from_hass(
|
||||
assert level_cluster.request.call_count == 1
|
||||
assert level_cluster.request.await_count == 1
|
||||
assert on_off_cluster.request.call_args == call(
|
||||
False, ON, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
||||
False,
|
||||
ON,
|
||||
on_off_cluster.commands_by_name["on"].schema,
|
||||
expect_reply=True,
|
||||
manufacturer=None,
|
||||
tries=1,
|
||||
tsn=None,
|
||||
)
|
||||
assert level_cluster.request.call_args == call(
|
||||
False,
|
||||
4,
|
||||
(zigpy.types.uint8_t, zigpy.types.uint16_t),
|
||||
level_cluster.commands_by_name["move_to_level_with_on_off"].schema,
|
||||
254,
|
||||
100.0,
|
||||
expect_reply=True,
|
||||
@@ -419,7 +442,7 @@ async def async_test_level_on_off_from_hass(
|
||||
assert level_cluster.request.call_args == call(
|
||||
False,
|
||||
4,
|
||||
(zigpy.types.uint8_t, zigpy.types.uint16_t),
|
||||
level_cluster.commands_by_name["move_to_level_with_on_off"].schema,
|
||||
10,
|
||||
1,
|
||||
expect_reply=True,
|
||||
@@ -462,7 +485,7 @@ async def async_test_flash_from_hass(hass, cluster, entity_id, flash):
|
||||
assert cluster.request.call_args == call(
|
||||
False,
|
||||
64,
|
||||
(zigpy.types.uint8_t, zigpy.types.uint8_t),
|
||||
cluster.commands_by_name["trigger_effect"].schema,
|
||||
FLASH_EFFECTS[flash],
|
||||
0,
|
||||
expect_reply=True,
|
||||
|
||||
@@ -307,7 +307,7 @@ async def async_test_device_temperature(hass, cluster, entity_id):
|
||||
"metering_device_type": 0x00,
|
||||
"multiplier": 1,
|
||||
"status": 0x00,
|
||||
"summa_formatting": 0b1_0111_010,
|
||||
"summation_formatting": 0b1_0111_010,
|
||||
"unit_of_measure": 0x01,
|
||||
},
|
||||
{"instaneneous_demand"},
|
||||
@@ -814,7 +814,7 @@ async def test_se_summation_uom(
|
||||
"metering_device_type": 0x00,
|
||||
"multiplier": 1,
|
||||
"status": 0x00,
|
||||
"summa_formatting": 0b1_0111_010,
|
||||
"summation_formatting": 0b1_0111_010,
|
||||
"unit_of_measure": raw_uom,
|
||||
}
|
||||
await zha_device_joined(zigpy_device)
|
||||
|
||||
@@ -141,7 +141,13 @@ async def test_switch(hass, zha_device_joined_restored, zigpy_device):
|
||||
)
|
||||
assert len(cluster.request.mock_calls) == 1
|
||||
assert cluster.request.call_args == call(
|
||||
False, ON, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
||||
False,
|
||||
ON,
|
||||
cluster.commands_by_name["on"].schema,
|
||||
expect_reply=True,
|
||||
manufacturer=None,
|
||||
tries=1,
|
||||
tsn=None,
|
||||
)
|
||||
|
||||
# turn off from HA
|
||||
@@ -155,7 +161,13 @@ async def test_switch(hass, zha_device_joined_restored, zigpy_device):
|
||||
)
|
||||
assert len(cluster.request.mock_calls) == 1
|
||||
assert cluster.request.call_args == call(
|
||||
False, OFF, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
||||
False,
|
||||
OFF,
|
||||
cluster.commands_by_name["off"].schema,
|
||||
expect_reply=True,
|
||||
manufacturer=None,
|
||||
tries=1,
|
||||
tsn=None,
|
||||
)
|
||||
|
||||
# test joining a new switch to the network and HA
|
||||
@@ -224,7 +236,13 @@ async def test_zha_group_switch_entity(
|
||||
)
|
||||
assert len(group_cluster_on_off.request.mock_calls) == 1
|
||||
assert group_cluster_on_off.request.call_args == call(
|
||||
False, ON, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
||||
False,
|
||||
ON,
|
||||
group_cluster_on_off.commands_by_name["on"].schema,
|
||||
expect_reply=True,
|
||||
manufacturer=None,
|
||||
tries=1,
|
||||
tsn=None,
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
|
||||
@@ -239,7 +257,13 @@ async def test_zha_group_switch_entity(
|
||||
)
|
||||
assert len(group_cluster_on_off.request.mock_calls) == 1
|
||||
assert group_cluster_on_off.request.call_args == call(
|
||||
False, OFF, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
||||
False,
|
||||
OFF,
|
||||
group_cluster_on_off.commands_by_name["off"].schema,
|
||||
expect_reply=True,
|
||||
manufacturer=None,
|
||||
tries=1,
|
||||
tsn=None,
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
|
||||
|
||||
Reference in New Issue
Block a user