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 1 commit
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
86 changes: 86 additions & 0 deletions zhaquirks/sonoff/zbminir2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""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 CustomSonoffCluster(CustomCluster):
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
"""Custom Sonoff cluster."""

cluster_id = 0xFC11

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

ExternalTriggerMode = ZCLAttributeDef(
name="ExternalTriggerMode",
id=0x0016,
type=t.uint8_t,
)

DetachRelay = ZCLAttributeDef(
name="DetachRelay",
id=0x0017,
type=t.Bool,
)

TurboMode = ZCLAttributeDef(name="TurboMode", id=0x0012, type=t.int16s)
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved

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 41 in zhaquirks/sonoff/zbminir2.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/sonoff/zbminir2.py#L41

Added line #L41 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 50 in zhaquirks/sonoff/zbminir2.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/sonoff/zbminir2.py#L50

Added line #L50 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
pluse_trigger = 0x01
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
normally_off_follow_trigger = 0x02
normally_on_follow_trigger = 0x82


(
QuirkBuilder("SONOFF", "ZBMINIR2")
.replaces(CustomSonoffCluster)
.enum(
CustomSonoffCluster.AttributeDefs.ExternalTriggerMode.name,
SonoffExternalSwitchTriggerType,
CustomSonoffCluster.cluster_id,
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
fallback_name="External Trigger Mode",
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
)
.switch(
CustomSonoffCluster.AttributeDefs.TurboMode.name,
CustomSonoffCluster.cluster_id,
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
off_value=9,
on_value=20,
fallback_name="Turbo Mode",
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
)
.switch(
CustomSonoffCluster.AttributeDefs.DetachRelay.name,
CustomSonoffCluster.cluster_id,
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
off_value=0,
on_value=1,
fallback_name="Detach Relay",
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
)
.add_to_registry()
)
Loading