77 lines
2.8 KiB
TypeScript
77 lines
2.8 KiB
TypeScript
import * as logger from './log'
|
|
import { mqttHandler } from './MqttDispatcher'
|
|
import { AHomematicItem } from './AHomematicItem'
|
|
|
|
|
|
export class HomematicDimmerItem extends AHomematicItem {
|
|
private oldBright: number|undefined
|
|
private bright: number
|
|
private oldState: string|undefined
|
|
private state: string
|
|
private errorReducedTopic: string
|
|
private errorOverloadTopic: string
|
|
private errorOverheatTopic: string
|
|
private actionTopic: string
|
|
private brightFeedbackTopic: string
|
|
private stateFeedbackTopic: string
|
|
private brightTopic: string
|
|
private stateTopic: string
|
|
|
|
constructor(floor: string, room: string, item: string, hmId: number) {
|
|
super(floor, room, item, hmId)
|
|
this.stateTopic = `${this.topicFirstPart}/state`
|
|
this.brightTopic = `${this.topicFirstPart}/bright`
|
|
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
|
this.brightFeedbackTopic = `${this.topicFirstPart}/bright/feedback`
|
|
this.actionTopic = `${this.actionTopicPre}/1/LEVEL`
|
|
this.errorOverheatTopic = `${this.deviceTopicPre}/1/ERROR_OVERHEAT`
|
|
this.errorOverloadTopic = `${this.deviceTopicPre}/1/ERROR_OVERLOAD`
|
|
this.errorReducedTopic = `${this.deviceTopicPre}/1/ERROR_REDUCED`
|
|
this.subscribeTopics = [
|
|
this.stateTopic,
|
|
this.brightTopic,
|
|
this.errorOverheatTopic,
|
|
this.errorOverloadTopic,
|
|
this.errorReducedTopic
|
|
]
|
|
this.state = 'OFF'
|
|
this.oldState = undefined
|
|
this.bright = 0.0
|
|
this.oldBright = undefined
|
|
}
|
|
|
|
dimmerAction() : void {
|
|
if ((this.state != this.oldState) || (this.bright != this.oldBright)) {
|
|
if (this.state == 'ON') {
|
|
mqttHandler.send(this.actionTopic, `${this.bright / 100.0}`)
|
|
} else {
|
|
mqttHandler.send(this.actionTopic, '0')
|
|
}
|
|
this.oldState = this.state
|
|
this.oldBright = this.bright
|
|
}
|
|
}
|
|
|
|
processMessage(topic: string, payload: string) : void {
|
|
switch (topic) {
|
|
case this.stateTopic:
|
|
this.state = payload
|
|
mqttHandler.send(this.stateFeedbackTopic, this.state)
|
|
this.dimmerAction()
|
|
break
|
|
case this.brightTopic:
|
|
this.bright = parseFloat(payload)
|
|
mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`)
|
|
this.dimmerAction()
|
|
break
|
|
case this.errorOverheatTopic:
|
|
case this.errorOverloadTopic:
|
|
case this.errorReducedTopic:
|
|
if (payload != 'false') {
|
|
logger.warn(`Homematic dimmer ${this.hmId}, ${this.itemId} reports: ${topic}: ${payload}`)
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|