Skip to content

Commit

Permalink
Set key to device type
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Jun 27, 2022
1 parent 1911829 commit 8dcf0ac
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion custom_components/matter_experimental/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,20 @@ class MatterBinarySensorEntityDescription(

# You can't set default values on inherited data classes
MatterSensorEntityDescriptionFactory = partial(
MatterBinarySensorEntityDescription, key=None, entity_cls=MatterBinarySensor
MatterBinarySensorEntityDescription, entity_cls=MatterBinarySensor
)

DEVICE_ENTITY: dict[
type[device_types.DeviceType],
MatterEntityDescription | list[MatterEntityDescription],
] = {
device_types.ContactSensor: MatterSensorEntityDescriptionFactory(
key=device_types.ContactSensor,
subscribe_attributes=(clusters.BooleanState.Attributes.StateValue,),
device_class=BinarySensorDeviceClass.DOOR,
),
device_types.OccupancySensor: MatterSensorEntityDescriptionFactory(
key=device_types.OccupancySensor,
entity_cls=MatterOccupancySensor,
subscribe_attributes=(clusters.OccupancySensing.Attributes.Occupancy,),
),
Expand Down
5 changes: 4 additions & 1 deletion custom_components/matter_experimental/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class MatterLightEntityDescription(

# You can't set default values on inherited data classes
MatterLightEntityDescriptionFactory = partial(
MatterLightEntityDescription, key=None, entity_cls=MatterLight
MatterLightEntityDescription, entity_cls=MatterLight
)


Expand All @@ -120,15 +120,18 @@ class MatterLightEntityDescription(
MatterEntityDescription | list[MatterEntityDescription],
] = {
device_types.OnOffLight: MatterLightEntityDescriptionFactory(
key=device_types.OnOffLight,
subscribe_attributes=(clusters.OnOff.Attributes.OnOff,),
),
device_types.DimmableLight: MatterLightEntityDescriptionFactory(
key=device_types.DimmableLight,
subscribe_attributes=(
clusters.OnOff.Attributes.OnOff,
clusters.LevelControl.Attributes.CurrentLevel,
),
),
device_types.DimmablePlugInUnit: MatterLightEntityDescriptionFactory(
key=device_types.DimmablePlugInUnit,
subscribe_attributes=(
clusters.OnOff.Attributes.OnOff,
clusters.LevelControl.Attributes.CurrentLevel,
Expand Down
7 changes: 6 additions & 1 deletion custom_components/matter_experimental/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class MatterSensorEntityDescription(

# You can't set default values on inherited data classes
MatterSensorEntityDescriptionFactory = partial(
MatterSensorEntityDescription, key=None, entity_cls=MatterSensor
MatterSensorEntityDescription, entity_cls=MatterSensor
)


Expand All @@ -118,6 +118,7 @@ class MatterSensorEntityDescription(
MatterEntityDescription | list[MatterEntityDescription],
] = {
device_types.TemperatureSensor: MatterSensorEntityDescriptionFactory(
key=device_types.TemperatureSensor,
measurement_to_ha=lambda x: x / 100,
subscribe_attributes=(
clusters.TemperatureMeasurement.Attributes.MeasuredValue,
Expand All @@ -126,17 +127,20 @@ class MatterSensorEntityDescription(
device_class=SensorDeviceClass.TEMPERATURE,
),
device_types.PressureSensor: MatterSensorEntityDescriptionFactory(
key=device_types.PressureSensor,
measurement_to_ha=lambda x: x / 10,
subscribe_attributes=(clusters.PressureMeasurement.Attributes.MeasuredValue,),
native_unit_of_measurement=PRESSURE_KPA,
device_class=SensorDeviceClass.PRESSURE,
),
device_types.FlowSensor: MatterSensorEntityDescriptionFactory(
key=device_types.FlowSensor,
measurement_to_ha=lambda x: x / 10,
subscribe_attributes=(clusters.FlowMeasurement.Attributes.MeasuredValue,),
native_unit_of_measurement=VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
),
device_types.HumiditySensor: MatterSensorEntityDescriptionFactory(
key=device_types.HumiditySensor,
measurement_to_ha=lambda x: x / 100,
subscribe_attributes=(
clusters.RelativeHumidityMeasurement.Attributes.MeasuredValue,
Expand All @@ -145,6 +149,7 @@ class MatterSensorEntityDescription(
device_class=SensorDeviceClass.HUMIDITY,
),
device_types.LightSensor: MatterSensorEntityDescriptionFactory(
key=device_types.LightSensor,
measurement_to_ha=lambda x: round(pow(10, ((x - 1) / 10000)), 1),
subscribe_attributes=(
clusters.IlluminanceMeasurement.Attributes.MeasuredValue,
Expand Down
3 changes: 2 additions & 1 deletion custom_components/matter_experimental/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MatterSwitchEntityDescription(

# You can't set default values on inherited data classes
MatterSwitchEntityDescriptionFactory = partial(
MatterSwitchEntityDescription, key=None, entity_cls=MatterSwitch
MatterSwitchEntityDescription, entity_cls=MatterSwitch
)


Expand All @@ -78,6 +78,7 @@ class MatterSwitchEntityDescription(
MatterEntityDescription | list[MatterEntityDescription],
] = {
device_types.OnOffPlugInUnit: MatterSwitchEntityDescriptionFactory(
key=device_types.OnOffPlugInUnit,
subscribe_attributes=(clusters.OnOff.Attributes.OnOff,),
device_class=SwitchDeviceClass.OUTLET,
),
Expand Down

0 comments on commit 8dcf0ac

Please sign in to comment.