Bug report
Description
WXKG11LMSensorSwitchLightController.get_zha_action() misidentifies plain on_off attribute reports as a "single" click, because it doesn't filter by attribute_id before applying its click-count mapping, and Python's True == 1 causes the boolean on_off value to match the 1: "single" mapping entry.
Expected behaviour: only the device's dedicated click-count attribute (attribute_id: 32768) should determine the action (single/double/triple/quadruple).
Observed behaviour: the device also fires plain on_off attribute-report events (attribute_id: 0, value: True) as a side effect of the physical button contact, on every press regardless of click count. get_zha_action reads data["args"]["value"] from these events too, without checking attribute_id:
# apps/controllerx/cx_devices/aqara.py
def get_zha_action(self, data: EventData) -> str:
mapping = {
1: "single",
2: "double",
3: "triple",
4: "quadruple",
}
clicks = data["args"]["value"]
return mapping.get(clicks, "")
Since True == 1 in Python, mapping.get(True, "") matches key 1 and returns "single". This spurious "single" action fires alongside (and races against) the real click-count action from the attribute_id: 32768 event, so a double- or triple-click intermittently ends up executing the single action's result instead, depending on which event's action handler finishes last.
ZHAIntegration.event_callback calls get_zha_action for every zha_event from the device (filtered only by device_ieee), so nothing upstream of this function filters out the unrelated on_off events either:
# apps/controllerx/cx_core/integration/zha.py
async def event_callback(self, event_name, data, kwargs):
action = self.controller.get_zha_action(data)
...
Steps to reproduce
- Pair a
lumi.sensor_switch.aq2 (Aqara WXKG11LM) via ZHA.
- Configure
WXKG11LMSensorSwitchLightController with distinct actions mapped to single and double/triple/quadruple.
- In Developer Tools → Events, listen to
zha_event and physically double- or triple-click the switch.
- Observe both an
attribute_id: 0 (on_off) event and an attribute_id: 32768 event firing for the same physical action.
- Observe the light lands in the state associated with the
single action, even on a double/triple click.
Suggested fix
def get_zha_action(self, data: EventData) -> str:
args = data.get("args", {})
if args.get("attribute_id") != 32768:
return ""
mapping = {
1: "single",
2: "double",
3: "triple",
4: "quadruple",
}
return mapping.get(args.get("value"), "")
(A more general guard against the True == 1 issue — if not isinstance(clicks, int) or isinstance(clicks, bool): return "" — would also help any other controller with a similarly-structured mapping.)
Additional information
- Devices involved:
- Model: Aqara WXKG11LM (
lumi.sensor_switch.aq2, ZHA quirk zhaquirks.xiaomi.aqara.switch_aq2:SwitchAQ2) as Controller
- Model: generic dimmable light as
Light
- Integration:
zha
- AppDaemon version: 0.18.5
- ControllerX version: v5.2.3
- HACS version (if installed
Bug report
Description
WXKG11LMSensorSwitchLightController.get_zha_action()misidentifies plainon_offattribute reports as a "single" click, because it doesn't filter byattribute_idbefore applying its click-count mapping, and Python'sTrue == 1causes the booleanon_offvalue to match the1: "single"mapping entry.Expected behaviour: only the device's dedicated click-count attribute (
attribute_id: 32768) should determine the action (single/double/triple/quadruple).Observed behaviour: the device also fires plain
on_offattribute-report events (attribute_id: 0,value: True) as a side effect of the physical button contact, on every press regardless of click count.get_zha_actionreadsdata["args"]["value"]from these events too, without checkingattribute_id:Since
True == 1in Python,mapping.get(True, "")matches key1and returns"single". This spurious"single"action fires alongside (and races against) the real click-count action from theattribute_id: 32768event, so a double- or triple-click intermittently ends up executing thesingleaction's result instead, depending on which event's action handler finishes last.ZHAIntegration.event_callbackcallsget_zha_actionfor everyzha_eventfrom the device (filtered only bydevice_ieee), so nothing upstream of this function filters out the unrelatedon_offevents either:Steps to reproduce
lumi.sensor_switch.aq2(Aqara WXKG11LM) via ZHA.WXKG11LMSensorSwitchLightControllerwith distinct actions mapped tosingleanddouble/triple/quadruple.zha_eventand physically double- or triple-click the switch.attribute_id: 0(on_off) event and anattribute_id: 32768event firing for the same physical action.singleaction, even on a double/triple click.Suggested fix
(A more general guard against the
True == 1issue —if not isinstance(clicks, int) or isinstance(clicks, bool): return ""— would also help any other controller with a similarly-structured mapping.)Additional information
lumi.sensor_switch.aq2, ZHA quirkzhaquirks.xiaomi.aqara.switch_aq2:SwitchAQ2) asControllerLightzha