Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated dev.handle_message usage in tests #3746

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions tests/test_inovelli_blue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from unittest import mock
from unittest.mock import MagicMock

import zigpy.types as t

import zhaquirks
from zhaquirks.inovelli.VZM31SN import InovelliVZM31SNv11

Expand All @@ -25,7 +27,15 @@ class Listener:
cluster_listener
)

device.handle_message(260, cluster_id, endpoint_id, endpoint_id, data)
device.packet_received(
t.ZigbeePacket(
profile_id=260,
cluster_id=cluster_id,
src_ep=endpoint_id,
dst_ep=endpoint_id,
data=t.SerializableBytes(data),
)
)

assert cluster_listener.zha_send_event.call_count == 1
assert cluster_listener.zha_send_event.call_args == mock.call(
Expand All @@ -35,8 +45,14 @@ class Listener:
cluster_listener.zha_send_event.reset_mock()

led_effect_complete_data = b"\x15/\x12\x0c$\x10"
device.handle_message(
260, cluster_id, endpoint_id, endpoint_id, led_effect_complete_data
device.packet_received(
t.ZigbeePacket(
profile_id=260,
cluster_id=cluster_id,
src_ep=endpoint_id,
dst_ep=endpoint_id,
data=t.SerializableBytes(led_effect_complete_data),
)
)

assert cluster_listener.zha_send_event.call_count == 1
Expand Down
31 changes: 28 additions & 3 deletions tests/test_konke.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest import mock

import pytest
import zigpy.types as t

from tests.common import ZCL_IAS_MOTION_COMMAND, ClusterListener
import zhaquirks
Expand Down Expand Up @@ -83,7 +84,15 @@ async def test_konke_button(zigpy_device_from_quirk, quirk):

# single press
message = b"\x08W\n\x00\x00\x10\x80"
device.handle_message(260, cluster.cluster_id, 1, 1, message)
device.packet_received(
t.ZigbeePacket(
profile_id=260,
cluster_id=cluster.cluster_id,
src_ep=1,
dst_ep=1,
data=t.SerializableBytes(message),
)
)
assert listener.zha_send_event.call_count == 1
assert listener.zha_send_event.call_args_list[0][0][0] == COMMAND_SINGLE
assert listener.zha_send_event.call_args_list[0][0][1][PRESS_TYPE] == COMMAND_SINGLE
Expand All @@ -92,7 +101,15 @@ async def test_konke_button(zigpy_device_from_quirk, quirk):
# double press
listener.reset_mock()
message = b"\x08X\n\x00\x00\x10\x81"
device.handle_message(260, cluster.cluster_id, 1, 1, message)
device.packet_received(
t.ZigbeePacket(
profile_id=260,
cluster_id=cluster.cluster_id,
src_ep=1,
dst_ep=1,
data=t.SerializableBytes(message),
)
)
assert listener.zha_send_event.call_count == 1
assert listener.zha_send_event.call_args_list[0][0][0] == COMMAND_DOUBLE
assert listener.zha_send_event.call_args_list[0][0][1][PRESS_TYPE] == COMMAND_DOUBLE
Expand All @@ -101,7 +118,15 @@ async def test_konke_button(zigpy_device_from_quirk, quirk):
# long press
listener.reset_mock()
message = b"\x08Y\n\x00\x00\x10\x82"
device.handle_message(260, cluster.cluster_id, 1, 1, message)
device.packet_received(
t.ZigbeePacket(
profile_id=260,
cluster_id=cluster.cluster_id,
src_ep=1,
dst_ep=1,
data=t.SerializableBytes(message),
)
)
assert listener.zha_send_event.call_count == 1
assert listener.zha_send_event.call_args_list[0][0][0] == COMMAND_HOLD
assert listener.zha_send_event.call_args_list[0][0][1][PRESS_TYPE] == COMMAND_HOLD
Expand Down
11 changes: 10 additions & 1 deletion tests/test_linxura.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import mock

import pytest
import zigpy.types as t
from zigpy.zcl.clusters.security import IasZone

import zhaquirks
Expand Down Expand Up @@ -105,7 +106,15 @@ async def test_button_triggers(zigpy_device_from_quirk, message, button, press_t
listener = mock.MagicMock()
cluster.add_listener(listener)

device.handle_message(260, cluster.cluster_id, 1, 1, message)
device.packet_received(
t.ZigbeePacket(
profile_id=260,
cluster_id=cluster.cluster_id,
src_ep=1,
dst_ep=1,
data=t.SerializableBytes(message),
)
)
assert listener.zha_send_event.call_count == 1
assert listener.zha_send_event.call_args == mock.call(
f"{button}_{press_type}",
Expand Down
21 changes: 17 additions & 4 deletions tests/test_tuya_air.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
import zigpy.profiles.zha
import zigpy.types as t

import zhaquirks
from zhaquirks.tuya import TuyaNewManufCluster
Expand Down Expand Up @@ -65,8 +66,14 @@ def air_quality_device(zigpy_device_from_v2_quirk):
def test_co2_sensor(air_quality_device, data, ep_attr, expected_value):
"""Test Tuya Air Quality Sensor."""

air_quality_device.handle_message(
zigpy.profiles.zha.PROFILE_ID, TuyaNewManufCluster.cluster_id, 1, 1, data
air_quality_device.packet_received(
t.ZigbeePacket(
profile_id=zigpy.profiles.zha.PROFILE_ID,
cluster_id=TuyaNewManufCluster.cluster_id,
src_ep=1,
dst_ep=1,
data=t.SerializableBytes(data),
)
)
cluster = getattr(air_quality_device.endpoints[1], ep_attr)
assert cluster.get("measured_value") == expected_value
Expand Down Expand Up @@ -132,8 +139,14 @@ def smart_air_quality_device(zigpy_device_from_v2_quirk):
def test_smart_air_sensor(smart_air_quality_device, data, ep_attr, expected_value):
"""Test Tuya Smart Air Sensor."""

smart_air_quality_device.handle_message(
zigpy.profiles.zha.PROFILE_ID, TuyaNewManufCluster.cluster_id, 1, 1, data
smart_air_quality_device.packet_received(
t.ZigbeePacket(
profile_id=zigpy.profiles.zha.PROFILE_ID,
cluster_id=TuyaNewManufCluster.cluster_id,
src_ep=1,
dst_ep=1,
data=t.SerializableBytes(data),
)
)
cluster = getattr(smart_air_quality_device.endpoints[1], ep_attr)
assert cluster.get("measured_value") == expected_value
85 changes: 54 additions & 31 deletions tests/test_xbee.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import mock

import pytest
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import AnalogOutput, Basic, LevelControl, OnOff

Expand Down Expand Up @@ -177,12 +178,14 @@ async def test_receive_serial_data(zigpy_device_from_quirk):
].add_listener(listener)

# Receive serial data
xbee3_device.handle_message(
XBEE_PROFILE_ID,
XBEE_DATA_CLUSTER,
XBEE_DATA_ENDPOINT,
XBEE_DATA_ENDPOINT,
b"Test UART data",
xbee3_device.packet_received(
t.ZigbeePacket(
profile_id=XBEE_PROFILE_ID,
cluster_id=XBEE_DATA_CLUSTER,
src_ep=XBEE_DATA_ENDPOINT,
dst_ep=XBEE_DATA_ENDPOINT,
data=t.SerializableBytes(b"Test UART data"),
)
)

listener.zha_send_event.assert_called_once_with(
Expand Down Expand Up @@ -350,12 +353,14 @@ async def test_remote_at_non_native(

def mock_at_response(*args, **kwargs):
"""Simulate remote AT command response from device."""
xbee3_device.handle_message(
XBEE_PROFILE_ID,
XBEE_AT_RESPONSE_CLUSTER,
XBEE_AT_ENDPOINT,
XBEE_AT_ENDPOINT,
response_data,
xbee3_device.packet_received(
t.ZigbeePacket(
profile_id=XBEE_PROFILE_ID,
cluster_id=XBEE_AT_RESPONSE_CLUSTER,
src_ep=XBEE_AT_ENDPOINT,
dst_ep=XBEE_AT_ENDPOINT,
data=t.SerializableBytes(response_data),
)
)
return mock.DEFAULT

Expand Down Expand Up @@ -477,12 +482,14 @@ async def test_remote_at_tx_failure(zigpy_device_from_quirk):

def mock_at_response(*args, **kwargs):
"""Simulate remote AT command response from device."""
xbee3_device.handle_message(
XBEE_PROFILE_ID,
XBEE_AT_RESPONSE_CLUSTER,
XBEE_AT_ENDPOINT,
XBEE_AT_ENDPOINT,
b"\x01TP\x04",
xbee3_device.packet_received(
t.ZigbeePacket(
profile_id=XBEE_PROFILE_ID,
cluster_id=XBEE_AT_RESPONSE_CLUSTER,
src_ep=XBEE_AT_ENDPOINT,
dst_ep=XBEE_AT_ENDPOINT,
data=t.SerializableBytes(b"\x01TP\x04"),
)
)
return mock.DEFAULT

Expand Down Expand Up @@ -515,12 +522,16 @@ async def test_io_sample_report(zigpy_device_from_quirk):
]

# {'digital_samples': [1, None, 0, None, 1, None, 0, None, 1, None, 0, None, 1, None, 0], 'analog_samples': [341, None, 682, None, None, None, None, 3305]}
xbee3_device.handle_message(
XBEE_PROFILE_ID,
XBEE_IO_CLUSTER,
XBEE_DATA_ENDPOINT,
XBEE_DATA_ENDPOINT,
b"\x01\x55\x55\x85\x11\x11\x01\x55\x02\xaa\x0c\xe9",
xbee3_device.packet_received(
t.ZigbeePacket(
profile_id=XBEE_PROFILE_ID,
cluster_id=XBEE_IO_CLUSTER,
src_ep=XBEE_DATA_ENDPOINT,
dst_ep=XBEE_DATA_ENDPOINT,
data=t.SerializableBytes(
b"\x01\x55\x55\x85\x11\x11\x01\x55\x02\xaa\x0c\xe9"
),
)
)

for i in range(len(digital_listeners)):
Expand Down Expand Up @@ -564,12 +575,16 @@ async def test_io_sample_report_on_at_response(zigpy_device_from_quirk):

def mock_at_response(*args, **kwargs):
"""Simulate remote AT command response from device."""
xbee_device.handle_message(
XBEE_PROFILE_ID,
XBEE_AT_RESPONSE_CLUSTER,
XBEE_AT_ENDPOINT,
XBEE_AT_ENDPOINT,
b"\x01IS\x00\x01\x55\x55\x85\x11\x11\x01\x55\x02\xaa\x0c\xe9",
xbee_device.packet_received(
t.ZigbeePacket(
profile_id=XBEE_PROFILE_ID,
cluster_id=XBEE_AT_RESPONSE_CLUSTER,
src_ep=XBEE_AT_ENDPOINT,
dst_ep=XBEE_AT_ENDPOINT,
data=t.SerializableBytes(
b"\x01IS\x00\x01\x55\x55\x85\x11\x11\x01\x55\x02\xaa\x0c\xe9"
),
)
)
return mock.DEFAULT

Expand Down Expand Up @@ -649,7 +664,15 @@ async def test_zdo(handle_mgmt_lqi_resp, zigpy_device_from_quirk):
xbee3_device = zigpy_device_from_quirk(XBee3Sensor)

# Receive ZDOCmd.IEEE_addr_req
xbee3_device.handle_message(0, 0x0001, 0, 0, b"\x07\x34\x12\x00\x00")
xbee3_device.packet_received(
t.ZigbeePacket(
profile_id=0,
cluster_id=0x01,
src_ep=0,
dst_ep=0,
data=t.SerializableBytes(b"\x07\x34\x12\x00\x00"),
)
)

assert handle_mgmt_lqi_resp.call_count == 1
assert len(handle_mgmt_lqi_resp.call_args_list[0][0]) == 4
Expand Down
Loading
Loading