67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import * as logger from './log'
|
|
import { mqttHandler } from './MqttDispatcher'
|
|
import { AHomegearItem } from './AHomegearItem'
|
|
import { LightScene } from './Scene'
|
|
|
|
export class MaxEcoSwitch extends AHomegearItem {
|
|
private ecoTopic: string
|
|
private mainTopic: string
|
|
private mainButtonTopic: string
|
|
private ecoButtonTopic: string
|
|
private state: string
|
|
|
|
constructor(floor: string, room: string, item: string, label: string, hmId: number,
|
|
mainScene: LightScene, ecoScene: LightScene) {
|
|
super(floor, room, item, label, hmId)
|
|
|
|
this.mainButtonTopic = `${this.deviceTopicPre}/1/PRESS`
|
|
this.ecoButtonTopic = `${this.deviceTopicPre}/2/PRESS`
|
|
|
|
this.subscribeTopics = [ this.mainButtonTopic, this.ecoButtonTopic ]
|
|
|
|
this.mainTopic = mainScene.getStateTopic()
|
|
this.ecoTopic = ecoScene.getStateTopic()
|
|
|
|
this.state = 'OFF'
|
|
}
|
|
|
|
|
|
|
|
processMessage(topic: string, payload: string) : void {
|
|
switch(this.state) {
|
|
case 'OFF':
|
|
if (topic == this.mainButtonTopic) {
|
|
this.state = 'ON'
|
|
} else if (topic == this.ecoButtonTopic) {
|
|
this.state = 'ECO'
|
|
}
|
|
break
|
|
case 'ON':
|
|
if (topic == this.mainButtonTopic) {
|
|
this.state = 'OFF'
|
|
} else if (topic == this.ecoButtonTopic) {
|
|
this.state = 'ECO'
|
|
}
|
|
break
|
|
case 'ECO':
|
|
if (topic == this.mainButtonTopic) {
|
|
this.state = 'ON'
|
|
} else if (topic == this.ecoButtonTopic) {
|
|
this.state = 'OFF'
|
|
}
|
|
break
|
|
}
|
|
switch(this.state) {
|
|
case 'OFF':
|
|
mqttHandler.send(this.mainTopic, 'OFF')
|
|
break
|
|
case 'ON':
|
|
mqttHandler.send(this.mainTopic, 'ON')
|
|
break
|
|
case 'ECO':
|
|
mqttHandler.send(this.ecoTopic, 'ON')
|
|
break
|
|
}
|
|
}
|
|
}
|