22
33from typing import Final
44
5- from zigpy .quirks import CustomCluster
6- from zigpy .quirks .v2 import CustomDeviceV2 , QuirkBuilder
5+ from zigpy .quirks .v2 import QuirkBuilder
76import zigpy .types as t
8- from zigpy .zcl .clusters .homeautomation import ElectricalMeasurement
9- from zigpy .zcl .clusters .hvac import Thermostat , UserInterface
7+ from zigpy .zcl .clusters .hvac import Thermostat
108from zigpy .zcl .foundation import ZCLAttributeDef
119
12- from zhaquirks import Bus , LocalDataCluster
13-
14- ELKO = "ELKO"
10+ from zhaquirks .elko import (
11+ ELKO ,
12+ ElkoElectricalMeasurementCluster ,
13+ ElkoThermostat ,
14+ ElkoThermostatCluster ,
15+ ElkoUserInterfaceCluster ,
16+ )
1517
1618LOCAL_TEMP = 0x0000
1719UNKNOWN_1 = 0x0401
3537UNKNOWN_9 = 0x0419
3638
3739
38- class ElkoThermostatCluster (CustomCluster , Thermostat ):
39- """Thermostat cluster for Elko Thermostats."""
40-
41- class AttributeDefs (Thermostat .AttributeDefs ):
42- """Cluster attributes."""
43-
44- def __init__ (self , * args , ** kwargs ):
45- """Init thermostat cluster."""
46- super ().__init__ (* args , ** kwargs )
47- self .endpoint .device .thermostat_bus .add_listener (self )
48-
49- def heating_active_change (self , value ):
50- """State update from device."""
51- if value == 0 :
52- mode = self .RunningMode .Off
53- state = self .RunningState .Idle
54- else :
55- mode = self .RunningMode .Heat
56- state = self .RunningState .Heat_State_On
57-
58- self ._update_attribute (self .attributes_by_name ["running_mode" ].id , mode )
59- self ._update_attribute (self .attributes_by_name ["running_state" ].id , state )
60-
61-
62- class ElkoUserInterfaceCluster (LocalDataCluster , UserInterface ):
63- """User interface cluster for Elko Thermostats."""
64-
65- def __init__ (self , * args , ** kwargs ):
66- """Init UI cluster."""
67- super ().__init__ (* args , ** kwargs )
68- self .endpoint .device .ui_bus .add_listener (self )
69-
70- def child_lock_change (self , mode ):
71- """Enable/disable child lock."""
72- if mode :
73- lockout = self .KeypadLockout .Level_1_lockout
74- else :
75- lockout = self .KeypadLockout .No_lockout
76-
77- self ._update_attribute (self .attributes_by_name ["keypad_lockout" ].id , lockout )
78-
79-
80- class ElkoElectricalMeasurementCluster (LocalDataCluster , ElectricalMeasurement ):
81- """Electrical measurement cluster for Elko Thermostats."""
82-
83- ACTIVE_POWER_ID = 0x050B
84-
85- def __init__ (self , * args , ** kwargs ):
86- """Init electrical measurement cluster."""
87- super ().__init__ (* args , ** kwargs )
88- self .endpoint .device .power_bus .add_listener (self )
89-
90- def power_reported (self , value ):
91- """Report consumption."""
92- self ._update_attribute (self .ACTIVE_POWER_ID , value )
93-
94-
95- class ElkoThermostat (CustomDeviceV2 ):
96- """Generic Elko Thermostat device."""
97-
98- def __init__ (self , * args , ** kwargs ):
99- """Init device."""
100- self .thermostat_bus = Bus ()
101- self .ui_bus = Bus ()
102- self .power_bus = Bus ()
103- super ().__init__ (* args , ** kwargs )
104-
105-
10640class ActiveSensor (t .enum8 ):
10741 """Working modes of the thermostat."""
10842
@@ -145,6 +79,7 @@ def __init__(self, *args, **kwargs):
14579 """Init Elko thermostat."""
14680 super ().__init__ (* args , ** kwargs )
14781 self .active_sensor = None
82+ self .endpoint .device .thermostat_bus .add_listener (self )
14883
14984 async def write_attributes (self , attributes , manufacturer = None ):
15085 """Override writes to thermostat attributes."""
@@ -165,9 +100,15 @@ async def write_attributes(self, attributes, manufacturer=None):
165100
166101 def _update_attribute (self , attrid , value ):
167102 if attrid == HEATING_ACTIVE :
168- self .endpoint .device .thermostat_bus .listener_event (
169- "heating_active_change" , value
170- )
103+ if value == 0 :
104+ mode = self .RunningMode .Off
105+ state = self .RunningState .Idle
106+ else :
107+ mode = self .RunningMode .Heat
108+ state = self .RunningState .Heat_State_On
109+
110+ self ._update_attribute (self .attributes_by_name ["running_mode" ].id , mode )
111+ self ._update_attribute (self .attributes_by_name ["running_state" ].id , state )
171112 elif attrid == CHILD_LOCK :
172113 self .endpoint .device .ui_bus .listener_event ("child_lock_change" , value )
173114 elif attrid == ACTIVE_SENSOR :
0 commit comments