Bump python-matter-server to 3.0.0 (#88607)

* Bump python-matter-server to 3.0.0

Include all fixes for the changed api schema of the library

* fix test fixtures

* remove invalid data from fixtures

* fix some of the tests

* fix binary sensor bug

* fix sensor bug

* fix switch test

* fix tests

* adjust bugs and typos
This commit is contained in:
Marcel van der Veldt 2023-02-22 20:24:30 +01:00 committed by GitHub
parent 9c7adfc4b2
commit 881e85d74f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 3687 additions and 31021 deletions

View file

@ -4,12 +4,10 @@ from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from functools import partial
from typing import Any
from chip.clusters import Objects as clusters
from chip.clusters.Types import Nullable, NullValue
from matter_server.common.models import device_types
from matter_server.common.models.device_type_instance import MatterDeviceTypeInstance
from matter_server.client.models import device_types
from homeassistant.components.sensor import (
SensorDeviceClass,
@ -53,13 +51,12 @@ class MatterSensor(MatterEntity, SensorEntity):
def _update_from_device(self) -> None:
"""Update from device."""
measurement: Nullable | float | None
measurement = _get_attribute_value(
self._device_type_instance,
measurement = self.get_matter_attribute_value(
# We always subscribe to a single value
self.entity_description.subscribe_attributes[0],
)
if measurement is NullValue or measurement is None:
if measurement == NullValue or measurement is None:
measurement = None
else:
measurement = self.entity_description.measurement_to_ha(measurement)
@ -67,29 +64,6 @@ class MatterSensor(MatterEntity, SensorEntity):
self._attr_native_value = measurement
def _get_attribute_value(
device_type_instance: MatterDeviceTypeInstance,
attribute: clusters.ClusterAttributeDescriptor,
) -> Any:
"""Return the value of an attribute."""
# Find the cluster for this attribute. We don't have a lookup table yet.
cluster_cls: clusters.Cluster = next(
cluster
for cluster in device_type_instance.device_type.clusters
if cluster.id == attribute.cluster_id
)
# Find the attribute descriptor so we know the instance variable to fetch
attribute_descriptor: clusters.ClusterObjectFieldDescriptor = next(
descriptor
for descriptor in cluster_cls.descriptor.Fields
if descriptor.Tag == attribute.attribute_id
)
cluster_data = device_type_instance.get_cluster(cluster_cls)
return getattr(cluster_data, attribute_descriptor.Label)
@dataclass
class MatterSensorEntityDescriptionMixin:
"""Required fields for sensor device mapping."""