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

feat: Detect HA matter bridge association #2792

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

kennylevinsen
Copy link
Contributor

This is an entirely untested take on @danielbrunt57's idea from #2709 (comment).

I do not own any Alexa devices and have no means to run or test this, hence draft. My incentive for making this PR is to allow home-assistant-matter-hub to correctly report bridged device vendor names (which should be the vendor of the device, not the bridge), which would invalidate the existing workaround.

Prior discussion: #2709
Prior PR: #2730

Avoid deep nesting by building a dict of appliances and iterating over
its values. A dict is used to allow appliance checks to look up other
appliances as part of their evaluation.
Detect the association between leaf appliances and bridge appliances,
and detect known HA matter bridges using the bridge appliance. This
allows us to more robustly detect known bridges instead of relying on
particular bridge behaviors, and can allow easily filtering all matter
bridges altogether.

Related: alandtse#2709
@kennylevinsen kennylevinsen changed the title Detect HA matter bridge association feat: Detect HA matter bridge association Jan 7, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 12657356426

Details

  • 2 of 60 (3.33%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 9.405%

Changes Missing Coverage Covered Lines Changed/Added Lines %
custom_components/alexa_media/alexa_entity.py 2 60 3.33%
Totals Coverage Status
Change from base Build 12596243117: 0.004%
Covered Lines: 327
Relevant Lines: 3477

💛 - Coveralls

@danielbrunt57
Copy link
Collaborator

Tested and confirmed working!

2025-01-08 00:06:39.639 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] is_known_ha_bridge: True (manufacturer_name: t0bst4r)

2025-01-08 00:06:39.639 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] Found Home Assistant bridge, skipping {'applianceId': 'AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#58', 'endpointTypeId': '', 'driverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'manufacturerName': 't0bst4r', 'friendlyDescription': 't0bst4r smart device', 'modelName': '', 'deviceType': '', 'version': '0', 'friendlyName': 'Scene: Sleep mode', 'friendlyNameModifiedAt': 1736317717001, 'capabilitiesModifiedAt': 1736317717001, 'ipAddress': '', 'port': '', 'entityId': 'c4d6c469-b5d3-40d1-a45f-8985ea73fd64', 'applianceNetworkState': {'reachability': 'REACHABLE', 'lastSeenAt': 1736323599420, 'createdAt': 1736317717001, 'lastSeenDiscoverySessionId': {'value': '0fc55f83-33ca-4fe5-b9ee-df8c8d30b400'}}, 'tags': {'tagNameToValueSetMap': {}}, 'additionalApplianceDetails': {'additionalApplianceDetails': {}}, 'firmwareVersion': '0', 'actions': [], 'capabilities': [{'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'powerState'}], 'proactivelyReported': True, 'retrievable': True, 'readOnly': False}, 'interfaceName': 'Alexa.PowerController'}, {'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'connectivity'}], 'proactivelyReported': True, 'retrievable': True, 'readOnly': False}, 'interfaceName': 'Alexa.EndpointHealth'}], 'applianceTypes': ['SMARTPLUG'], 'isEnabled': True, 'aliases': [], 'connectedVia': 'Kitchen Echo Dot', 'alexaDeviceIdentifierList': [], 'applianceKey': 'c4d6c469-b5d3-40d1-a45f-8985ea73fd64', 'identifiers': {}, 'ipaddress': '', 'applianceLambdaControlled': True, 'applianceDriverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'mergedApplianceIds': ['AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#58']}

2025-01-08 00:06:39.639 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] is_known_ha_bridge: True (manufacturer_name: t0bst4r)

2025-01-08 00:06:39.639 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] Found Home Assistant bridge, skipping {'applianceId': 'AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#57', 'endpointTypeId': '', 'driverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'manufacturerName': 't0bst4r', 'friendlyDescription': 't0bst4r smart device', 'modelName': '', 'deviceType': '', 'version': '0', 'friendlyName': 'Scene: Good Night', 'friendlyNameModifiedAt': 1736317714662, 'capabilitiesModifiedAt': 1736317714662, 'ipAddress': '', 'port': '', 'entityId': 'c45979de-cddc-4b4c-b959-4ef066802cd7', 'applianceNetworkState': {'reachability': 'REACHABLE', 'lastSeenAt': 1736323599420, 'createdAt': 1736317714662, 'lastSeenDiscoverySessionId': {'value': '1b22186d-8b32-4efc-ad73-bc88cfecb033'}}, 'tags': {'tagNameToValueSetMap': {}}, 'additionalApplianceDetails': {'additionalApplianceDetails': {}}, 'firmwareVersion': '0', 'actions': [], 'capabilities': [{'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'powerState'}], 'proactivelyReported': True, 'retrievable': True, 'readOnly': False}, 'interfaceName': 'Alexa.PowerController'}, {'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'connectivity'}], 'proactivelyReported': True, 'retrievable': True, 'readOnly': False}, 'interfaceName': 'Alexa.EndpointHealth'}], 'applianceTypes': ['SMARTPLUG'], 'isEnabled': True, 'aliases': [], 'connectedVia': 'Echo Show 8', 'alexaDeviceIdentifierList': [], 'applianceKey': 'c45979de-cddc-4b4c-b959-4ef066802cd7', 'identifiers': {}, 'ipaddress': '', 'applianceLambdaControlled': True, 'applianceDriverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'mergedApplianceIds': ['AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#57']}

2025-01-08 00:06:39.640 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] is_known_ha_bridge: True (manufacturer_name: t0bst4r)

2025-01-08 00:06:39.640 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] Found Home Assistant bridge, skipping {'applianceId': 'AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#59', 'endpointTypeId': '', 'driverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'manufacturerName': 't0bst4r', 'friendlyDescription': 't0bst4r smart device', 'modelName': '', 'deviceType': '', 'version': '0', 'friendlyName': 'Scene: Good Morning', 'friendlyNameModifiedAt': 1736317719267, 'capabilitiesModifiedAt': 1736317719267, 'ipAddress': '', 'port': '', 'entityId': 'efe4b581-933c-47f0-ada8-93b752ac33e9', 'applianceNetworkState': {'reachability': 'REACHABLE', 'lastSeenAt': 1736323599420, 'createdAt': 1736317719267, 'lastSeenDiscoverySessionId': {'value': '46130a51-e822-439a-82ab-a38b3a297146'}}, 'tags': {'tagNameToValueSetMap': {}}, 'additionalApplianceDetails': {'additionalApplianceDetails': {}}, 'firmwareVersion': '0', 'actions': [], 'capabilities': [{'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'powerState'}], 'proactivelyReported': True, 'retrievable': True, 'readOnly': False}, 'interfaceName': 'Alexa.PowerController'}, {'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'connectivity'}], 'proactivelyReported': True, 'retrievable': True, 'readOnly': False}, 'interfaceName': 'Alexa.EndpointHealth'}], 'applianceTypes': ['SMARTPLUG'], 'isEnabled': True, 'aliases': [], 'connectedVia': 'Kitchen Echo Dot', 'alexaDeviceIdentifierList': [], 'applianceKey': 'efe4b581-933c-47f0-ada8-93b752ac33e9', 'identifiers': {}, 'ipaddress': '', 'applianceLambdaControlled': True, 'applianceDriverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'mergedApplianceIds': ['AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#59']}

2025-01-08 00:06:39.640 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] is_known_ha_bridge: True (manufacturer_name: t0bst4r)

2025-01-08 00:06:39.640 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] Found Home Assistant bridge, skipping {'applianceId': 'AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#65', 'endpointTypeId': '', 'driverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'manufacturerName': 't0bst4r', 'friendlyDescription': 't0bst4r smart device', 'modelName': '', 'deviceType': '', 'version': '0', 'friendlyName': 'Vehicle Occupancy', 'friendlyNameModifiedAt': 1736317733369, 'capabilitiesModifiedAt': 1736317733369, 'ipAddress': '', 'port': '', 'entityId': '2ab3553a-7202-459a-88c4-ed3190a7119a', 'applianceNetworkState': {'reachability': 'REACHABLE', 'lastSeenAt': 1736323599420, 'createdAt': 1736317733369, 'lastSeenDiscoverySessionId': {'value': 'df3c9925-8877-4525-b79a-6022bc28cce9'}}, 'tags': {'tagNameToValueSetMap': {}}, 'additionalApplianceDetails': {'additionalApplianceDetails': {}}, 'firmwareVersion': '0', 'actions': [], 'capabilities': [{'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'detectionState'}], 'proactivelyReported': True, 'retrievable': False, 'readOnly': False}, 'interfaceName': 'Alexa.MotionSensor'}, {'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'connectivity'}], 'proactivelyReported': True, 'retrievable': True, 'readOnly': False}, 'interfaceName': 'Alexa.EndpointHealth'}], 'applianceTypes': ['MOTION_SENSOR'], 'isEnabled': True, 'aliases': [], 'connectedVia': 'Echo Show 8', 'alexaDeviceIdentifierList': [], 'applianceKey': '2ab3553a-7202-459a-88c4-ed3190a7119a', 'identifiers': {}, 'ipaddress': '', 'applianceLambdaControlled': True, 'applianceDriverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'mergedApplianceIds': ['AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#65']}

2025-01-08 00:06:39.640 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] is_known_ha_bridge: True (manufacturer_name: t0bst4r)

2025-01-08 00:06:39.640 DEBUG (MainThread) [custom_components.alexa_media.alexa_entity] Found Home Assistant bridge, skipping {'applianceId': 'AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#64', 'endpointTypeId': '', 'driverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'manufacturerName': 't0bst4r', 'friendlyDescription': 't0bst4r smart device', 'modelName': '', 'deviceType': '', 'version': '0', 'friendlyName': 'House Motion', 'friendlyNameModifiedAt': 1736317730955, 'capabilitiesModifiedAt': 1736317730955, 'ipAddress': '', 'port': '', 'entityId': 'b514f9f6-ec79-4c2f-9768-955b33581147', 'applianceNetworkState': {'reachability': 'REACHABLE', 'lastSeenAt': 1736323599420, 'createdAt': 1736317730955, 'lastSeenDiscoverySessionId': {'value': '9e53d311-cb0e-40d7-aac5-ec594aa9092e'}}, 'tags': {'tagNameToValueSetMap': {}}, 'additionalApplianceDetails': {'additionalApplianceDetails': {}}, 'firmwareVersion': '0', 'actions': [], 'capabilities': [{'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'detectionState'}], 'proactivelyReported': True, 'retrievable': False, 'readOnly': False}, 'interfaceName': 'Alexa.ContactSensor'}, {'capabilityType': 'AVSInterfaceCapability', 'type': 'AlexaInterface', 'version': '3', 'properties': {'supported': [{'name': 'connectivity'}], 'proactivelyReported': True, 'retrievable': True, 'readOnly': False}, 'interfaceName': 'Alexa.EndpointHealth'}], 'applianceTypes': ['CONTACT_SENSOR'], 'isEnabled': True, 'aliases': [], 'connectedVia': 'Kitchen Echo Dot', 'alexaDeviceIdentifierList': [], 'applianceKey': 'b514f9f6-ec79-4c2f-9768-955b33581147', 'identifiers': {}, 'ipaddress': '', 'applianceLambdaControlled': True, 'applianceDriverIdentity': {'namespace': 'AAA', 'identifier': 'SonarCloudService'}, 'mergedApplianceIds': ['AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#64']}

etc., etc.

@kennylevinsen kennylevinsen marked this pull request as ready for review January 8, 2025 09:22
@kennylevinsen
Copy link
Contributor Author

Tested and confirmed working!

Well I guess it doesn't have to be a draft then. :)

Thanks for testing!

@alandtse alandtse merged commit 6152017 into alandtse:dev Jan 14, 2025
4 of 5 checks passed
@kennylevinsen kennylevinsen deleted the detect-bridges branch January 14, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants