Support Tuya cover with operation mach_operate (#62650)
This commit is contained in:
parent
540ae4d10e
commit
1bbeaa722c
2 changed files with 28 additions and 6 deletions
|
@ -206,6 +206,7 @@ class DPCode(str, Enum):
|
||||||
LIGHT = "light" # Light
|
LIGHT = "light" # Light
|
||||||
LIGHT_MODE = "light_mode"
|
LIGHT_MODE = "light_mode"
|
||||||
LOCK = "lock" # Lock / Child lock
|
LOCK = "lock" # Lock / Child lock
|
||||||
|
MACH_OPERATE = "mach_operate"
|
||||||
MATERIAL = "material" # Material
|
MATERIAL = "material" # Material
|
||||||
MODE = "mode" # Working mode / Mode
|
MODE = "mode" # Working mode / Mode
|
||||||
MOTION_RECORD = "motion_record"
|
MOTION_RECORD = "motion_record"
|
||||||
|
@ -221,6 +222,7 @@ class DPCode(str, Enum):
|
||||||
PERCENT_STATE = "percent_state"
|
PERCENT_STATE = "percent_state"
|
||||||
PERCENT_STATE_2 = "percent_state_2"
|
PERCENT_STATE_2 = "percent_state_2"
|
||||||
PERCENT_STATE_3 = "percent_state_3"
|
PERCENT_STATE_3 = "percent_state_3"
|
||||||
|
POSITION = "position"
|
||||||
PHASE_A = "phase_a"
|
PHASE_A = "phase_a"
|
||||||
PHASE_B = "phase_b"
|
PHASE_B = "phase_b"
|
||||||
PHASE_C = "phase_c"
|
PHASE_C = "phase_c"
|
||||||
|
|
|
@ -38,6 +38,9 @@ class TuyaCoverEntityDescription(CoverEntityDescription):
|
||||||
current_state_inverse: bool = False
|
current_state_inverse: bool = False
|
||||||
current_position: DPCode | tuple[DPCode, ...] | None = None
|
current_position: DPCode | tuple[DPCode, ...] | None = None
|
||||||
set_position: 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, ...]] = {
|
COVERS: dict[str, tuple[TuyaCoverEntityDescription, ...]] = {
|
||||||
|
@ -67,6 +70,16 @@ COVERS: dict[str, tuple[TuyaCoverEntityDescription, ...]] = {
|
||||||
set_position=DPCode.PERCENT_CONTROL_3,
|
set_position=DPCode.PERCENT_CONTROL_3,
|
||||||
device_class=CoverDeviceClass.CURTAIN,
|
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
|
# switch_1 is an undocumented code that behaves identically to control
|
||||||
# It is used by the Kogan Smart Blinds Driver
|
# It is used by the Kogan Smart Blinds Driver
|
||||||
TuyaCoverEntityDescription(
|
TuyaCoverEntityDescription(
|
||||||
|
@ -193,11 +206,11 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
|
||||||
self._attr_supported_features |= SUPPORT_OPEN | SUPPORT_CLOSE
|
self._attr_supported_features |= SUPPORT_OPEN | SUPPORT_CLOSE
|
||||||
elif device.function[description.key].type == "Enum":
|
elif device.function[description.key].type == "Enum":
|
||||||
data_type = EnumTypeData.from_json(device.function[description.key].values)
|
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
|
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
|
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
|
self._attr_supported_features |= SUPPORT_STOP
|
||||||
|
|
||||||
# Determine type to use for setting the position
|
# Determine type to use for setting the position
|
||||||
|
@ -309,7 +322,7 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
|
||||||
"""Open the cover."""
|
"""Open the cover."""
|
||||||
value: bool | str = True
|
value: bool | str = True
|
||||||
if self.device.function[self.entity_description.key].type == "Enum":
|
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]] = [
|
commands: list[dict[str, str | int]] = [
|
||||||
{"code": self.entity_description.key, "value": value}
|
{"code": self.entity_description.key, "value": value}
|
||||||
|
@ -336,7 +349,7 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
|
||||||
"""Close cover."""
|
"""Close cover."""
|
||||||
value: bool | str = False
|
value: bool | str = False
|
||||||
if self.device.function[self.entity_description.key].type == "Enum":
|
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]] = [
|
commands: list[dict[str, str | int]] = [
|
||||||
{"code": self.entity_description.key, "value": value}
|
{"code": self.entity_description.key, "value": value}
|
||||||
|
@ -381,7 +394,14 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
|
||||||
|
|
||||||
def stop_cover(self, **kwargs: Any) -> None:
|
def stop_cover(self, **kwargs: Any) -> None:
|
||||||
"""Stop the cover."""
|
"""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):
|
def set_cover_tilt_position(self, **kwargs):
|
||||||
"""Move the cover tilt to a specific position."""
|
"""Move the cover tilt to a specific position."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue