typescriptifying
This commit is contained in:
31
src/AItem.ts
Normal file
31
src/AItem.ts
Normal 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user