Support Tuya cover with operation mach_operate (#62650)

This commit is contained in:
Marcus Lönnberg 2021-12-23 15:07:23 +01:00 committed by GitHub
parent 540ae4d10e
commit 1bbeaa722c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 6 deletions

View file

@ -206,6 +206,7 @@ class DPCode(str, Enum):
LIGHT = "light" # Light
LIGHT_MODE = "light_mode"
LOCK = "lock" # Lock / Child lock
MACH_OPERATE = "mach_operate"
MATERIAL = "material" # Material
MODE = "mode" # Working mode / Mode
MOTION_RECORD = "motion_record"
@ -221,6 +222,7 @@ class DPCode(str, Enum):
PERCENT_STATE = "percent_state"
PERCENT_STATE_2 = "percent_state_2"
PERCENT_STATE_3 = "percent_state_3"
POSITION = "position"
PHASE_A = "phase_a"
PHASE_B = "phase_b"
PHASE_C = "phase_c"

View file

@ -38,6 +38,9 @@ class TuyaCoverEntityDescription(CoverEntityDescription):
current_state_inverse: bool = False
current_position: DPCode | tuple[DPCode, ...] | None = None
set_position: DPCode | None = None
open_instruction_value: str = "open"
close_instruction_value: str = "close"
stop_instruction_value: str = "stop"
COVERS: dict[str, tuple[TuyaCoverEntityDescription, ...]] = {
@ -67,6 +70,16 @@ COVERS: dict[str, tuple[TuyaCoverEntityDescription, ...]] = {
set_position=DPCode.PERCENT_CONTROL_3,
device_class=CoverDeviceClass.CURTAIN,
),
TuyaCoverEntityDescription(
key=DPCode.MACH_OPERATE,
name="Curtain",
current_position=DPCode.POSITION,
set_position=DPCode.POSITION,
device_class=CoverDeviceClass.CURTAIN,
open_instruction_value="FZ",
close_instruction_value="ZZ",
stop_instruction_value="STOP",
),
# switch_1 is an undocumented code that behaves identically to control
# It is used by the Kogan Smart Blinds Driver
TuyaCoverEntityDescription(
@ -193,11 +206,11 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
self._attr_supported_features |= SUPPORT_OPEN | SUPPORT_CLOSE
elif device.function[description.key].type == "Enum":
data_type = EnumTypeData.from_json(device.function[description.key].values)
if "open" in data_type.range:
if description.open_instruction_value in data_type.range:
self._attr_supported_features |= SUPPORT_OPEN
if "close" in data_type.range:
if description.close_instruction_value in data_type.range:
self._attr_supported_features |= SUPPORT_CLOSE
if "stop" in data_type.range:
if description.stop_instruction_value in data_type.range:
self._attr_supported_features |= SUPPORT_STOP
# Determine type to use for setting the position
@ -309,7 +322,7 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
"""Open the cover."""
value: bool | str = True
if self.device.function[self.entity_description.key].type == "Enum":
value = "open"
value = self.entity_description.open_instruction_value
commands: list[dict[str, str | int]] = [
{"code": self.entity_description.key, "value": value}
@ -336,7 +349,7 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
"""Close cover."""
value: bool | str = False
if self.device.function[self.entity_description.key].type == "Enum":
value = "close"
value = self.entity_description.close_instruction_value
commands: list[dict[str, str | int]] = [
{"code": self.entity_description.key, "value": value}
@ -381,7 +394,14 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
def stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
self._send_command([{"code": self.entity_description.key, "value": "stop"}])
self._send_command(
[
{
"code": self.entity_description.key,
"value": self.entity_description.stop_instruction_value,
}
]
)
def set_cover_tilt_position(self, **kwargs):
"""Move the cover tilt to a specific position."""