add all existing items, homekit export
This commit is contained in:
15
src/AItem.ts
15
src/AItem.ts
@ -1,26 +1,37 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { HomekitExportType } from './Export'
|
||||
|
||||
|
||||
export abstract class AItem {
|
||||
protected topicFirstPart: string
|
||||
protected itemId: string
|
||||
protected label: string
|
||||
private item: string
|
||||
private room: string
|
||||
private floor: string
|
||||
protected subscribeTopics: string[]
|
||||
|
||||
|
||||
constructor(floor: string, room: string, item: 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
|
||||
|
||||
exportHomekit() : HomekitExportType {
|
||||
return {'id': this.itemId, 'object': null }
|
||||
}
|
||||
|
||||
start() : void {
|
||||
mqttHandler.register(this.subscribeTopics, (topic: string, payload: string) : void => {
|
||||
logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
|
||||
@ -28,5 +39,3 @@ export abstract class AItem {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user