66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import * as logger from './log'
|
|
import { mqttHandler } from './MqttDispatcher'
|
|
import { AHomematicItem } from './AHomematicItem'
|
|
import { LightScene } from './Scene'
|
|
|
|
export class MaxEcoSwitch extends AHomematicItem {
|
|
private ecoTopic: string
|
|
private mainTopic: string
|
|
private buttonTopic2: string
|
|
private buttonTopic1: 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.buttonTopic1 = `${this.deviceTopicPre}/1/PRESS`
|
|
this.buttonTopic2 = `${this.deviceTopicPre}/2/PRESS`
|
|
|
|
this.subscribeTopics = [ this.buttonTopic1, this.buttonTopic2 ]
|
|
|
|
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.mainTopic) {
|
|
this.state = 'ON'
|
|
} else if (topic == this.ecoTopic) {
|
|
this.state = 'ECO'
|
|
}
|
|
break
|
|
case 'ON':
|
|
if (topic == this.mainTopic) {
|
|
this.state = 'OFF'
|
|
} else if (topic == this.ecoTopic) {
|
|
this.state = 'ECO'
|
|
}
|
|
break
|
|
case 'ECO':
|
|
if (topic == this.mainTopic) {
|
|
this.state = 'ON'
|
|
} else if (topic == this.ecoTopic) {
|
|
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
|
|
}
|
|
}
|
|
} |