Home Assistant Unofficial Reference 2024.12.1
models.py
Go to the documentation of this file.
1 """Models used for the Matter integration."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 from typing import Any, TypedDict
7 
8 from chip.clusters import Objects as clusters
9 from chip.clusters.Objects import Cluster, ClusterAttributeDescriptor
10 from matter_server.client.models.device_types import DeviceType
11 from matter_server.client.models.node import MatterEndpoint
12 
13 from homeassistant.const import Platform
14 from homeassistant.helpers.entity import EntityDescription
15 
16 type SensorValueTypes = type[
17  clusters.uint | int | clusters.Nullable | clusters.float32 | float
18 ]
19 
20 
21 class MatterDeviceInfo(TypedDict):
22  """Dictionary with Matter Device info.
23 
24  Used to send to other Matter controllers,
25  such as Google Home to prevent duplicated devices.
26 
27  Reference: https://developers.home.google.com/matter/device-deduplication
28  """
29 
30  unique_id: str
31  vendor_id: str # vendorId hex string
32  product_id: str # productId hex string
33 
34 
35 @dataclass
37  """Info discovered from (primary) Matter Attribute to create entity."""
38 
39  # MatterEndpoint to which the value(s) belongs
40  endpoint: MatterEndpoint
41 
42  # the home assistant platform for which an entity should be created
43  platform: Platform
44 
45  # All attributes that need to be watched by entity (incl. primary)
46  attributes_to_watch: list[type[ClusterAttributeDescriptor]]
47 
48  # the entity description to use
49  entity_description: EntityDescription
50 
51  # entity class to use to instantiate the entity
52  entity_class: type
53 
54  # the original discovery schema used to create this entity
55  discovery_schema: MatterDiscoverySchema
56 
57  @property
58  def primary_attribute(self) -> type[ClusterAttributeDescriptor]:
59  """Return Primary Attribute belonging to the entity."""
60  return self.attributes_to_watch[0]
61 
62 
63 @dataclass
65  """Matter discovery schema.
66 
67  The Matter endpoint and its (primary) Attribute
68  for an entity must match these conditions.
69  """
70 
71  # specify the hass platform for which this scheme applies (e.g. light, sensor)
72  platform: Platform
73 
74  # platform-specific entity description
75  entity_description: EntityDescription
76 
77  # entity class to use to instantiate the entity
78  entity_class: type
79 
80  # DISCOVERY OPTIONS
81 
82  # [required] attributes that ALL need to be present
83  # on the node for this scheme to pass (minimal one == primary)
84  required_attributes: tuple[type[ClusterAttributeDescriptor], ...]
85 
86  # [optional] the value's endpoint must contain this devicetype(s)
87  device_type: tuple[type[DeviceType] | DeviceType, ...] | None = None
88 
89  # [optional] the value's endpoint must NOT contain this devicetype(s)
90  not_device_type: tuple[type[DeviceType] | DeviceType, ...] | None = None
91 
92  # [optional] the endpoint's vendor_id must match ANY of these values
93  vendor_id: tuple[int, ...] | None = None
94 
95  # [optional] the endpoint's product_name must match ANY of these values
96  product_name: tuple[str, ...] | None = None
97 
98  # [optional] the attribute's endpoint_id must match ANY of these values
99  endpoint_id: tuple[int, ...] | None = None
100 
101  # [optional] attributes that MAY NOT be present
102  # (on the same endpoint) for this scheme to pass
103  absent_attributes: tuple[type[ClusterAttributeDescriptor], ...] | None = None
104 
105  # [optional] cluster(s) that MAY NOT be present
106  # (on ANY endpoint) for this scheme to pass
107  absent_clusters: tuple[type[Cluster], ...] | None = None
108 
109  # [optional] additional attributes that may be present (on the same endpoint)
110  # these attributes are copied over to attributes_to_watch and
111  # are not discovered by other entities
112  optional_attributes: tuple[type[ClusterAttributeDescriptor], ...] | None = None
113 
114  # [optional] the primary attribute value must contain this value
115  # for example for the AcceptedCommandList
116  # NOTE: only works for list values
117  value_contains: Any | None = None
118 
119  # [optional] the primary attribute's cluster featuremap must contain this value
120  # for example for the DoorSensor on a DoorLock Cluster
121  featuremap_contains: int | None = None
122 
123  # [optional] bool to specify if this primary value may be discovered
124  # by multiple platforms
125  allow_multi: bool = False
type[ClusterAttributeDescriptor] primary_attribute(self)
Definition: models.py:58