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

Merged
merged 9 commits into from
Nov 24, 2024
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):
"""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)

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's possible that zigpy/zigpy#1505 can clean this up?



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

edge_trigger = 0x00
pluse_trigger = 0x01
normally_off_follow_trigger = 0x02
normally_on_follow_trigger = 0x82


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