switch adaptor
This commit is contained in:
@ -1,12 +1,18 @@
|
||||
import { AItem } from './AItem'
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { HasInTopic } from './AItem';
|
||||
|
||||
|
||||
export class Forwarder extends AItem {
|
||||
export class Forwarder extends AItem implements HasInTopic {
|
||||
private targetTopics: string[]
|
||||
private inTopic: string
|
||||
|
||||
getInTopic() : string {
|
||||
return this.inTopic
|
||||
}
|
||||
|
||||
|
||||
constructor(floor: string, room: string, item: string, topicLastPart: string, label: string, targetTopics: string[]) {
|
||||
super(floor, room, item, label)
|
||||
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`
|
||||
|
41
src/SwitchAdaptor.ts
Normal file
41
src/SwitchAdaptor.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { AItem, HasInTopic } from './AItem'
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
|
||||
export class SwitchAdaptor extends AItem implements HasInTopic {
|
||||
private state: string
|
||||
private inTopic: string
|
||||
private actionStateTopic: string
|
||||
|
||||
constructor(floor: string, room: string, item: string) {
|
||||
super(floor, room, item)
|
||||
this.actionStateTopic = `${this.topicFirstPart}/state`
|
||||
this.inTopic = `${this.topicFirstPart}/in`
|
||||
this.subscribeTopics = [ this.inTopic ]
|
||||
this.state = 'OFF'
|
||||
}
|
||||
|
||||
getInTopic() : string {
|
||||
return this.inTopic
|
||||
}
|
||||
|
||||
|
||||
processMessage(topic: string, payload: string) : void {
|
||||
switch (topic) {
|
||||
case this.inTopic:
|
||||
switch (payload) {
|
||||
case 'SHORT':
|
||||
if (this.state == 'OFF') {
|
||||
this.state = 'ON'
|
||||
} else {
|
||||
this.state = 'OFF'
|
||||
}
|
||||
mqttHandler.send(this.actionStateTopic, this.state, true)
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
14
src/main.ts
14
src/main.ts
@ -10,6 +10,7 @@ import { M433SwitchItem } from './M433SwitchItem'
|
||||
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
|
||||
import { DimmerAdaptor } from './DimmerAdaptor'
|
||||
import { TimerAdaptor } from './TimerAdaptor'
|
||||
import { SwitchAdaptor } from './SwitchAdaptor'
|
||||
import { HomematicDimmerItem } from './HomematicDimmerItem'
|
||||
import { HomematicSwitchItem } from './HomematicSwitchItem'
|
||||
import { Forwarder } from './Forwarder'
|
||||
@ -481,6 +482,17 @@ basementLargeLight.on('somethingChanged', () => {
|
||||
})
|
||||
|
||||
|
||||
let basementForwarder = new Forwarder('Base', 'All', 'Forwarder', 'state', 'BasementForwarder', [
|
||||
basementLargeLight.getState(),
|
||||
basementSmallLight.getState(),
|
||||
workshopLight.getState()
|
||||
])
|
||||
basementForwarder.start()
|
||||
|
||||
|
||||
let basementForwarderSwitchAdaptor = new SwitchAdaptor('Base', 'All', 'Forwarder')
|
||||
basementForwarderSwitchAdaptor.start()
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let twoLedSignal1 = new TwoLedSignal('Gnd', 'Hallway', 'TwoLedSignal1', 'Licht- und Fenster-Anzeiger',
|
||||
allRelevantLights, "OFF", "ON",
|
||||
@ -490,7 +502,7 @@ twoLedSignal1.start()
|
||||
// MySwitchTHing
|
||||
let mySwitchThingWolfgang = new MySwitchThing('1st', 'BedRoom', 'WolfgangsSwitch', [
|
||||
new MySwitchSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic()),
|
||||
new MySwitchSingleItem('IoT/InsLeere/1'),
|
||||
new MySwitchSingleItem(basementForwarderSwitchAdaptor.getInTopic()),
|
||||
new MySwitchSingleItem('IoT/InsLeere/2'),
|
||||
])
|
||||
mySwitchThingWolfgang.start()
|
||||
|
Reference in New Issue
Block a user