11"""Innr SP 240 plug."""
22
3- from zigpy .profiles import zgp , zha
4- from zigpy .quirks import CustomCluster , CustomDevice
5- from zigpy .zcl .clusters .general import (
6- Basic ,
7- GreenPowerProxy ,
8- Groups ,
9- Identify ,
10- LevelControl ,
11- OnOff ,
12- Ota ,
13- Scenes ,
14- Time ,
15- )
16- from zigpy .zcl .clusters .homeautomation import ElectricalMeasurement
17- from zigpy .zcl .clusters .lightlink import LightLink
18- from zigpy .zcl .clusters .smartenergy import Metering
3+ from zigpy .quirks import CustomCluster
4+ from zigpy .quirks .v2 import QuirkBuilder
5+ from zigpy .zcl .clusters .general import LevelControl
196
20- from zhaquirks .const import (
21- DEVICE_TYPE ,
22- ENDPOINTS ,
23- INPUT_CLUSTERS ,
24- MODELS_INFO ,
25- OUTPUT_CLUSTERS ,
26- PROFILE_ID ,
27- )
28- from zhaquirks .innr import INNR , MeteringClusterInnr
7+ from zhaquirks .innr import MeteringClusterInnrNew , MeteringClusterInnrOld
298
309
3110class InnrCluster (CustomCluster ):
@@ -34,72 +13,25 @@ class InnrCluster(CustomCluster):
3413 cluster_id = 0xE001
3514
3615
37- class SP240 (CustomDevice ):
38- """Innr SP 240 smart plug."""
39-
40- signature = {
41- MODELS_INFO : [(INNR , "SP 240" )],
42- ENDPOINTS : {
43- 1 : {
44- PROFILE_ID : zha .PROFILE_ID ,
45- DEVICE_TYPE : zha .DeviceType .ON_OFF_PLUG_IN_UNIT ,
46- INPUT_CLUSTERS : [
47- Basic .cluster_id ,
48- Identify .cluster_id ,
49- Groups .cluster_id ,
50- Scenes .cluster_id ,
51- OnOff .cluster_id ,
52- LevelControl .cluster_id ,
53- Metering .cluster_id ,
54- ElectricalMeasurement .cluster_id ,
55- LightLink .cluster_id ,
56- InnrCluster .cluster_id ,
57- ],
58- OUTPUT_CLUSTERS : [
59- Time .cluster_id ,
60- Ota .cluster_id ,
61- ],
62- },
63- 242 : {
64- PROFILE_ID : zgp .PROFILE_ID ,
65- DEVICE_TYPE : zgp .DeviceType .PROXY_BASIC ,
66- INPUT_CLUSTERS : [],
67- OUTPUT_CLUSTERS : [
68- GreenPowerProxy .cluster_id ,
69- ],
70- },
71- },
72- }
16+ (
17+ QuirkBuilder (manufacturer = "innr" , model = "SP 240" )
18+ # Firmware version 421410437 fixed the divisor and multiplier bug,
19+ # so only apply this quirk to versions older than that (max_version is exclusive).
20+ .firmware_version_filter (max_version = 0x191E3685 , allow_missing = False )
21+ .replaces (MeteringClusterInnrOld , endpoint_id = 1 )
22+ .replaces (InnrCluster , endpoint_id = 1 )
23+ .prevent_default_entity_creation (endpoint_id = 1 , cluster_id = LevelControl .cluster_id )
24+ .add_to_registry ()
25+ )
7326
74- replacement = {
75- ENDPOINTS : {
76- 1 : {
77- PROFILE_ID : zha .PROFILE_ID ,
78- DEVICE_TYPE : zha .DeviceType .ON_OFF_PLUG_IN_UNIT ,
79- INPUT_CLUSTERS : [
80- Basic .cluster_id ,
81- Identify .cluster_id ,
82- Groups .cluster_id ,
83- Scenes .cluster_id ,
84- OnOff .cluster_id ,
85- LevelControl .cluster_id ,
86- MeteringClusterInnr ,
87- ElectricalMeasurement .cluster_id ,
88- LightLink .cluster_id ,
89- InnrCluster ,
90- ],
91- OUTPUT_CLUSTERS : [
92- Time .cluster_id ,
93- Ota .cluster_id ,
94- ],
95- },
96- 242 : {
97- PROFILE_ID : zgp .PROFILE_ID ,
98- DEVICE_TYPE : zgp .DeviceType .PROXY_BASIC ,
99- INPUT_CLUSTERS : [],
100- OUTPUT_CLUSTERS : [
101- GreenPowerProxy .cluster_id ,
102- ],
103- },
104- },
105- }
27+ (
28+ QuirkBuilder (manufacturer = "innr" , model = "SP 240" )
29+ # Firmware version 421410437 fixed the divisor and multiplier bug,
30+ # so apply this quirk to that and newer versions to force correct new values,
31+ # in case the old quirk persisted the old values into the database.
32+ .firmware_version_filter (min_version = 0x191E3685 , allow_missing = True )
33+ .replaces (MeteringClusterInnrNew , endpoint_id = 1 )
34+ .replaces (InnrCluster , endpoint_id = 1 )
35+ .prevent_default_entity_creation (endpoint_id = 1 , cluster_id = LevelControl .cluster_id )
36+ .add_to_registry ()
37+ )
0 commit comments