Adjust Matter discovery logic to disallow the primary value(s) to be None ()

pull/129757/head
Marcel van der Veldt 2025-01-28 15:24:15 +01:00 committed by GitHub
parent 259f57b3aa
commit 22e72953e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 23 additions and 1 deletions

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Generator
from chip.clusters.Objects import ClusterAttributeDescriptor
from chip.clusters.ClusterObjects import ClusterAttributeDescriptor, NullValue
from matter_server.client.models.node import MatterEndpoint
from homeassistant.const import Platform
@ -121,6 +121,13 @@ def async_discover_entities(
):
continue
# check if value exists but is none/null
if not schema.allow_none_value and any(
endpoint.get_attribute_value(None, val_schema) in (None, NullValue)
for val_schema in schema.required_attributes
):
continue
# check for required value in (primary) attribute
primary_attribute = schema.required_attributes[0]
primary_value = endpoint.get_attribute_value(None, primary_attribute)

View File

@ -128,3 +128,6 @@ class MatterDiscoverySchema:
# [optional] bool to specify if this primary value may be discovered
# by multiple platforms
allow_multi: bool = False
# [optional] the primary attribute value may not be null/None
allow_none_value: bool = False

View File

@ -86,6 +86,8 @@ DISCOVERY_SCHEMAS = [
),
entity_class=MatterNumber,
required_attributes=(clusters.LevelControl.Attributes.OnLevel,),
# allow None value to account for 'default' value
allow_none_value=True,
),
MatterDiscoverySchema(
platform=Platform.NUMBER,
@ -103,6 +105,8 @@ DISCOVERY_SCHEMAS = [
),
entity_class=MatterNumber,
required_attributes=(clusters.LevelControl.Attributes.OnTransitionTime,),
# allow None value to account for 'default' value
allow_none_value=True,
),
MatterDiscoverySchema(
platform=Platform.NUMBER,
@ -120,6 +124,8 @@ DISCOVERY_SCHEMAS = [
),
entity_class=MatterNumber,
required_attributes=(clusters.LevelControl.Attributes.OffTransitionTime,),
# allow None value to account for 'default' value
allow_none_value=True,
),
MatterDiscoverySchema(
platform=Platform.NUMBER,
@ -137,6 +143,8 @@ DISCOVERY_SCHEMAS = [
),
entity_class=MatterNumber,
required_attributes=(clusters.LevelControl.Attributes.OnOffTransitionTime,),
# allow None value to account for 'default' value
allow_none_value=True,
),
MatterDiscoverySchema(
platform=Platform.NUMBER,

View File

@ -267,6 +267,8 @@ DISCOVERY_SCHEMAS = [
),
entity_class=MatterAttributeSelectEntity,
required_attributes=(clusters.OnOff.Attributes.StartUpOnOff,),
# allow None value for previous state
allow_none_value=True,
),
MatterDiscoverySchema(
platform=Platform.SELECT,

View File

@ -261,5 +261,6 @@ DISCOVERY_SCHEMAS = [
clusters.OtaSoftwareUpdateRequestor.Attributes.UpdateState,
clusters.OtaSoftwareUpdateRequestor.Attributes.UpdateStateProgress,
),
allow_none_value=True,
),
]

View File

@ -208,5 +208,6 @@ DISCOVERY_SCHEMAS = [
clusters.PowerSource.Attributes.BatPercentRemaining,
),
device_type=(device_types.RoboticVacuumCleaner,),
allow_none_value=True,
),
]