diff --git a/homeassistant/components/zha/binary_sensor.py b/homeassistant/components/zha/binary_sensor.py index 2548060c0fd..ba95a0e4bc6 100644 --- a/homeassistant/components/zha/binary_sensor.py +++ b/homeassistant/components/zha/binary_sensor.py @@ -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.""" diff --git a/homeassistant/components/zha/core/registries.py b/homeassistant/components/zha/core/registries.py index 0cc350ba4b8..81521748da0 100644 --- a/homeassistant/components/zha/core/registries.py +++ b/homeassistant/components/zha/core/registries.py @@ -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) diff --git a/tests/components/zha/zha_devices_list.py b/tests/components/zha/zha_devices_list.py index 6de4bd79a72..e33cb48778c 100644 --- a/tests/components/zha/zha_devices_list.py +++ b/tests/components/zha/zha_devices_list.py @@ -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", }, },