-
Notifications
You must be signed in to change notification settings - Fork 881
Add quirk for Schneider Electric 1GANG/SHUTTER/1 (MEG5113-0300) #2928
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
89ea58d
Add skeleton
axellebot e9a9e88
Add SE shutter related attributes
axellebot ca5559d
Edit lift_duration attribute
axellebot 4d9771d
Fix attribute name
axellebot 9ff2ed1
Revert covering lift percentage
axellebot 1afe73e
Remove ZCLAttributeDef use for attribute
axellebot 17dca84
Fix attributes update
axellebot 2a53080
Fix lift_duration attribute ID
axellebot c6da55b
Add Schneider Electric readme
axellebot c9ac278
Add SEOnOff cluster
axellebot f3ba323
Add CH2AX/SWITCH/1 signature
axellebot 3829121
Add found dimmer/thermostat mode
axellebot e01b590
Add CH2AX/SWITCH/1 scan
axellebot 6b90d19
Refactor modules
axellebot f3e7a34
Fix tests
axellebot 6725f0e
Merge branch 'dev' into schneider
cspurk 30f59f1
Add quirk for Schneider Electric 1GANG/SHUTTER/1 (MEG5113-0300)
cspurk 1aa7ff4
Merge branch 'dev' into schneider
cspurk 5257939
Correct type hint
cspurk adf0ad9
Add test asserting that unpatched ZCL commands keep working
cspurk a4d596c
Remove README by reviewer request
cspurk 5837511
Make structure of packages more consistent with others
cspurk 33f90aa
Remove superfluous cluster ID comments
cspurk b6c973e
Correct constant value for Schneider Electric manufacturer code
cspurk 18dce89
Merge branch 'dev' into schneider
cspurk a7ddd34
Define cluster attributes in a more modern way
cspurk 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 hidden or 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,134 @@ | ||
"""Tests for Schneider Electric devices.""" | ||
from unittest import mock | ||
|
||
from zigpy.zcl import foundation | ||
from zigpy.zcl.clusters.closures import WindowCovering | ||
|
||
import zhaquirks.schneiderelectric.devices.shutters | ||
|
||
from tests.common import ClusterListener | ||
|
||
zhaquirks.setup() | ||
|
||
|
||
def test_1gang_shutter_1_signature(assert_signature_matches_quirk): | ||
signature = { | ||
"node_descriptor": ( | ||
"NodeDescriptor(logical_type=<LogicalType.Router: 1>, " | ||
"complex_descriptor_available=0, user_descriptor_available=0, reserved=0, " | ||
"aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, " | ||
"mac_capability_flags=<MACCapabilityFlags.FullFunctionDevice|MainsPowered" | ||
"|RxOnWhenIdle|AllocateAddress: 142>, manufacturer_code=4190, " | ||
"maximum_buffer_size=82, maximum_incoming_transfer_size=82, " | ||
"server_mask=10752, maximum_outgoing_transfer_size=82, " | ||
"descriptor_capability_field=<DescriptorCapability.NONE: 0>, " | ||
"*allocate_address=True, *is_alternate_pan_coordinator=False, " | ||
"*is_coordinator=False, *is_end_device=False, " | ||
"*is_full_function_device=True, *is_mains_powered=True, " | ||
"*is_receiver_on_when_idle=True, *is_router=True, " | ||
"*is_security_capable=False)" | ||
), | ||
"endpoints": { | ||
"5": { | ||
"profile_id": 0x0104, | ||
"device_type": "0x0202", | ||
"in_clusters": [ | ||
"0x0000", | ||
"0x0003", | ||
"0x0004", | ||
"0x0005", | ||
"0x0102", | ||
"0x0b05", | ||
], | ||
"out_clusters": ["0x0019"], | ||
}, | ||
"21": { | ||
"profile_id": 0x0104, | ||
"device_type": "0x0104", | ||
"in_clusters": [ | ||
"0x0000", | ||
"0x0003", | ||
"0x0b05", | ||
"0xff17", | ||
], | ||
"out_clusters": [ | ||
"0x0003", | ||
"0x0005", | ||
"0x0006", | ||
"0x0008", | ||
"0x0019", | ||
"0x0102", | ||
], | ||
}, | ||
}, | ||
"manufacturer": "Schneider Electric", | ||
"model": "1GANG/SHUTTER/1", | ||
"class": "zigpy.device.Device", | ||
} | ||
assert_signature_matches_quirk( | ||
zhaquirks.schneiderelectric.devices.shutters.OneGangShutter1, signature | ||
) | ||
|
||
|
||
async def test_1gang_shutter_1_go_to_lift_percentage_cmd(zigpy_device_from_quirk): | ||
"""Asserts that the go_to_lift_percentage command inverts the percentage value.""" | ||
|
||
device = zigpy_device_from_quirk( | ||
zhaquirks.schneiderelectric.devices.shutters.OneGangShutter1 | ||
) | ||
window_covering_cluster = device.endpoints[5].window_covering | ||
|
||
p = mock.patch.object(window_covering_cluster, "request", mock.AsyncMock()) | ||
with p as request_mock: | ||
request_mock.return_value = (foundation.Status.SUCCESS, "done") | ||
|
||
await window_covering_cluster.go_to_lift_percentage(58) | ||
|
||
assert request_mock.call_count == 1 | ||
assert request_mock.call_args[0][1] == ( | ||
WindowCovering.ServerCommandDefs.go_to_lift_percentage.id | ||
) | ||
assert request_mock.call_args[0][3] == 42 # 100 - 58 | ||
|
||
|
||
async def test_1gang_shutter_1_unpatched_cmd(zigpy_device_from_quirk): | ||
"""Asserts that unpatched ZCL commands keep working.""" | ||
|
||
device = zigpy_device_from_quirk( | ||
zhaquirks.schneiderelectric.devices.shutters.OneGangShutter1 | ||
) | ||
window_covering_cluster = device.endpoints[5].window_covering | ||
|
||
p = mock.patch.object(window_covering_cluster, "request", mock.AsyncMock()) | ||
with p as request_mock: | ||
request_mock.return_value = (foundation.Status.SUCCESS, "done") | ||
|
||
await window_covering_cluster.up_open() | ||
|
||
assert request_mock.call_count == 1 | ||
assert request_mock.call_args[0][1] == ( | ||
WindowCovering.ServerCommandDefs.up_open.id | ||
) | ||
|
||
|
||
async def test_1gang_shutter_1_lift_percentage_updates(zigpy_device_from_quirk): | ||
"""Asserts that updates to the ``current_position_lift_percentage`` attribute | ||
(e.g., by the device) invert the reported percentage value.""" | ||
|
||
device = zigpy_device_from_quirk( | ||
zhaquirks.schneiderelectric.devices.shutters.OneGangShutter1 | ||
) | ||
window_covering_cluster = device.endpoints[5].window_covering | ||
cluster_listener = ClusterListener(window_covering_cluster) | ||
|
||
window_covering_cluster.update_attribute( | ||
WindowCovering.AttributeDefs.current_position_lift_percentage.id, | ||
77, | ||
) | ||
|
||
assert len(cluster_listener.attribute_updates) == 1 | ||
assert cluster_listener.attribute_updates[0] == ( | ||
WindowCovering.AttributeDefs.current_position_lift_percentage.id, | ||
23, # 100 - 77 | ||
) | ||
assert len(cluster_listener.cluster_commands) == 0 |
This file contains hidden or 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,4 @@ | ||
"""Quirks implementations for Schneider Electric devices.""" | ||
|
||
SE_MANUF_NAME = "Schneider Electric" | ||
SE_MANUF_ID = 0x4190 | ||
This file contains hidden or 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,131 @@ | ||
from typing import Any, Coroutine, Dict, Union | ||
|
||
from zigpy.quirks import CustomCluster | ||
import zigpy.types as t | ||
from zigpy.zcl import foundation | ||
from zigpy.zcl.clusters.closures import WindowCovering | ||
from zigpy.zcl.clusters.general import Basic | ||
from zigpy.zcl.foundation import ZCLAttributeDef | ||
|
||
|
||
class SEBasic(CustomCluster, Basic): | ||
"""Schneider Electric manufacturer specific Basic cluster.""" | ||
|
||
attributes: Dict[int, ZCLAttributeDef] = Basic.attributes.copy() | ||
|
||
attributes.update( | ||
{ | ||
0xE001: ( | ||
"se_sw_build_id", | ||
t.CharacterString, | ||
True, | ||
), # value: "002.004.016 R | ||
0xE002: ( | ||
"unknown_attribute_57346", | ||
t.CharacterString, | ||
True, | ||
), # value: "001.000.000" | ||
0xE004: ( | ||
"unknown_attribute_57348", | ||
t.CharacterString, | ||
True, | ||
), # value: "213249FEFF5ECFD" | ||
0xE007: ( | ||
"unknown_attribute_57351", | ||
t.enum16, | ||
True, | ||
), | ||
0xE008: ( | ||
"se_device_type", | ||
t.CharacterString, | ||
True, | ||
), # value: "Wiser Light" | ||
0xE009: ( | ||
"se_model", | ||
t.CharacterString, | ||
True, | ||
), # value: "NHPB/SHUTTER/1" | ||
0xE00A: ( | ||
"se_realm", | ||
t.CharacterString, | ||
True, | ||
), # value: "Wiser Home" | ||
0xE00B: ( | ||
"unknown_attribute_57355", | ||
t.CharacterString, | ||
True, | ||
), # value: "http://www.schneider-electric.com" | ||
} | ||
) | ||
|
||
|
||
class SEWindowCovering(CustomCluster, WindowCovering): | ||
"""Schneider Electric manufacturer specific Window Covering cluster.""" | ||
|
||
attributes: Dict[int, ZCLAttributeDef] = WindowCovering.attributes.copy() | ||
|
||
attributes.update( | ||
{ | ||
0xFFFD: ("unknown_attribute_65533", t.uint16_t, True), | ||
0xE000: ("lift_duration", t.uint16_t, True), | ||
0xE010: ("unknown_attribute_57360", t.bitmap8, True), | ||
0xE012: ("unknown_attribute_57362", t.uint16_t, True), | ||
0xE013: ("unknown_attribute_57363", t.bitmap8, True), | ||
0xE014: ("unknown_attribute_57364", t.uint16_t, True), | ||
0xE015: ("unknown_attribute_57365", t.uint16_t, True), | ||
0xE016: ("unknown_attribute_57366", t.uint16_t, True), | ||
0xE017: ("unknown_attribute_57367", t.uint8_t, True), | ||
} | ||
) | ||
|
||
def _update_attribute(self, attrid: Union[int, t.uint16_t], value: Any): | ||
if attrid == WindowCovering.AttributeDefs.current_position_lift_percentage.id: | ||
# Invert the percentage value | ||
value = 100 - value | ||
super()._update_attribute(attrid, value) | ||
|
||
async def command( | ||
self, | ||
command_id: Union[foundation.GeneralCommand, int, t.uint8_t], | ||
*args: Any, | ||
**kwargs: Any, | ||
) -> Coroutine: | ||
command = self.server_commands[command_id] | ||
|
||
# Override default command to invert percent lift value. | ||
if command.id == WindowCovering.ServerCommandDefs.go_to_lift_percentage.id: | ||
percent = args[0] | ||
percent = 100 - percent | ||
return await super().command(command_id, percent, **kwargs) | ||
|
||
return await super().command(command_id, *args, **kwargs) | ||
|
||
|
||
class SESpecific(CustomCluster): | ||
"""Schneider Electric manufacturer specific cluster.""" | ||
|
||
name = "Schneider Electric Manufacturer Specific" | ||
ep_attribute = "schneider_electric_manufacturer" | ||
cluster_id = 0xFF17 | ||
|
||
class LedIndicatorSignals(t.enum8): | ||
"""Available LED indicator signal combinations. | ||
|
||
Shutter movement can be indicated with a red LED signal. A green LED | ||
light permanently provides orientation, if desired. | ||
""" | ||
|
||
MOVEMENT_ONLY = 0x00 | ||
MOVEMENT_AND_ORIENTATION = 0x01 | ||
ORIENTATION_ONLY = 0x02 | ||
NONE = 0x03 | ||
|
||
attributes = { | ||
0x0000: ("led_indicator_signals", LedIndicatorSignals, True), | ||
0x0001: ("unknown_attribute_1", t.enum8, True), | ||
0x0010: ("unknown_attribute_16", t.uint8_t, True), | ||
0x0011: ("unknown_attribute_17", t.uint16_t, True), | ||
0x0020: ("unknown_attribute_32", t.uint8_t, True), | ||
0x0021: ("unknown_attribute_33", t.uint16_t, True), | ||
0xFFFD: ("unknown_attribute_65533", t.uint16_t, True), | ||
} |
Empty file.
This file contains hidden or 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,112 @@ | ||
"""Quirks for Schneider Electric shutters.""" | ||
from zigpy.profiles import zha | ||
from zigpy.quirks import CustomDevice | ||
from zigpy.zcl.clusters.closures import WindowCovering | ||
from zigpy.zcl.clusters.general import ( | ||
Basic, | ||
Groups, | ||
Identify, | ||
LevelControl, | ||
OnOff, | ||
Ota, | ||
Scenes, | ||
) | ||
from zigpy.zcl.clusters.homeautomation import Diagnostic | ||
|
||
from zhaquirks.const import ( | ||
DEVICE_TYPE, | ||
ENDPOINTS, | ||
INPUT_CLUSTERS, | ||
MODELS_INFO, | ||
OUTPUT_CLUSTERS, | ||
PROFILE_ID, | ||
) | ||
from zhaquirks.schneiderelectric import SE_MANUF_NAME | ||
from zhaquirks.schneiderelectric.clusters import SEBasic, SESpecific, SEWindowCovering | ||
|
||
|
||
class OneGangShutter1(CustomDevice): | ||
"""1GANG/SHUTTER/1 from Schneider Electric.""" | ||
|
||
signature = { | ||
MODELS_INFO: [ | ||
(SE_MANUF_NAME, "1GANG/SHUTTER/1"), | ||
], | ||
ENDPOINTS: { | ||
# <SimpleDescriptor endpoint=5, profile=260, device_type=514, | ||
# device_version=0, | ||
# input_clusters=[0, 3, 4, 5, 258, 2821], | ||
# output_clusters=[25]> | ||
5: { | ||
PROFILE_ID: zha.PROFILE_ID, | ||
DEVICE_TYPE: zha.DeviceType.WINDOW_COVERING_DEVICE, # 0x0202 | ||
INPUT_CLUSTERS: [ | ||
Basic.cluster_id, # 0x0000 | ||
Identify.cluster_id, # 0x0003 | ||
Groups.cluster_id, # 0x0004 | ||
Scenes.cluster_id, # 0x0005 | ||
WindowCovering.cluster_id, # 0x0102 | ||
Diagnostic.cluster_id, # 0x0B05 | ||
], | ||
OUTPUT_CLUSTERS: [Ota.cluster_id], # 0x0019 | ||
|
||
}, | ||
# <SimpleDescriptor endpoint=21, profile=260, device_type=260, | ||
# device_version=0, | ||
# input_clusters=[0, 3, 2821, 65303], | ||
# output_clusters=[3, 5, 6, 8, 25, 258]> | ||
21: { | ||
PROFILE_ID: zha.PROFILE_ID, | ||
DEVICE_TYPE: zha.DeviceType.DIMMER_SWITCH, # 0x0104 | ||
INPUT_CLUSTERS: [ | ||
Basic.cluster_id, # 0x0000 | ||
Identify.cluster_id, # 0x0003 | ||
Diagnostic.cluster_id, # 0x0B05 | ||
SESpecific.cluster_id, # 0xFF17 | ||
], | ||
OUTPUT_CLUSTERS: [ | ||
Identify.cluster_id, # 0x0003 | ||
Scenes.cluster_id, # 0x0005 | ||
OnOff.cluster_id, # 0x0006 | ||
LevelControl.cluster_id, # 0x0008 | ||
Ota.cluster_id, # 0x0019 | ||
WindowCovering.cluster_id, # 0x0102 | ||
], | ||
}, | ||
}, | ||
} | ||
|
||
replacement = { | ||
ENDPOINTS: { | ||
5: { | ||
PROFILE_ID: zha.PROFILE_ID, | ||
DEVICE_TYPE: zha.DeviceType.WINDOW_COVERING_DEVICE, # 0x0202 | ||
INPUT_CLUSTERS: [ | ||
SEBasic, # 0x0000 | ||
Identify.cluster_id, # 0x0003 | ||
Groups.cluster_id, # 0x0004 | ||
Scenes.cluster_id, # 0x0005 | ||
SEWindowCovering, # 0x0102 | ||
Diagnostic.cluster_id, # 0x0B05 | ||
], | ||
OUTPUT_CLUSTERS: [Ota.cluster_id], # 0x0019 | ||
}, | ||
21: { | ||
PROFILE_ID: zha.PROFILE_ID, | ||
DEVICE_TYPE: zha.DeviceType.DIMMER_SWITCH, # 0x0104 | ||
INPUT_CLUSTERS: [ | ||
SEBasic, # 0x0000 | ||
Identify.cluster_id, # 0x0003 | ||
Diagnostic.cluster_id, # 0x0B05 | ||
SESpecific, # 0xff17 | ||
], | ||
OUTPUT_CLUSTERS: [ | ||
Identify.cluster_id, # 0x0003 | ||
Scenes.cluster_id, # 0x0005 | ||
OnOff.cluster_id, # 0x0006 | ||
LevelControl.cluster_id, # 0x0008 | ||
Ota.cluster_id, # 0x0019 | ||
SEWindowCovering, # 0x0102 | ||
], | ||
}, | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.