From 4a6bb96a0fc5f2c7027715a54065bf74252983d8 Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Sun, 25 Apr 2021 21:15:04 -0400 Subject: [PATCH] Stop fast polling of a Zigbee device after a check-in command (#49685) * Stop fast polling after a check-in * Update tests --- homeassistant/components/zha/core/channels/general.py | 1 + tests/components/zha/test_channels.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/zha/core/channels/general.py b/homeassistant/components/zha/core/channels/general.py index 3bd08e6f93e..881a4512bef 100644 --- a/homeassistant/components/zha/core/channels/general.py +++ b/homeassistant/components/zha/core/channels/general.py @@ -422,6 +422,7 @@ class PollControl(ZigbeeChannel): await self.checkin_response(True, self.CHECKIN_FAST_POLL_TIMEOUT, tsn=tsn) if self._ch_pool.manufacturer_code not in self._IGNORED_MANUFACTURER_ID: await self.set_long_poll_interval(self.LONG_POLL) + await self.fast_poll_stop() @callback def skip_manufacturer_id(self, manufacturer_code: int) -> None: diff --git a/tests/components/zha/test_channels.py b/tests/components/zha/test_channels.py index a391439a239..f60b7d4859a 100644 --- a/tests/components/zha/test_channels.py +++ b/tests/components/zha/test_channels.py @@ -445,19 +445,22 @@ async def test_poll_control_checkin_response(poll_control_ch): """Test poll control channel checkin response.""" rsp_mock = AsyncMock() set_interval_mock = AsyncMock() + fast_poll_mock = AsyncMock() cluster = poll_control_ch.cluster patch_1 = mock.patch.object(cluster, "checkin_response", rsp_mock) patch_2 = mock.patch.object(cluster, "set_long_poll_interval", set_interval_mock) + patch_3 = mock.patch.object(cluster, "fast_poll_stop", fast_poll_mock) - with patch_1, patch_2: + with patch_1, patch_2, patch_3: await poll_control_ch.check_in_response(33) assert rsp_mock.call_count == 1 assert set_interval_mock.call_count == 1 + assert fast_poll_mock.call_count == 1 await poll_control_ch.check_in_response(33) - assert cluster.endpoint.request.call_count == 2 - assert cluster.endpoint.request.await_count == 2 + assert cluster.endpoint.request.call_count == 3 + assert cluster.endpoint.request.await_count == 3 assert cluster.endpoint.request.call_args_list[0][0][1] == 33 assert cluster.endpoint.request.call_args_list[0][0][0] == 0x0020 assert cluster.endpoint.request.call_args_list[1][0][0] == 0x0020