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 quirk for Sonoff ZBMINIR2 #3428

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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
88 changes: 88 additions & 0 deletions zhaquirks/sonoff/zbminir2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""Sonoff ZBMINIR2 - Zigbee Switch."""

from zigpy import types
from zigpy.quirks import CustomCluster
from zigpy.quirks.v2 import QuirkBuilder
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef


class SonoffCluster(CustomCluster):
"""Custom Sonoff cluster."""

cluster_id = 0xFC11

class AttributeDefs(BaseAttributeDefs):
"""Attribute definitions."""

external_trigger_mode = ZCLAttributeDef(
id=0x0016,
type=t.uint8_t,
)
detach_relay = ZCLAttributeDef(
id=0x0017,
type=t.Bool,
)
turbo_mode = ZCLAttributeDef(
id=0x0012,
type=t.int16s,
)

async def _read_attributes(
self,
attribute_ids: list[t.uint16_t],
*args,
manufacturer: int | t.uint16_t | None = None,
**kwargs,
):
"""Read attributes ZCL foundation command."""
return await super()._read_attributes(

Check warning on line 40 in zhaquirks/sonoff/zbminir2.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/sonoff/zbminir2.py#L40

Added line #L40 was not covered by tests
attribute_ids,
*args,
manufacturer=foundation.ZCLHeader.NO_MANUFACTURER_ID,
**kwargs,
)

@property
def _is_manuf_specific(self):
return False

Check warning on line 49 in zhaquirks/sonoff/zbminir2.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/sonoff/zbminir2.py#L49

Added line #L49 was not covered by tests
Comment on lines +32 to +49
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, in the future, we should have a better solution for this, so we don't need to duplicate it across all quirks.



class SonoffExternalSwitchTriggerType(types.enum8):
"""extern switch trigger type."""

edge_trigger = 0x00
pulse_trigger = 0x01
normally_off_follow_trigger = 0x02
normally_on_follow_trigger = 0x82
Comment on lines +55 to +58
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to check which naming convention we want to use here.
Other possibilities include: EdgeTrigger, Edge_Trigger, and Edge_trigger.



(
QuirkBuilder("SONOFF", "ZBMINIR2")
.replaces(SonoffCluster)
.enum(
SonoffCluster.AttributeDefs.external_trigger_mode.name,
SonoffExternalSwitchTriggerType,
SonoffCluster.cluster_id,
translation_key="external_trigger_mode",
fallback_name="External trigger mode",
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
)
.switch(
SonoffCluster.AttributeDefs.turbo_mode.name,
SonoffCluster.cluster_id,
off_value=9,
on_value=20,
translation_key="turbo_mode",
fallback_name="Turbo mode",
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
)
.switch(
SonoffCluster.AttributeDefs.detach_relay.name,
SonoffCluster.cluster_id,
off_value=0,
on_value=1,
translation_key="detach_relay",
fallback_name="Detach relay",
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
)
.add_to_registry()
)