couple large and small basement light
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { ExportType } from './Export'
|
||||
import * as Events from 'events'
|
||||
|
||||
|
||||
|
||||
@ -20,7 +21,7 @@ export interface HasInTopic {
|
||||
getInTopic() : string
|
||||
}
|
||||
|
||||
export abstract class AItem {
|
||||
export abstract class AItem extends Events.EventEmitter {
|
||||
protected topicFirstPart: string
|
||||
protected itemId: string
|
||||
protected label: string
|
||||
@ -31,6 +32,7 @@ export abstract class AItem {
|
||||
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string = '') {
|
||||
super()
|
||||
this.floor = floor
|
||||
this.room = room
|
||||
this.item = item
|
||||
|
@ -22,6 +22,10 @@ export class HomematicSwitchItem extends AHomegearItem implements HasStateAndFee
|
||||
return this.stateFeedbackTopic
|
||||
}
|
||||
|
||||
getState() : string {
|
||||
return this.state
|
||||
}
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string, hmId: number, partId: number = 1, type: string = 'bulb') {
|
||||
super(floor, room, item, label, hmId)
|
||||
this.partId = partId
|
||||
@ -43,6 +47,7 @@ export class HomematicSwitchItem extends AHomegearItem implements HasStateAndFee
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) : void {
|
||||
this.emit('somethingChanged')
|
||||
switch (topic) {
|
||||
case this.stateTopic:
|
||||
this.state = payload
|
||||
|
@ -463,6 +463,13 @@ let basementLargeLight = new HomematicSwitchItem('Base', 'Hallway', 'LargeLight'
|
||||
basementLargeLight.start()
|
||||
allLabeledItems.push(basementLargeLight)
|
||||
allRelevantLights.push(basementLargeLight)
|
||||
basementLargeLight.on('somethingChange', () => {
|
||||
if (basementLargeLight.getState() == 'ON') {
|
||||
mqttHandler.send(basementSmallLight.getStateTopic(), 'ON')
|
||||
} else if (basementLargeLight.getState() == 'OFF') {
|
||||
mqttHandler.send(basementSmallLight.getStateTopic(), 'OFF')
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user