Skip to content

Add Aqara Z1 Pro Light Switch Quirk #4043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions zhaquirks/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
import zigpy.types as t

ACTION = "action"
ARGS = "args"
ATTR_ID = "attr_id"
ATTRIBUTE_ID = "attribute_id"
Expand Down Expand Up @@ -73,6 +74,7 @@
COMMAND_TILT = "Tilt"
COMMAND_TOGGLE = "toggle"
COMMAND_TRIPLE = "triple"
COMMAND_SLIDER_EVENT = "slider_event"
DESCRIPTION = "description"
DEVICE_TYPE = SIG_EP_TYPE
DIM_DOWN = "dim_down"
Expand Down Expand Up @@ -116,9 +118,15 @@
SKIP_CONFIGURATION = SIG_SKIP_CONFIG
SHORT_RELEASE = "remote_button_short_release"
TOGGLE = "toggle"
SLIDER = "slider"
TRIPLE_PRESS = "remote_button_triple_press"
TURN_OFF = "turn_off"
TURN_ON = "turn_on"
SLIDER_SINGLE = "slider_single"
SLIDER_DOUBLE = "slider_double"
SLIDER_HOLD = "slider_hold"
SLIDER_UP = "slider_up"
SLIDER_DOWN = "slider_down"
UNKNOWN = "Unknown"
VALUE = "value"
ZHA_SEND_EVENT = "zha_send_event"
Expand Down
106 changes: 106 additions & 0 deletions zhaquirks/xiaomi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@
ATTRIBUTE_ID,
ATTRIBUTE_NAME,
COMMAND_ATTRIBUTE_UPDATED,
COMMAND_SLIDER_EVENT,
COMMAND_TRIPLE,
SLIDER_DOUBLE,
SLIDER_DOWN,
SLIDER_HOLD,
SLIDER_SINGLE,
SLIDER_UP,
UNKNOWN,
VALUE,
ZHA_SEND_EVENT,
Expand Down Expand Up @@ -733,6 +739,106 @@
)


class AqaraZ1ProManufacturerSpecificCluster(CustomCluster):
"""Custom cluster for Aqara Z1 Pro manufacturer specific events."""

cluster_id = 0xFCC0

# Attribute IDs
ATTR_SLIDER_ACTION = 0x028C # 652
ATTR_SLIDE_TIME = 0x0231 # 561
ATTR_SLIDE_SPEED = 0x0232 # 562
ATTR_SLIDE_RELATIVE_DISPLACEMENT = 0x0233 # 563
ATTR_SLIDE_TIME_DELTA = 0x0301 # 769

# ATTR_DEVICE_ID_SHADE = 0x0200 # 512
# ATTR_LOCK_RELAY = 0x0285 # 645
# ATTR_SWITCH_MODE = 0x0004 # 4
# ATTR_POWER_ON_BEHAVIOR = 0x0517 # 1303
# ATTR_CLICK_MODE = 0x0125 # 293

# Action mapping
ACTION_MAPPING = {
1: SLIDER_SINGLE,
2: SLIDER_DOUBLE,
3: SLIDER_HOLD,
4: SLIDER_UP,
5: SLIDER_DOWN,
}

def __init__(self, *args, **kwargs):
"""Init."""
super().__init__(*args, **kwargs)
self._attr_id = self.ATTR_SLIDER_ACTION
_LOGGER.debug(

Check warning on line 773 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L771-L773

Added lines #L771 - L773 were not covered by tests
"AqaraZ1ProManufacturerSpecificCluster initialized for device %s",
self._endpoint.device.ieee,
)

def _update_attribute(self, attrid, value):
"""Handle attribute updates."""

# Store all attributes for the event
if not hasattr(self, "_manufacturer_attrs"):
self._manufacturer_attrs = {}

Check warning on line 783 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L782-L783

Added lines #L782 - L783 were not covered by tests

# Update the attribute value
self._manufacturer_attrs[attrid] = value

Check warning on line 786 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L786

Added line #L786 was not covered by tests

# If this is the slider action attribute, send the event
if attrid == self.ATTR_SLIDER_ACTION:

Check warning on line 789 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L789

Added line #L789 was not covered by tests
# Get the action name from the mapping
action = self.ACTION_MAPPING.get(value, f"slider_unknown_{value}")
_LOGGER.debug(

Check warning on line 792 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L791-L792

Added lines #L791 - L792 were not covered by tests
"AqaraZ1ProManufacturerSpecificCluster detected action: %s (value: %s)",
action,
value,
)

# Prepare the event data
event_data = {

Check warning on line 799 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L799

Added line #L799 was not covered by tests
"action": action,
"value": value,
"slide_time": self._manufacturer_attrs.get(self.ATTR_SLIDE_TIME),
"slide_speed": self._manufacturer_attrs.get(self.ATTR_SLIDE_SPEED),
"slide_relative_displacement": self._manufacturer_attrs.get(
self.ATTR_SLIDE_RELATIVE_DISPLACEMENT
),
"slide_time_delta": self._manufacturer_attrs.get(
self.ATTR_SLIDE_TIME_DELTA
),
}

_LOGGER.debug(

Check warning on line 812 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L812

Added line #L812 was not covered by tests
"AqaraZ1ProManufacturerSpecificCluster sending event data: %s",
event_data,
)

# Send the event
self.listener_event(

Check warning on line 818 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L818

Added line #L818 was not covered by tests
ZHA_SEND_EVENT,
action,
event_data,
)

# Also send a generic slider event for easier automation
self.listener_event(

Check warning on line 825 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L825

Added line #L825 was not covered by tests
ZHA_SEND_EVENT,
COMMAND_SLIDER_EVENT,
event_data,
)
_LOGGER.debug(

Check warning on line 830 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L830

Added line #L830 was not covered by tests
"AqaraZ1ProManufacturerSpecificCluster events sent successfully"
)

_LOGGER.debug(

Check warning on line 834 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L834

Added line #L834 was not covered by tests
"AqaraZ1ProManufacturerSpecificCluster attribute update: attrid=0x%04x, value=%s",
attrid,
value,
)
super()._update_attribute(attrid, value)

Check warning on line 839 in zhaquirks/xiaomi/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/__init__.py#L839

Added line #L839 was not covered by tests


def handle_quick_init(
sender: zigpy.device.Device,
profile: int,
Expand Down
Loading
Loading