1- import {
2- Characteristic ,
3- CharacteristicGetCallback ,
4- CharacteristicSetCallback ,
5- CharacteristicValue ,
6- PlatformAccessory ,
7- Service
8- } from 'homebridge' ;
1+ import { CharacteristicSetCallback , CharacteristicValue , PlatformAccessory , Service , Units } from 'homebridge' ;
92
103import { HomebridgePrincessHeaterPlatform } from './platform' ;
114import {
@@ -14,13 +7,10 @@ import {
147 PrincessHeaterAccessoryContext ,
158 PrincessHeaterState ,
169 PrincessHeaterStateWsIncomingMessage ,
17- ResponseWsIncomingMessage ,
18- SubscribeWsOutgoingMessage ,
19- WsIncomingMessage
10+ SubscribeWsOutgoingMessage
2011} from "./ws/types" ;
2112import { WsClient } from "./ws/client" ;
2213import { MessageType } from "./ws/const" ;
23- import { normalizeSlashes } from "ts-node" ;
2414
2515/**
2616 * Platform Accessory
@@ -47,24 +37,22 @@ export class HomewizardPrincessHeaterAccessory {
4737 this . service . setCharacteristic ( this . platform . Characteristic . Name , this . accessory . displayName ) ;
4838
4939 this . service . getCharacteristic ( this . platform . Characteristic . TargetHeatingCoolingState )
40+ . setProps ( {
41+ validValues : [
42+ this . platform . Characteristic . TargetHeatingCoolingState . OFF ,
43+ this . platform . Characteristic . TargetHeatingCoolingState . HEAT
44+ ]
45+ } )
5046 . on ( 'set' , this . setTargetHeatingCoolingState . bind ( this ) ) ;
51- // .on('get', this.getTargetHeatingCoolingState.bind(this));
5247
53- // this.service.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
54- // .on('get', this.getCurrentHeaterCoolerState.bind(this));
55-
56- // this.service.getCharacteristic(this.platform.Characteristic.CurrentHeatingCoolingState)
57- // .on('get', this.getCurrentHeatingCoolingState.bind(this));
5848
5949 this . service . getCharacteristic ( this . platform . Characteristic . TargetTemperature )
6050 . setProps ( {
51+ unit : Units . CELSIUS ,
6152 minStep : 1
6253 } )
6354 . on ( 'set' , this . setTargetTemperature . bind ( this ) )
64- // .on('get', this.getTargetTemperature.bind(this));
6555
66- // this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
67- // .on('get', this.getCurrentTemperature.bind(this));
6856
6957 this . wsClient . ws . on ( 'message' , this . onWsMessage . bind ( this ) ) ;
7058
@@ -95,6 +83,39 @@ export class HomewizardPrincessHeaterAccessory {
9583 onStateMessage ( message : PrincessHeaterStateWsIncomingMessage ) {
9684 this . platform . log . info ( 'Updating state from message ->' , message ) ;
9785 this . state = message . state
86+
87+ Object . keys ( message . state ) . forEach ( key => {
88+ const value = message . state [ key ]
89+
90+ switch ( key ) {
91+ case 'power_on' :
92+ this . service . setCharacteristic (
93+ this . platform . Characteristic . TargetHeatingCoolingState ,
94+ value ?
95+ this . platform . Characteristic . TargetHeatingCoolingState . HEAT :
96+ this . platform . Characteristic . TargetHeatingCoolingState . OFF
97+ ) ;
98+ this . service . setCharacteristic (
99+ this . platform . Characteristic . CurrentHeatingCoolingState ,
100+ value ?
101+ this . platform . Characteristic . CurrentHeatingCoolingState . HEAT :
102+ this . platform . Characteristic . CurrentHeatingCoolingState . OFF
103+ ) ;
104+ break ;
105+ case 'current_temperature' :
106+ this . service . setCharacteristic (
107+ this . platform . Characteristic . CurrentTemperature ,
108+ value
109+ ) ;
110+ break ;
111+ case 'target_temperature' :
112+ this . service . setCharacteristic (
113+ this . platform . Characteristic . TargetTemperature ,
114+ value
115+ ) ;
116+ break ;
117+ }
118+ } )
98119 }
99120
100121 setTargetHeatingCoolingState ( value : CharacteristicValue , callback : CharacteristicSetCallback ) {
@@ -139,6 +160,8 @@ export class HomewizardPrincessHeaterAccessory {
139160
140161 this . wsClient . send ( message ) ;
141162
163+ this . service . updateCharacteristic ( this . platform . Characteristic . TargetHeatingCoolingState , normalizedValue )
164+
142165 callback ( null )
143166 } else {
144167 this . platform . log . warn ( 'Trying to set TargetHeatingCoolingState but state is null' ) ;
0 commit comments