@@ -20,12 +20,6 @@ import {MessageType} from "./ws/const";
2020export class HomewizardPrincessHeaterAccessory {
2121 private service : Service ;
2222
23- /**
24- * These are just used to create a working example
25- * You should implement your own code to track the state of your accessory
26- */
27- // private state: PrincessHeaterState | null = null;
28-
2923 constructor (
3024 private readonly platform : HomebridgePrincessHeaterPlatform ,
3125 private readonly accessory : PlatformAccessory < PrincessHeaterAccessoryContext > ,
@@ -53,6 +47,9 @@ export class HomewizardPrincessHeaterAccessory {
5347 } )
5448 . on ( 'set' , this . setTargetTemperature . bind ( this ) )
5549
50+ this . service . getCharacteristic ( this . platform . Characteristic . LockPhysicalControls )
51+ . on ( 'set' , this . setLockPhysicalControls . bind ( this ) )
52+
5653
5754 this . wsClient . ws . on ( 'message' , this . onWsMessage . bind ( this ) ) ;
5855
@@ -72,11 +69,11 @@ export class HomewizardPrincessHeaterAccessory {
7269 if ( 'state' in incomingMessage ) {
7370 this . onStateMessage ( incomingMessage )
7471 } else if ( 'type' in incomingMessage && incomingMessage . type === MessageType . JSONPatch ) {
75- this . onJSONMessage ( incomingMessage )
72+ this . onJSONPatchMessage ( incomingMessage )
7673 }
7774 }
7875
79- onJSONMessage ( message : JSONPatchWsIncomingMessage ) {
76+ onJSONPatchMessage ( message : JSONPatchWsIncomingMessage ) {
8077 message . patch . forEach ( patchItem => {
8178 const { op, path, value} = patchItem
8279
@@ -108,7 +105,6 @@ export class HomewizardPrincessHeaterAccessory {
108105
109106 onStateMessage ( message : PrincessHeaterStateWsIncomingMessage ) {
110107 this . platform . log . info ( 'Updating state from message ->' , message ) ;
111- // this.state = message.state
112108
113109 Object . keys ( message . state ) . forEach ( key => {
114110 const value = message . state [ key ]
@@ -133,62 +129,34 @@ export class HomewizardPrincessHeaterAccessory {
133129 }
134130
135131 setTargetHeatingCoolingState ( value : CharacteristicValue , callback : CharacteristicSetCallback ) {
136- // if (this.state) {
137-
138- let stateValue : boolean
139- let normalizedValue : CharacteristicValue = value
140-
141- switch ( value ) {
142- case this . platform . Characteristic . TargetHeatingCoolingState . OFF :
143- case this . platform . Characteristic . TargetHeatingCoolingState . COOL :
144- stateValue = false ;
145- normalizedValue = this . platform . Characteristic . TargetHeatingCoolingState . OFF
146- break ;
147- case this . platform . Characteristic . TargetHeatingCoolingState . HEAT :
148- case this . platform . Characteristic . TargetHeatingCoolingState . AUTO :
149- stateValue = true ;
150- normalizedValue = this . platform . Characteristic . TargetHeatingCoolingState . HEAT
151- break ;
152- default :
153- this . platform . log . warn ( 'Setting Characteristic TargetHeatingCoolingState, but value is not supported ->' , value ) ;
154- callback ( new Error ( 'Unsupported characteristic value' ) )
155- return ;
156- }
157132
158- this . platform . log . debug ( 'Set Characteristic TargetHeatingCoolingState ->' , value , stateValue ) ;
133+ this . platform . log . debug ( 'Set Characteristic TargetHeatingCoolingState ->' , value ) ;
159134
160135 const message : JSONPatchWsOutgoingMessage = {
161136 type : MessageType . JSONPatch ,
162137 message_id : this . wsClient . generateMessageId ( ) ,
163138 device : this . accessory . context . device . identifier ,
164139 patch : [ {
165- op : " replace" ,
166- path : ` /state/power_on` ,
167- value : stateValue
140+ op : ' replace' ,
141+ path : ' /state/power_on' ,
142+ value : value === this . platform . Characteristic . TargetHeatingCoolingState . HEAT
168143 } ]
169144 }
170145
171146 this . wsClient . send ( message ) ;
172147
173- this . service . updateCharacteristic ( this . platform . Characteristic . TargetHeatingCoolingState , normalizedValue )
174-
175148 callback ( null )
176- // } else {
177- // this.platform.log.warn('Trying to set TargetHeatingCoolingState but state is null');
178- // callback(new Error('Trying to set TargetHeatingCoolingState but state is null'))
179- // }
180149 }
181150
182151 setTargetTemperature ( value : CharacteristicValue , callback : CharacteristicSetCallback ) {
183- // if (this.state) {
184152
185153 const message : JSONPatchWsOutgoingMessage = {
186154 type : MessageType . JSONPatch ,
187155 message_id : this . wsClient . generateMessageId ( ) ,
188156 device : this . accessory . context . device . identifier ,
189157 patch : [ {
190- op : " replace" ,
191- path : ` /state/target_temperature` ,
158+ op : ' replace' ,
159+ path : ' /state/target_temperature' ,
192160 value : value
193161 } ]
194162 }
@@ -197,12 +165,26 @@ export class HomewizardPrincessHeaterAccessory {
197165
198166 this . wsClient . send ( message ) ;
199167
200- this . service . updateCharacteristic ( this . platform . Characteristic . TargetTemperature , value )
168+ callback ( null )
169+ }
170+
171+ setLockPhysicalControls ( value : CharacteristicValue , callback : CharacteristicSetCallback ) {
172+
173+ const message : JSONPatchWsOutgoingMessage = {
174+ type : MessageType . JSONPatch ,
175+ message_id : this . wsClient . generateMessageId ( ) ,
176+ device : this . accessory . context . device . identifier ,
177+ patch : [ {
178+ op : 'replace' ,
179+ path : '/state/lock' ,
180+ value : Boolean ( value )
181+ } ]
182+ }
183+
184+ this . platform . log . debug ( 'Set Characteristic LockPhysicalControls ->' , value ) ;
185+
186+ this . wsClient . send ( message ) ;
201187
202188 callback ( null )
203- // } else {
204- // this.platform.log.warn('Trying to set TargetTemperature but state is null');
205- // callback(new Error('Trying to set TargetTemperature but state is null'))
206- // }
207189 }
208190}
0 commit comments