Indentify IKEA and Phillips motion sensors correctly (#41111)

This commit is contained in:
Abílio Costa 2020-10-04 00:52:21 +01:00 committed by GitHub
parent a73daa5f20
commit 4aacc87425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -143,6 +143,25 @@ class Opening(BinarySensor):
DEVICE_CLASS = DEVICE_CLASS_OPENING
@STRICT_MATCH(
channel_names=CHANNEL_ON_OFF,
manufacturers="IKEA of Sweden",
models=lambda model: isinstance(model, str)
and model is not None
and model.find("motion") != -1,
)
@STRICT_MATCH(
channel_names=CHANNEL_ON_OFF,
manufacturers="Philips",
models={"SML001", "SML002"},
)
class Motion(BinarySensor):
"""ZHA BinarySensor."""
SENSOR_ATTR = "on_off"
DEVICE_CLASS = DEVICE_CLASS_MOTION
@STRICT_MATCH(channel_names=CHANNEL_ZONE)
class IASZone(BinarySensor):
"""ZHA IAS BinarySensor."""

View File

@ -180,10 +180,12 @@ class MatchRule:
"""
weight = 0
if self.models:
weight += 401 - len(self.models)
weight += 401 - (1 if callable(self.models) else len(self.models))
if self.manufacturers:
weight += 301 - len(self.manufacturers)
weight += 301 - (
1 if callable(self.manufacturers) else len(self.manufacturers)
)
weight += 10 * len(self.channel_names)
weight += 5 * len(self.generic_ids)

View File

@ -784,7 +784,7 @@ DEVICES = [
},
("binary_sensor", "00:11:22:33:44:55:66:77-1-6"): {
"channels": ["on_off"],
"entity_class": "Opening",
"entity_class": "Motion",
"entity_id": "binary_sensor.ikea_of_sweden_tradfri_motion_sensor_77665544_on_off",
},
},