mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Implement Ignore list for poll control configuration on Ikea devices (#48667)
Co-authored-by: Hmmbob <33529490+hmmbob@users.noreply.github.com>
This commit is contained in:
parent
6dc1414b69
commit
6204765835
@ -391,6 +391,9 @@ class PollControl(ZigbeeChannel):
|
|||||||
CHECKIN_INTERVAL = 55 * 60 * 4 # 55min
|
CHECKIN_INTERVAL = 55 * 60 * 4 # 55min
|
||||||
CHECKIN_FAST_POLL_TIMEOUT = 2 * 4 # 2s
|
CHECKIN_FAST_POLL_TIMEOUT = 2 * 4 # 2s
|
||||||
LONG_POLL = 6 * 4 # 6s
|
LONG_POLL = 6 * 4 # 6s
|
||||||
|
_IGNORED_MANUFACTURER_ID = {
|
||||||
|
4476,
|
||||||
|
} # IKEA
|
||||||
|
|
||||||
async def async_configure_channel_specific(self) -> None:
|
async def async_configure_channel_specific(self) -> None:
|
||||||
"""Configure channel: set check-in interval."""
|
"""Configure channel: set check-in interval."""
|
||||||
@ -416,8 +419,14 @@ class PollControl(ZigbeeChannel):
|
|||||||
async def check_in_response(self, tsn: int) -> None:
|
async def check_in_response(self, tsn: int) -> None:
|
||||||
"""Respond to checkin command."""
|
"""Respond to checkin command."""
|
||||||
await self.checkin_response(True, self.CHECKIN_FAST_POLL_TIMEOUT, tsn=tsn)
|
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.set_long_poll_interval(self.LONG_POLL)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def skip_manufacturer_id(self, manufacturer_code: int) -> None:
|
||||||
|
"""Block a specific manufacturer id from changing default polling."""
|
||||||
|
self._IGNORED_MANUFACTURER_ID.add(manufacturer_code)
|
||||||
|
|
||||||
|
|
||||||
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.PowerConfiguration.cluster_id)
|
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.PowerConfiguration.cluster_id)
|
||||||
class PowerConfigurationChannel(ZigbeeChannel):
|
class PowerConfigurationChannel(ZigbeeChannel):
|
||||||
|
@ -492,6 +492,38 @@ async def test_poll_control_cluster_command(hass, poll_control_device):
|
|||||||
assert data["device_id"] == poll_control_device.device_id
|
assert data["device_id"] == poll_control_device.device_id
|
||||||
|
|
||||||
|
|
||||||
|
async def test_poll_control_ignore_list(hass, poll_control_device):
|
||||||
|
"""Test poll control channel ignore list."""
|
||||||
|
set_long_poll_mock = AsyncMock()
|
||||||
|
poll_control_ch = poll_control_device.channels.pools[0].all_channels["1:0x0020"]
|
||||||
|
cluster = poll_control_ch.cluster
|
||||||
|
|
||||||
|
with mock.patch.object(cluster, "set_long_poll_interval", set_long_poll_mock):
|
||||||
|
await poll_control_ch.check_in_response(33)
|
||||||
|
|
||||||
|
assert set_long_poll_mock.call_count == 1
|
||||||
|
|
||||||
|
set_long_poll_mock.reset_mock()
|
||||||
|
poll_control_ch.skip_manufacturer_id(4151)
|
||||||
|
with mock.patch.object(cluster, "set_long_poll_interval", set_long_poll_mock):
|
||||||
|
await poll_control_ch.check_in_response(33)
|
||||||
|
|
||||||
|
assert set_long_poll_mock.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_poll_control_ikea(hass, poll_control_device):
|
||||||
|
"""Test poll control channel ignore list for ikea."""
|
||||||
|
set_long_poll_mock = AsyncMock()
|
||||||
|
poll_control_ch = poll_control_device.channels.pools[0].all_channels["1:0x0020"]
|
||||||
|
cluster = poll_control_ch.cluster
|
||||||
|
|
||||||
|
poll_control_device.device.node_desc.manufacturer_code = 4476
|
||||||
|
with mock.patch.object(cluster, "set_long_poll_interval", set_long_poll_mock):
|
||||||
|
await poll_control_ch.check_in_response(33)
|
||||||
|
|
||||||
|
assert set_long_poll_mock.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def zigpy_zll_device(zigpy_device_mock):
|
def zigpy_zll_device(zigpy_device_mock):
|
||||||
"""ZLL device fixture."""
|
"""ZLL device fixture."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user