Skip to content

Commit ec82cb8

Browse files
TheJulianJESpuddly
andauthored
Fix custom divisor for Innr SP 240 on 0x191E3685 (#4592)
Co-authored-by: puddly <[email protected]>
1 parent 35d1fc1 commit ec82cb8

File tree

4 files changed

+54
-100
lines changed

4 files changed

+54
-100
lines changed

zhaquirks/innr/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
INNR = "innr"
88

99

10-
class MeteringClusterInnr(CustomCluster, Metering):
11-
"""Provide constant multiplier and divisor.
10+
class MeteringClusterInnrOld(CustomCluster, Metering):
11+
"""Provide constant multiplier and divisor for old Innr plug firmware.
1212
13-
The device seems to supply the summation_formatting attribute correctly, but ZHA doesn't use it for kWh for now.
13+
Old firmware provides incorrect values for the divisor, so we override them.
1414
"""
1515

1616
_CONSTANT_ATTRIBUTES = {
@@ -19,6 +19,20 @@ class MeteringClusterInnr(CustomCluster, Metering):
1919
}
2020

2121

22+
class MeteringClusterInnrNew(CustomCluster, Metering):
23+
"""Provide constant multiplier and divisor for new Innr plug firmware.
24+
25+
New firmware provides already provides correct value, but the old quirk will have
26+
persisted the static values in the database, so we need to force the new values
27+
to avoid users having to re-pair the device.
28+
"""
29+
30+
_CONSTANT_ATTRIBUTES = {
31+
Metering.AttributeDefs.multiplier.id: 1,
32+
Metering.AttributeDefs.divisor.id: 1000,
33+
}
34+
35+
2236
class ElectricalMeasurementClusterInnr(CustomCluster, ElectricalMeasurement):
2337
"""Fix multiplier and divisor for AC current and power."""
2438

zhaquirks/innr/innr_sp120_plug.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
OUTPUT_CLUSTERS,
2525
PROFILE_ID,
2626
)
27-
from zhaquirks.innr import INNR, ElectricalMeasurementClusterInnr, MeteringClusterInnr
27+
from zhaquirks.innr import (
28+
INNR,
29+
ElectricalMeasurementClusterInnr,
30+
MeteringClusterInnrOld,
31+
)
2832

2933

3034
class SP120(CustomDevice):
@@ -75,7 +79,7 @@ class SP120(CustomDevice):
7579
Groups.cluster_id,
7680
Identify.cluster_id,
7781
LevelControl.cluster_id,
78-
MeteringClusterInnr,
82+
MeteringClusterInnrOld,
7983
OnOff.cluster_id,
8084
Scenes.cluster_id,
8185
Time.cluster_id,

zhaquirks/innr/innr_sp234_plug.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
OUTPUT_CLUSTERS,
2525
PROFILE_ID,
2626
)
27-
from zhaquirks.innr import INNR, ElectricalMeasurementClusterInnr, MeteringClusterInnr
27+
from zhaquirks.innr import (
28+
INNR,
29+
ElectricalMeasurementClusterInnr,
30+
MeteringClusterInnrOld,
31+
)
2832

2933

3034
class SP234(CustomDevice):
@@ -75,7 +79,7 @@ class SP234(CustomDevice):
7579
Groups.cluster_id,
7680
Scenes.cluster_id,
7781
OnOff.cluster_id,
78-
MeteringClusterInnr,
82+
MeteringClusterInnrOld,
7983
ElectricalMeasurementClusterInnr,
8084
Diagnostic.cluster_id,
8185
LightLink.cluster_id,

zhaquirks/innr/innr_sp240_plug.py

Lines changed: 25 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
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

3110
class 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

Comments
 (0)