Fix inverted tuya doorcontact_state (#59427)

This commit is contained in:
Yehuda Davis 2021-11-13 08:30:47 -05:00 committed by GitHub
parent b2f2c76e5a
commit b5de99ebfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View file

@ -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

View file

@ -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