preset fix

This commit is contained in:
2018-04-06 23:38:08 +02:00
parent c503e31ee5
commit a5c629e331
8 changed files with 36 additions and 8 deletions

View File

@ -41,6 +41,10 @@ export abstract class AItem {
abstract processMessage(topic: string, payload: string) : void
startFunc() : void {
}
exportItem() : ExportType|null {
return null
}
@ -49,6 +53,6 @@ export abstract class AItem {
mqttHandler.register(this.subscribeTopics, (topic: string, payload: string) : void => {
// logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
this.processMessage(topic, payload)
})
}, () => { this.startFunc() })
}
}

View File

@ -61,7 +61,11 @@ export class MaxThermostat extends AHomegearItem implements HasInTopic {
}
setPresetTemperature(presetTemperature: number) {
this.processMessage(this.presetTemperatureTopic, `${presetTemperature}`)
this.presetTemperature = presetTemperature
}
startFunc() : void {
mqttHandler.send(this.presetTemperatureTopic, `${this.presetTemperature}`)
}
processMessage(topic: string, payload: string) : void {

View File

@ -7,6 +7,7 @@ import { IClientPublishOptions } from 'mqtt';
export type TopicCallbackFunc = (topic: string, payload: string) => void
export type StartCallbackFunc = () => void
export interface TopicHandler {
topic: string,
@ -14,11 +15,13 @@ export interface TopicHandler {
}
class MqttHandler {
private mqttClient: Mqtt.Client
private mqttOptions: Mqtt.IClientOptions = {}
private mqttBrokerUrl: string
private topicHandlers: TopicHandler[]
private startCallbacks: StartCallbackFunc[]
constructor() {
this.mqttBrokerUrl = config.dict.brokerUrl
@ -33,15 +36,17 @@ class MqttHandler {
}
this.topicHandlers = []
this.startCallbacks = []
logger.info("MqttHandler constructed")
}
register(topics: string[], cb: TopicCallbackFunc) : void {
register(topics: string[], cb: TopicCallbackFunc, startCb: StartCallbackFunc) : void {
topics.forEach((topic) => {
this.topicHandlers.push({topic: topic, callback: cb})
logger.info(`Callback registered for ${topic}`)
})
this.startCallbacks.push(startCb)
}
exec() : void {
@ -59,6 +64,10 @@ class MqttHandler {
logger.info(`${topicHandler.topic} subscribed`)
})
logger.info('MQTT connection established')
this.startCallbacks.forEach((cb) => {
cb()
logger.info("started")
})
})
this.mqttClient.on('message', (topic: string, payload: Buffer, packet : Mqtt.IPublishPacket): void => {
if (! packet.retain) {

View File

@ -288,7 +288,7 @@ allLabeledItems.push(windowContactBathroom1st)
let thermostatBathroom1st = new MaxThermostat('1st', 'Bathroom', 'Thermostat', 'Thermostat Bad oben', 3, [windowContactBathroom1st])
thermostatBathroom1st.start()
thermostatBedroom1st.setPresetTemperature(20.0)
thermostatBathroom1st.setPresetTemperature(20.0)
allLabeledItems.push(thermostatBathroom1st)
let thermostatBathroom1stCron = new Cron('thermostatBathroom1stCron', thermostatBathroom1st, [