consider device feedback
This commit is contained in:
@ -5,6 +5,9 @@ import { HueColorLightExport, ExportType } from './Export'
|
||||
import { HasStateAndFeedbackTopic, HasInTopic } from './AItem'
|
||||
|
||||
export class HueColorBulbItem extends AHomegearItem implements HasStateAndFeedbackTopic{
|
||||
private readonly BRIGHT_FACTOR: number = 2.54
|
||||
private readonly HUE_FACTOR: number = (65535 / 360)
|
||||
private readonly SATURATION_FACTOR: number = 2.54
|
||||
private bright: number
|
||||
private colorTemperature: number
|
||||
private hue: number
|
||||
@ -25,6 +28,11 @@ export class HueColorBulbItem extends AHomegearItem implements HasStateAndFeedba
|
||||
private hueTopic: string
|
||||
private saturationTopic: string
|
||||
private colorTemperatureTopic: string
|
||||
private stateDeviceTopic: string
|
||||
private brightDeviceTopic: string
|
||||
private colorTemperatureDeviceTopic: string
|
||||
private hueDeviceTopic: string
|
||||
private saturationDeviceTopic: string
|
||||
|
||||
getStateTopic() : string {
|
||||
return this.stateTopic
|
||||
@ -55,12 +63,22 @@ export class HueColorBulbItem extends AHomegearItem implements HasStateAndFeedba
|
||||
this.hueActionTopic = `${this.actionTopicPre}/1/HUE`
|
||||
this.saturationActionTopic = `${this.actionTopicPre}/1/SATURATION`
|
||||
this.colorTemperatureActionTopic = `${this.actionTopicPre}/1/COLOR_TEMPERATURE`
|
||||
this.stateDeviceTopic = `${this.deviceTopicPre}/1/STATE`
|
||||
this.brightDeviceTopic = `${this.deviceTopicPre}/1/FAST_BRIGHTNESS`
|
||||
this.hueDeviceTopic = `${this.deviceTopicPre}/1/HUE`
|
||||
this.saturationDeviceTopic = `${this.deviceTopicPre}/1/SATURATION`
|
||||
this.colorTemperatureDeviceTopic = `${this.deviceTopicPre}/1/COLOR_TEMPERATURE`
|
||||
this.subscribeTopics = [
|
||||
this.stateTopic,
|
||||
this.brightTopic,
|
||||
this.colorTemperatureTopic,
|
||||
this.hueTopic,
|
||||
this.saturationTopic
|
||||
this.saturationTopic,
|
||||
this.stateDeviceTopic,
|
||||
this.brightDeviceTopic,
|
||||
this.colorTemperatureDeviceTopic,
|
||||
this.hueDeviceTopic,
|
||||
this.saturationDeviceTopic
|
||||
]
|
||||
this.state = 'OFF'
|
||||
this.bright = 0
|
||||
@ -90,26 +108,51 @@ export class HueColorBulbItem extends AHomegearItem implements HasStateAndFeedba
|
||||
mqttHandler.send(this.stateActionTopic, "false")
|
||||
}
|
||||
break
|
||||
case this.stateDeviceTopic:
|
||||
this.state = payload
|
||||
if (payload == "true") {
|
||||
this.state = "ON"
|
||||
} else {
|
||||
this.state = "OFF"
|
||||
}
|
||||
mqttHandler.send(this.stateFeedbackTopic, this.state)
|
||||
break
|
||||
case this.brightTopic:
|
||||
this.bright = parseFloat(payload)
|
||||
mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`)
|
||||
mqttHandler.send(this.brightActionTopic, `${this.bright * 2.54}`)
|
||||
mqttHandler.send(this.brightActionTopic, `${this.bright * this.BRIGHT_FACTOR}`)
|
||||
break
|
||||
case this.brightDeviceTopic:
|
||||
this.bright = parseFloat(payload) / this.BRIGHT_FACTOR
|
||||
mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`)
|
||||
break
|
||||
case this.hueTopic:
|
||||
this.hue = parseFloat(payload)
|
||||
mqttHandler.send(this.hueFeedbackTopic, `${this.hue}`)
|
||||
mqttHandler.send(this.hueActionTopic, `${this.hue * 65535.0 / 360.0}`)
|
||||
mqttHandler.send(this.hueActionTopic, `${this.hue * this.HUE_FACTOR}`)
|
||||
break
|
||||
case this.hueDeviceTopic:
|
||||
this.hue = parseFloat(payload) / this.HUE_FACTOR
|
||||
mqttHandler.send(this.hueFeedbackTopic, `${this.hue}`)
|
||||
break
|
||||
case this.saturationTopic:
|
||||
this.saturation = parseFloat(payload)
|
||||
mqttHandler.send(this.saturationFeedbackTopic, `${this.saturation}`)
|
||||
mqttHandler.send(this.saturationActionTopic, `${this.saturation * 2.54}`)
|
||||
mqttHandler.send(this.saturationActionTopic, `${this.saturation * this.SATURATION_FACTOR}`)
|
||||
break
|
||||
case this.saturationDeviceTopic:
|
||||
this.saturation = parseFloat(payload) / this.SATURATION_FACTOR
|
||||
mqttHandler.send(this.saturationFeedbackTopic, `${this.saturation}`)
|
||||
break
|
||||
case this.colorTemperatureTopic:
|
||||
this.colorTemperature = parseInt(payload)
|
||||
mqttHandler.send(this.colorTemperatureFeedbackTopic, `${this.colorTemperature}`)
|
||||
mqttHandler.send(this.colorTemperatureActionTopic, `${this.colorTemperature}`)
|
||||
break
|
||||
case this.colorTemperatureDeviceTopic:
|
||||
this.colorTemperature = parseInt(payload)
|
||||
mqttHandler.send(this.colorTemperatureFeedbackTopic, `${this.colorTemperature}`)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user