Skip to content

Commit

Permalink
Refactor NoManufacturerCluster classes (#1572)
Browse files Browse the repository at this point in the history
* Refactor NO_MANUFACTURER_ID classes

* Refactor NO_MANUFACTURER_ID classes

* Fix flake8 coverage
  • Loading branch information
javicalle committed May 23, 2022
1 parent 6ac6164 commit dab4d44
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 36 deletions.
1 change: 0 additions & 1 deletion zhaquirks/tuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ class TuyaCommand(t.Struct):
data: TuyaData


# based on https://github.com/zigpy/zha-device-handlers/blob/b802c1fb2cf2682f9a4722bfb57a1958cad9dad7/zhaquirks/tuya/ts0601_dimmer.py#L26
class NoManufacturerCluster(CustomCluster):
"""Forces the NO manufacturer id in command."""

Expand Down
1 change: 0 additions & 1 deletion zhaquirks/tuya/mcu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ async def command(
].schema(command_id=command_id, status=foundation.Status.UNSUP_CLUSTER_COMMAND)


# based on https://github.com/zigpy/zha-device-handlers/blob/b802c1fb2cf2682f9a4722bfb57a1958cad9dad7/zhaquirks/tuya/ts0601_dimmer.py#L48
class TuyaOnOffNM(NoManufacturerCluster, TuyaOnOff):
"""Tuya OnOff cluster with NoManufacturerID."""

Expand Down
36 changes: 2 additions & 34 deletions zhaquirks/tuya/ts0601_dimmer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
"""Tuya based touch switch."""
from typing import Optional, Union

from zigpy.profiles import zha
from zigpy.quirks import CustomCluster
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import Basic, GreenPowerProxy, Groups, Ota, Scenes, Time

from zhaquirks.const import (
Expand All @@ -15,42 +10,15 @@
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.tuya import TuyaDimmerSwitch
from zhaquirks.tuya import NoManufacturerCluster, TuyaDimmerSwitch
from zhaquirks.tuya.mcu import (
TuyaInWallLevelControl,
TuyaLevelControlManufCluster,
TuyaOnOff,
TuyaOnOffNM,
)


class NoManufacturerCluster(CustomCluster):
"""Forces the NO manufacturer id in command."""

async def command(
self,
command_id: Union[foundation.GeneralCommand, int, t.uint8_t],
*args,
manufacturer: Optional[Union[int, t.uint16_t]] = None,
expect_reply: bool = True,
tsn: Optional[Union[int, t.uint8_t]] = None,
):
"""Override the default Cluster command."""
self.debug("Setting the NO manufacturer id in command: %s", command_id)
return await super().command(
command_id,
*args,
manufacturer=foundation.ZCLHeader.NO_MANUFACTURER_ID,
expect_reply=expect_reply,
tsn=tsn,
)


class TuyaOnOffNM(NoManufacturerCluster, TuyaOnOff):
"""Tuya OnOff cluster with NoManufacturerID."""

pass


class TuyaInWallLevelControlNM(NoManufacturerCluster, TuyaInWallLevelControl):
"""Tuya Level cluster for inwall dimmable device with NoManufacturerID."""

Expand Down

0 comments on commit dab4d44

Please sign in to comment.