From d4c020b6753f8e87c6ca37868d03f237af68afdf Mon Sep 17 00:00:00 2001 From: Simon Engelhardt <360816+simonengelhardt@users.noreply.github.com> Date: Mon, 29 Aug 2022 21:14:12 +0200 Subject: [PATCH] Fix Tuya mc device support (#77346) Co-authored-by: Franck Nijhof --- homeassistant/components/tuya/binary_sensor.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tuya/binary_sensor.py b/homeassistant/components/tuya/binary_sensor.py index 5641a18022e..44d37050229 100644 --- a/homeassistant/components/tuya/binary_sensor.py +++ b/homeassistant/components/tuya/binary_sensor.py @@ -28,8 +28,8 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription): # DPCode, to use. If None, the key will be used as DPCode dpcode: DPCode | None = None - # Value to consider binary sensor to be "on" - on_value: bool | float | int | str = True + # Value or values to consider binary sensor to be "on" + on_value: bool | float | int | str | set[bool | float | int | str] = True # Commonly used sensors @@ -187,8 +187,9 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = { # https://developer.tuya.com/en/docs/iot/s?id=K9gf48r5zjsy9 "mc": ( TuyaBinarySensorEntityDescription( - key=DPCode.DOORCONTACT_STATE, + key=DPCode.STATUS, device_class=BinarySensorDeviceClass.DOOR, + on_value={"open", "opened"}, ), ), # Door Window Sensor @@ -393,4 +394,8 @@ class TuyaBinarySensorEntity(TuyaEntity, BinarySensorEntity): dpcode = self.entity_description.dpcode or self.entity_description.key if dpcode not in self.device.status: return False + + if isinstance(self.entity_description.on_value, set): + return self.device.status[dpcode] in self.entity_description.on_value + return self.device.status[dpcode] == self.entity_description.on_value