Skip to content
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

Add mode attribute to Aqara T1 relay #2823

Merged
merged 1 commit into from
Dec 23, 2023
Merged

Add mode attribute to Aqara T1 relay #2823

merged 1 commit into from
Dec 23, 2023

Conversation

dmulcahey
Copy link
Collaborator

@dmulcahey dmulcahey commented Dec 9, 2023

Proposed change

Add the mode attribute to the aqara T1 relay

TODO:

  • change mode to an enum?
  • add config entities to ZHA

Additional information

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works

Copy link

codecov bot commented Dec 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (aeca76d) 87.35% compared to head (33e1d3c) 87.35%.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #2823   +/-   ##
=======================================
  Coverage   87.35%   87.35%           
=======================================
  Files         287      287           
  Lines        8835     8835           
=======================================
  Hits         7718     7718           
  Misses       1117     1117           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheJulianJES
Copy link
Collaborator

change mode to an enum?

This mode/0x0009 attribute is only 0 ("ZCL mode") or 1 ("Aqara/Xiaomi hub mode"), so not like the mode attribute from your T2 relay PR (which should probably be renamed to switch_mode there).
Since this attribute isn't really meant to be user-accessible (ideally, it should auto-set to 1), I don't think we need to change it to an enum. If we do, we should probably change it in all quirks though.

It might make sense to change switch_type to an enum though (maybe that's also what you meant?). Just like done in opple_switch.py (scroll in code field below):

class OppleOperationMode(t.uint8_t, Enum):
"""Opple operation_mode enum."""
Decoupled = 0x00
Coupled = 0x01
class OppleSwitchMode(t.uint8_t, Enum):
"""Opple switch_mode enum."""
Fast = 0x01
Multi = 0x02
class OppleSwitchType(t.uint8_t, Enum):
"""Opple switch_type enum."""
Toggle = 0x01
Momentary = 0x02
class OppleIndicatorLight(t.uint8_t, Enum):
"""Opple indicator light enum."""
Normal = 0x00
Reverse = 0x01
class OppleSwitchCluster(OppleCluster):
"""Xiaomi mfg cluster implementation."""
attributes = copy.deepcopy(OppleCluster.attributes)
attributes.update(
{
0x0002: ("power_outage_count", t.uint8_t, True),
0x000A: ("switch_type", OppleSwitchType, True),
0x00F0: ("reverse_indicator_light", OppleIndicatorLight, True),
0x0125: ("switch_mode", OppleSwitchMode, True),
0x0200: ("operation_mode", OppleOperationMode, True),
0x0201: ("power_outage_memory", t.Bool, True),
0x0202: ("auto_off", t.Bool, True),
0x0203: ("do_not_disturb", t.Bool, True),
}
)

Maybe that implementation/enum can be used/shared if it's the same for this T1 relay.

@TheJulianJES
Copy link
Collaborator

Also, regarding "auto-setting" mode:

Although mode is likely only needed for old firmware versions of this relay, we could probably try to set it to 1 every time (when binding the cluster), since Z2M does it too. Like this:

attr_config = {0x0009: 0x01}

async def bind(self):
"""Bind cluster."""
result = await super().bind()
await self.write_attributes(self.attr_config, manufacturer=OPPLE_MFG_CODE)
return result

If that request errors out (when changing from 0 to 1), this might be needed instead zhaquirks/xiaomi/aqara/plug_eu.py#L65-L76, as it seems like that particular device briefly reboots (or something) and doesn't send back a response.

@dmulcahey
Copy link
Collaborator Author

Also, regarding "auto-setting" mode:

Although mode is likely only needed for old firmware versions of this relay, we could probably try to set it to 1 every time (when binding the cluster), since Z2M does it too. Like this:

attr_config = {0x0009: 0x01}

async def bind(self):
"""Bind cluster."""
result = await super().bind()
await self.write_attributes(self.attr_config, manufacturer=OPPLE_MFG_CODE)
return result

If that request errors out (when changing from 0 to 1), this might be needed instead zhaquirks/xiaomi/aqara/plug_eu.py#L65-L76, as it seems like that particular device briefly reboots (or something) and doesn't send back a response.

I debated doing this initially... the quirks work for multiple models and multiple fw differences... I didn't want to add this without more information. The goal was just to get the attribute there so we can set it from the UI and collect more info from users. thoughts?

@TheJulianJES
Copy link
Collaborator

I debated doing this initially... the quirks work for multiple models and multiple fw differences... I didn't want to add this without more information. The goal was just to get the attribute there so we can set it from the UI and collect more info from users. thoughts?

Yeah, let's not set it automatically for now then. I can't recall seeing any issues regarding this, so maybe everyone just uses a new firmware version on these.

@TheJulianJES TheJulianJES changed the title Add mode attribute to Aqara T1 relay Add mode attribute to Aqara T1 relay Dec 23, 2023
@TheJulianJES TheJulianJES merged commit 49b67d4 into dev Dec 23, 2023
14 checks passed
@TheJulianJES TheJulianJES deleted the dm/aqara_t1_mode branch December 23, 2023 19:52
elupus pushed a commit to elupus/zha-device-handlers that referenced this pull request Jan 17, 2024
lgraf pushed a commit to lgraf/zha-device-handlers that referenced this pull request May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants