Files
dispatcher_ng/src/AItem.ts

63 lines
1.5 KiB
TypeScript

import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { ExportType } from './Export'
export interface HasStateTopic {
getStateTopic() : string
}
export interface HasStateAndFeedbackTopic extends HasStateTopic {
getStateFeedbackTopic() : string
}
export interface HasFeedbackTopic {
getStateFeedbackTopic() : string
}
export interface HasInTopic {
getInTopic() : string
}
export abstract class AItem {
protected topicFirstPart: string
protected itemId: string
protected label: string
protected item: string
protected room: string
protected floor: string
protected subscribeTopics: string[]
constructor(floor: string, room: string, item: string, label: string = '') {
this.floor = floor
this.room = room
this.item = item
this.itemId = `${this.floor}_${this.room}_${this.item}`
if (label == '') {
this.label = this.itemId
} else {
this.label = label
}
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`
}
abstract processMessage(topic: string, payload: string) : void
startFunc() : void {
}
exportItem() : ExportType|null {
return null
}
start() : void {
mqttHandler.register(this.subscribeTopics, (topic: string, payload: string) : void => {
// logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
this.processMessage(topic, payload)
}, () => { this.startFunc() })
}
}