typescriptifying

This commit is contained in:
Wolfgang Hottgenroth
2018-01-09 16:36:14 +01:00
parent 9e39d74084
commit 8d85314fc9
21 changed files with 372 additions and 182 deletions

31
src/AItem.ts Normal file
View File

@ -0,0 +1,31 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
export abstract class AItem {
protected topicFirstPart: string;
private itemId: string;
private item: string;
private room: string;
private floor: string
protected subscribeTopics: string[]
constructor(floor: string, room: string, item: string) {
this.floor = floor
this.room = room
this.item = item
this.itemId = `${this.floor}.${this.room}.${this.item}`
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`
}
abstract processMessage(topic: string, payload: string) : void
start() : void {
mqttHandler.register(this.subscribeTopics, (topic: string, payload: string) : void => {
logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
this.processMessage(topic, payload)
})
}
}