-
Notifications
You must be signed in to change notification settings - Fork 670
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
Improve Legrand 064882 cable outlet heat mode #3031
Draft
piitaya
wants to merge
27
commits into
zigpy:dev
Choose a base branch
from
piitaya:heat_mode_legrand_outlet
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2cd60fe
Fix heat mode for legrand outlet
piitaya b83fbdd
Use AttributeDefs and ServerCommandDefs
piitaya 114f27c
Add tests
piitaya 1f7b88a
Fix name
piitaya 50ac382
Update case for enum
piitaya 13b13cc
Use quirk v2
piitaya 6d82c18
Add entity
piitaya f2176fb
Update test to use v2 quirks
piitaya 1565967
Merge branch 'dev' into heat_mode_legrand_outlet
piitaya 261a4b1
Format code
piitaya 973a072
Add climate entity
piitaya cfe94ba
Add enum back
piitaya 7720212
Use attributes def and don't use bus
piitaya 25875ca
Remove thermostat
piitaya 5adb0d6
Remove enum
piitaya be6bbfc
Add device mode
piitaya 033a90c
Remove init
piitaya 6f2f1e4
Add write device mode test
piitaya 7523f37
Rename cable outlet to wire pilot
piitaya 52584ad
Add thermostat with heat_mode attribute
piitaya 8003a14
Add thermostat system mode
piitaya 5664eb7
Remove unreachable code
piitaya 9518cbd
Improve test coverage
piitaya c1d541b
Add update attrs tests
piitaya f452498
Remove thermostat cluster
piitaya 9fca2ac
Use attribute def
piitaya 144fe4c
Use attribute def
piitaya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
"""Module for Legrand Cable Outlet with pilot wire functionality.""" | ||
|
||
from zigpy.quirks import CustomCluster | ||
from zigpy.quirks.v2 import add_to_registry_v2 | ||
import zigpy.types as t | ||
from zigpy.zcl import ClusterType | ||
from zigpy.zcl.foundation import ( | ||
BaseAttributeDefs, | ||
BaseCommandDefs, | ||
Direction, | ||
ZCLAttributeDef, | ||
ZCLCommandDef, | ||
) | ||
|
||
from zhaquirks.legrand import LEGRAND, MANUFACTURER_SPECIFIC_CLUSTER_ID | ||
|
||
MANUFACTURER_SPECIFIC_CLUSTER_ID_2 = 0xFC40 # 64576 | ||
|
||
|
||
class LegrandCluster(CustomCluster): | ||
"""LegrandCluster.""" | ||
|
||
cluster_id = MANUFACTURER_SPECIFIC_CLUSTER_ID | ||
name = "LegrandCluster" | ||
ep_attribute = "legrand_cluster" | ||
|
||
class AttributeDefs(BaseAttributeDefs): | ||
"""Attribute definitions.""" | ||
|
||
device_mode = ZCLAttributeDef( | ||
id=0x0000, | ||
type=t.data16, | ||
is_manufacturer_specific=True, | ||
) | ||
led_dark = ZCLAttributeDef( | ||
id=0x0001, | ||
type=t.Bool, | ||
is_manufacturer_specific=True, | ||
) | ||
led_on = ZCLAttributeDef( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add a switch config entity for this to the quirk below? |
||
id=0x0002, | ||
type=t.Bool, | ||
is_manufacturer_specific=True, | ||
) | ||
wire_pilot_mode = ZCLAttributeDef(id=0x4000, type=t.Bool) | ||
|
||
async def write_attributes(self, attributes, manufacturer=None) -> list: | ||
"""Write attributes to the cluster.""" | ||
|
||
attrs = {} | ||
for attr, value in attributes.items(): | ||
attr_def = self.find_attribute(attr) | ||
attr_id = attr_def.id | ||
if attr_id == LegrandCluster.AttributeDefs.wire_pilot_mode.id: | ||
attrs[LegrandCluster.AttributeDefs.device_mode.id] = ( | ||
[0x02, 0x00] if value else [0x01, 0x00] | ||
) | ||
else: | ||
attrs[attr] = value | ||
return await super().write_attributes(attrs, manufacturer) | ||
|
||
def _update_attribute(self, attrid, value) -> None: | ||
super()._update_attribute(attrid, value) | ||
if attrid == LegrandCluster.AttributeDefs.device_mode.id: | ||
self._update_attribute( | ||
LegrandCluster.AttributeDefs.wire_pilot_mode.id, value[0] == 0x02 | ||
) | ||
|
||
|
||
class HeatMode(t.enum8): | ||
"""Heat mode.""" | ||
|
||
Comfort = 0x00 | ||
Comfort_minus_1 = 0x01 | ||
Comfort_minus_2 = 0x02 | ||
Eco = 0x03 | ||
Frost_protection = 0x04 | ||
Off = 0x05 | ||
|
||
|
||
class LegrandWirePilotCluster(CustomCluster): | ||
"""Legrand wire pilot manufacturer-specific cluster.""" | ||
|
||
cluster_id = MANUFACTURER_SPECIFIC_CLUSTER_ID_2 | ||
name = "LegrandWirePilotCluster" | ||
ep_attribute = "legrand_wire_pilot_cluster" | ||
|
||
class AttributeDefs(BaseAttributeDefs): | ||
"""Attribute definitions for LegrandCluster.""" | ||
|
||
heat_mode = ZCLAttributeDef( | ||
id=0x00, | ||
type=HeatMode, | ||
is_manufacturer_specific=True, | ||
) | ||
|
||
class ServerCommandDefs(BaseCommandDefs): | ||
"""Server command definitions.""" | ||
|
||
set_heat_mode = ZCLCommandDef( | ||
id=0x00, | ||
schema={"mode": HeatMode}, | ||
direction=Direction.Client_to_Server, | ||
is_manufacturer_specific=True, | ||
) | ||
|
||
async def write_attributes(self, attributes, manufacturer=None) -> list: | ||
"""Write attributes to the cluster.""" | ||
|
||
attrs = {} | ||
for attr, value in attributes.items(): | ||
attr_def = self.find_attribute(attr) | ||
attr_id = attr_def.id | ||
if attr_id == LegrandWirePilotCluster.AttributeDefs.heat_mode.id: | ||
await self.set_heat_mode(value, manufacturer=manufacturer) | ||
return await super().write_attributes(attrs, manufacturer) | ||
|
||
|
||
( | ||
add_to_registry_v2(f" {LEGRAND}", " Cable outlet") | ||
.replaces(LegrandCluster) | ||
.replaces(LegrandWirePilotCluster) | ||
.replaces(LegrandCluster, cluster_type=ClusterType.Client) | ||
.switch( | ||
attribute_name=LegrandCluster.AttributeDefs.wire_pilot_mode.name, | ||
cluster_id=LegrandCluster.cluster_id, | ||
translation_key="wire_pilot_mode", | ||
) | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do and should it have some sort of config entity in the quirk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was here before so I didn't touched it. I will look in details and I may provide a config switch for those attributes if it makes sense in another PR.