Skip to content

Commit

Permalink
add test and correct lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Oct 16, 2024
1 parent c005e20 commit 4bed7c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 3 additions & 4 deletions homeassistant/components/zha/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,10 @@ async def _handle_entity_registry_updated(
assert ieee in self.device_proxies

zha_device_proxy = self.device_proxies[ieee]
if entity_entry.unique_id not in zha_device_proxy.device.platform_entities:
entity_key = (entity_entry.domain, entity_entry.unique_id)
if entity_key not in zha_device_proxy.device.platform_entities:
return

Check warning on line 574 in homeassistant/components/zha/helpers.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/zha/helpers.py#L574

Added line #L574 was not covered by tests
platform_entity = zha_device_proxy.device.platform_entities[
entity_entry.unique_id
]
platform_entity = zha_device_proxy.device.platform_entities[entity_key]
if entity_entry.disabled:
platform_entity.disable()
else:
Expand Down
19 changes: 19 additions & 0 deletions tests/components/zha/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from homeassistant.const import STATE_OFF, STATE_ON, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er

from .common import find_entity_id, send_attributes_report
from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE
Expand All @@ -37,6 +38,7 @@ def binary_sensor_platform_only():

async def test_binary_sensor(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
setup_zha,
zigpy_device_mock,
) -> None:
Expand Down Expand Up @@ -77,3 +79,20 @@ async def test_binary_sensor(
hass, cluster, {general.OnOff.AttributeDefs.on_off.id: OFF}
)
assert hass.states.get(entity_id).state == STATE_OFF

# test enable / disable sync w/ ZHA library
entity_entry = entity_registry.async_get(entity_id)
entity_key = (Platform.BINARY_SENSOR, entity_entry.unique_id)
assert zha_device_proxy.device.platform_entities.get(entity_key).enabled

entity_registry.async_update_entity(
entity_id=entity_id, disabled_by=er.RegistryEntryDisabler.USER
)
await hass.async_block_till_done()

assert not zha_device_proxy.device.platform_entities.get(entity_key).enabled

entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done()

assert zha_device_proxy.device.platform_entities.get(entity_key).enabled

0 comments on commit 4bed7c3

Please sign in to comment.