From b5de99ebfcb3b9f641c812892b3637d5baf6d13c Mon Sep 17 00:00:00 2001 From: Yehuda Davis Date: Sat, 13 Nov 2021 08:30:47 -0500 Subject: [PATCH] Fix inverted tuya doorcontact_state (#59427) --- homeassistant/components/tuya/const.py | 2 +- homeassistant/components/tuya/cover.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index a9f7afb0ec5..f0707b1b37a 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -190,7 +190,7 @@ class DPCode(str, Enum): DEHUMIDITY_SET_VALUE = "dehumidify_set_value" DO_NOT_DISTURB = "do_not_disturb" DOORCONTACT_STATE = "doorcontact_state" # Status of door window sensor - DOORCONTACT_STATE_2 = "doorcontact_state_3" + DOORCONTACT_STATE_2 = "doorcontact_state_2" DOORCONTACT_STATE_3 = "doorcontact_state_3" ELECTRICITY_LEFT = "electricity_left" FAN_DIRECTION = "fan_direction" # Fan direction diff --git a/homeassistant/components/tuya/cover.py b/homeassistant/components/tuya/cover.py index 0b8a658fd7c..b5ac5645cd2 100644 --- a/homeassistant/components/tuya/cover.py +++ b/homeassistant/components/tuya/cover.py @@ -36,6 +36,7 @@ class TuyaCoverEntityDescription(CoverEntityDescription): """Describe an Tuya cover entity.""" current_state: DPCode | None = None + current_state_inverse: bool = False current_position: DPCode | None = None set_position: DPCode | None = None @@ -75,18 +76,21 @@ COVERS: dict[str, tuple[TuyaCoverEntityDescription, ...]] = { key=DPCode.SWITCH_1, name="Door", current_state=DPCode.DOORCONTACT_STATE, + current_state_inverse=True, device_class=DEVICE_CLASS_GARAGE, ), TuyaCoverEntityDescription( key=DPCode.SWITCH_2, name="Door 2", current_state=DPCode.DOORCONTACT_STATE_2, + current_state_inverse=True, device_class=DEVICE_CLASS_GARAGE, ), TuyaCoverEntityDescription( key=DPCode.SWITCH_3, name="Door 3", current_state=DPCode.DOORCONTACT_STATE_3, + current_state_inverse=True, device_class=DEVICE_CLASS_GARAGE, ), ), @@ -262,7 +266,7 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity): @property def is_closed(self) -> bool | None: - """Return is cover is closed.""" + """Return true if cover is closed.""" if ( self.entity_description.current_state is not None and ( @@ -272,7 +276,9 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity): ) is not None ): - return current_state in (True, "fully_close") + return self.entity_description.current_state_inverse is not ( + current_state in (False, "fully_close") + ) if (position := self.current_cover_position) is not None: return position == 0