hue light
This commit is contained in:
102
src/HueColorBulbItem.ts
Normal file
102
src/HueColorBulbItem.ts
Normal file
@ -0,0 +1,102 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AHomegearItem } from './AHomegearItem'
|
||||
import { HueColorLightExport, ExportType } from './Export'
|
||||
|
||||
export class HueColorBulbItem extends AHomegearItem {
|
||||
private bright: number
|
||||
private colorTemperature: number
|
||||
private hue: number
|
||||
private saturation: number
|
||||
private state: string
|
||||
private stateActionTopic: string
|
||||
private brightActionTopic: string
|
||||
private colorTemperatureActionTopic: string
|
||||
private hueActionTopic: string
|
||||
private saturationActionTopic: string
|
||||
private brightFeedbackTopic: string
|
||||
private stateFeedbackTopic: string
|
||||
private colorTemperatureFeedbackTopic: string
|
||||
private hueFeedbackTopic: string
|
||||
private saturationFeedbackTopic: string
|
||||
private brightTopic: string
|
||||
private stateTopic: string
|
||||
private hueTopic: string
|
||||
private saturationTopic: string
|
||||
private colorTemperatureTopic: string
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number) {
|
||||
super(floor, room, item, label, hmId)
|
||||
this.stateTopic = `${this.topicFirstPart}/state`
|
||||
this.brightTopic = `${this.topicFirstPart}/bright`
|
||||
this.colorTemperatureTopic = `${this.topicFirstPart}/colorTemperature`
|
||||
this.hueTopic = `${this.topicFirstPart}/hue`
|
||||
this.saturationTopic = `${this.topicFirstPart}/saturation`
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
||||
this.brightFeedbackTopic = `${this.topicFirstPart}/bright/feedback`
|
||||
this.hueFeedbackTopic = `${this.topicFirstPart}/bright/hue`
|
||||
this.saturationFeedbackTopic = `${this.topicFirstPart}/bright/saturation`
|
||||
this.colorTemperatureFeedbackTopic = `${this.topicFirstPart}/colorTemperature/feedback`
|
||||
this.stateActionTopic = `${this.actionTopicPre}/1/STATE`
|
||||
this.brightActionTopic = `${this.actionTopicPre}/1/BRIGHTNESS`
|
||||
this.hueActionTopic = `${this.actionTopicPre}/1/HUE`
|
||||
this.saturationActionTopic = `${this.actionTopicPre}/1/SATURATION`
|
||||
this.colorTemperatureActionTopic = `${this.actionTopicPre}/1/COLOR_TEMPERATURE`
|
||||
this.subscribeTopics = [
|
||||
this.stateTopic,
|
||||
this.brightTopic,
|
||||
this.colorTemperatureTopic,
|
||||
this.hueTopic,
|
||||
this.saturationTopic
|
||||
]
|
||||
this.state = 'OFF'
|
||||
this.bright = 0
|
||||
this.colorTemperature = 0
|
||||
this.hue = 0
|
||||
this.saturation = 0
|
||||
}
|
||||
|
||||
exportItem() : ExportType|null {
|
||||
return HueColorLightExport(this.itemId, this.label,
|
||||
this.stateTopic, this.stateFeedbackTopic,
|
||||
this.brightTopic, this.brightFeedbackTopic,
|
||||
this.hueTopic, this.hueFeedbackTopic,
|
||||
this.saturationTopic, this.saturationFeedbackTopic,
|
||||
this.colorTemperatureTopic, this.colorTemperatureFeedbackTopic)
|
||||
}
|
||||
|
||||
|
||||
processMessage(topic: string, payload: string) : void {
|
||||
switch (topic) {
|
||||
case this.stateTopic:
|
||||
this.state = payload
|
||||
mqttHandler.send(this.stateFeedbackTopic, this.state)
|
||||
if (this.state == "ON") {
|
||||
mqttHandler.send(this.stateActionTopic, "true")
|
||||
} else {
|
||||
mqttHandler.send(this.stateActionTopic, "false")
|
||||
}
|
||||
break
|
||||
case this.brightTopic:
|
||||
this.bright = parseFloat(payload)
|
||||
mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`)
|
||||
mqttHandler.send(this.brightActionTopic, `${this.bright} * 2.54`)
|
||||
break
|
||||
case this.hueTopic:
|
||||
this.hue = parseFloat(payload)
|
||||
mqttHandler.send(this.hueFeedbackTopic, `${this.hue}`)
|
||||
mqttHandler.send(this.hueActionTopic, `${this.hue} * 65535.0 / 360.0`)
|
||||
break
|
||||
case this.saturationTopic:
|
||||
this.saturation = parseFloat(payload)
|
||||
mqttHandler.send(this.saturationFeedbackTopic, `${this.saturation}`)
|
||||
mqttHandler.send(this.saturationActionTopic, `${this.saturation} * 2.54`)
|
||||
break
|
||||
case this.colorTemperatureTopic:
|
||||
this.colorTemperature = parseInt(payload)
|
||||
mqttHandler.send(this.colorTemperatureFeedbackTopic, `${this.colorTemperature}`)
|
||||
mqttHandler.send(this.colorTemperatureActionTopic, `${this.colorTemperature}`)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user