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

Forward Philips Hue contact sensor changes to OnOff cluster #3541

Merged

Conversation

TheJulianJES
Copy link
Collaborator

@TheJulianJES TheJulianJES commented Nov 24, 2024

Proposed change

This forwards all attribute updates from the custom Hue contact attribute to the OnOff cluster.
The advantage is that if commands from/to the OnOff cluster are missed, we'll get an attribute report in (max) 15 minutes from the custom Hue contact attribute.

We do this to avoid creating another entity and causing a breaking change if we removed the OnOff for this device.
The custom cluster is also only bound and sets up attribute reporting when running Home Assistant Core 2024.11.0 or later. Some devices may have been set up before. These devices will still work with this PR, as the OnOff changes are also still received.
Using this approach, we also stay flexible if we do further changes to the OnOff entities in the future (e.g. only creating on a whitelist for supported devices, so we don't create them for remotes).

cc @mguaylam
Please test the changes from this PR again, as they're slightly different. Just install soc001.py as a custom quirk again.

Additional information

Closes #3464
Fixes #3314 (no entity for for last contact/tamper change though)

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works

@TheJulianJES TheJulianJES added the smash This PR is close to be merged soon label Nov 24, 2024
Copy link

codecov bot commented Nov 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.62%. Comparing base (f239f30) to head (5db2de4).
Report is 7 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #3541   +/-   ##
=======================================
  Coverage   89.61%   89.62%           
=======================================
  Files         313      313           
  Lines       10218    10224    +6     
=======================================
+ Hits         9157     9163    +6     
  Misses       1061     1061           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mguaylam
Copy link
Contributor

ZHA can't setup anymore throwing this error :

Enregistreur: homeassistant.config_entries
Source: config_entries.py:635
S'est produit pour la première fois: 05:27:29 (1 occurrences)
Dernier enregistrement: 05:27:29

Error setting up entry HubZ Smart Home Controller, s/n: 81300134 - Silicon Labs for zha
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 635, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/zha/__init__.py", line 132, in async_setup_entry
    async with radio_mgr.connect_zigpy_app() as app:
  File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/zha/radio_manager.py", line 182, in connect_zigpy_app
    app = await self.radio_type.controller.new(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zigpy/application.py", line 238, in new
    await app._load_db()
  File "/usr/local/lib/python3.12/site-packages/zigpy/application.py", line 110, in _load_db
    await self._dblistener.load()
  File "/usr/local/lib/python3.12/site-packages/zigpy/appdb.py", line 684, in load
    device = zigpy.quirks.get_device(device)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zigpy/quirks/__init__.py", line 43, in get_device
    return _DEVICE_REGISTRY.get_device(device)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zigpy/quirks/registry.py", line 125, in get_device
    raise MultipleQuirksMatchException(
zigpy.exceptions.MultipleQuirksMatchException: Multiple matches found for device <Device model='SOC001' manuf='Signify Netherlands B.V.' nwk=0x2B03 ieee=00:17:88:01:0d:ce:f9:51 is_initialized=True>: [QuirksV2RegistryEntry(quirk_file=PosixPath('/usr/local/lib/python3.12/site-packages/zhaquirks/philips/soc001.py'), quirk_file_line=46, manufacturer_model_metadata=(ManufacturerModelMetadata(manufacturer='Signify Netherlands B.V.', model='SOC001'),), friendly_name=None, device_alerts=(), filters=(), custom_device_class=None, device_node_descriptor=None, skip_device_configuration=False, adds_metadata=(), removes_metadata=(), replaces_metadata=(ReplacesMetadata(remove=RemovesMetadata(cluster_id=64518, endpoint_id=2, cluster_type=<ClusterType.Server: 0>), add=AddsMetadata(cluster=<class 'zhaquirks.philips.soc001.PhilipsContactCluster'>, endpoint_id=2, cluster_type=<ClusterType.Server: 0>, constant_attributes=frozendict.frozendict({}))),), replaces_cluster_occurrences_metadata=(), entity_metadata=(BinarySensorMetadata(entity_platform=<EntityPlatform.BINARY_SENSOR: 'binary_sensor'>, entity_type=<EntityType.DIAGNOSTIC: 'diagnostic'>, cluster_id=64518, endpoint_id=2, cluster_type=<ClusterType.Server: 0>, initially_disabled=False, attribute_initialized_from_cache=True, translation_key=None, fallback_name='Tamper', attribute_name='tamper', reporting_config=None, device_class=<BinarySensorDeviceClass.TAMPER: 'tamper'>),), device_automation_triggers_metadata=frozendict.frozendict({})), QuirksV2RegistryEntry(quirk_file=PosixPath('/config/quirks/soc001.py'), quirk_file_line=63, manufacturer_model_metadata=(ManufacturerModelMetadata(manufacturer='Signify Netherlands B.V.', model='SOC001'),), friendly_name=None, device_alerts=(), filters=(), custom_device_class=None, device_node_descriptor=None, skip_device_configuration=False, adds_metadata=(), removes_metadata=(), replaces_metadata=(ReplacesMetadata(remove=RemovesMetadata(cluster_id=64518, endpoint_id=2, cluster_type=<ClusterType.Server: 0>), add=AddsMetadata(cluster=<class 'soc001.PhilipsContactCluster'>, endpoint_id=2, cluster_type=<ClusterType.Server: 0>, constant_attributes=frozendict.frozendict({}))),), replaces_cluster_occurrences_metadata=(), entity_metadata=(BinarySensorMetadata(entity_platform=<EntityPlatform.BINARY_SENSOR: 'binary_sensor'>, entity_type=<EntityType.DIAGNOSTIC: 'diagnostic'>, cluster_id=64518, endpoint_id=2, cluster_type=<ClusterType.Server: 0>, initially_disabled=False, attribute_initialized_from_cache=True, translation_key=None, fallback_name='Tamper', attribute_name='tamper', reporting_config=None, device_class=<BinarySensorDeviceClass.TAMPER: 'tamper'>),), device_automation_triggers_metadata=frozendict.frozendict({}))]

@TheJulianJES
Copy link
Collaborator Author

TheJulianJES commented Nov 25, 2024

Uh, yeah. We have an issue where custom v2 quirks will cause this when there's already a v2 quirk present for the same device..

There's a workaround (in some other issue or PR) that you can use that deletes the old SOC001 registry entry. I'll put it here later if I don't forget.

@TheJulianJES
Copy link
Collaborator Author

See this workaround: #3465 (comment)

from zigpy.quirks import DEVICE_REGISTRY
# other existing imports from custom quirks

# remove upstream quirk from registry
del DEVICE_REGISTRY._registry_v2[("Signify Netherlands B.V.", "SOC001")]

# add custom quirk...

@mguaylam
Copy link
Contributor

It works and only create the necessary events. Thanks!
image

@TheJulianJES
Copy link
Collaborator Author

Thanks for testing!

@TheJulianJES TheJulianJES merged commit bb63900 into zigpy:dev Nov 26, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smash This PR is close to be merged soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Device Support Request] SOC001 - Philips Contact sensor
2 participants