TwoLedSignal stuff
This commit is contained in:
@ -1,12 +1,48 @@
|
||||
import { AItem, HasFeedbackTopic } from './AItem'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import * as logger from './log'
|
||||
|
||||
export class HeatingScene extends AItem {
|
||||
private led1Topics: string[] = []
|
||||
private led2Topics: string[] = []
|
||||
private led1GreenToken: string
|
||||
private led1RedToken: string
|
||||
private led2GreenToken: string
|
||||
private led2RedToken: string
|
||||
enum SignalState {
|
||||
SIGNAL_RED,
|
||||
SIGNAL_GREEN,
|
||||
SIGNAL_UNKNOWN,
|
||||
}
|
||||
|
||||
class SignalItem {
|
||||
private item: HasFeedbackTopic
|
||||
private signalState: SignalState
|
||||
private redToken: string
|
||||
private greenToken: string
|
||||
|
||||
constructor(item: HasFeedbackTopic, redToken: string, greenToken: string) {
|
||||
this.item = item
|
||||
this.signalState = SignalState.SIGNAL_UNKNOWN
|
||||
this.redToken = redToken
|
||||
this.greenToken = greenToken
|
||||
}
|
||||
|
||||
getSignalState() : SignalState {
|
||||
return this.signalState
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string): void {
|
||||
if (topic == this.item.getStateFeedbackTopic()) {
|
||||
logger.info(`${topic}, ${payload}`)
|
||||
if (payload == this.greenToken) {
|
||||
this.signalState = SignalState.SIGNAL_GREEN
|
||||
} else if (payload == this.redToken) {
|
||||
this.signalState = SignalState.SIGNAL_RED
|
||||
} else {
|
||||
this.signalState = SignalState.SIGNAL_UNKNOWN
|
||||
}
|
||||
// logger.info(`DBG: SignalItem: ${topic}, ${payload}, ${this.signalState}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class TwoLedSignal extends AItem {
|
||||
private led1Items: SignalItem[] = []
|
||||
private led2Items: SignalItem[] = []
|
||||
|
||||
constructor(floor: string, room: string, item: string, label: string,
|
||||
led1Items: HasFeedbackTopic[], led1GreenToken: string, led1RedToken: string,
|
||||
@ -16,23 +52,39 @@ export class HeatingScene extends AItem {
|
||||
|
||||
this.subscribeTopics = []
|
||||
led1Items.forEach((item: HasFeedbackTopic) => {
|
||||
this.led1Topics.push(item.getStateFeedbackTopic())
|
||||
this.led1Items.push(new SignalItem(item, led1RedToken, led1GreenToken))
|
||||
this.subscribeTopics.push(item.getStateFeedbackTopic())
|
||||
})
|
||||
led2Items.forEach((item: HasFeedbackTopic) => {
|
||||
this.led2Topics.push(item.getStateFeedbackTopic())
|
||||
this.led2Items.push(new SignalItem(item, led2RedToken, led2GreenToken))
|
||||
this.subscribeTopics.push(item.getStateFeedbackTopic())
|
||||
})
|
||||
|
||||
this.led1GreenToken = led1GreenToken
|
||||
this.led1RedToken = led1RedToken
|
||||
this.led2GreenToken = led2GreenToken
|
||||
this.led2RedToken = led2RedToken
|
||||
|
||||
}
|
||||
|
||||
|
||||
processMessage(topic: string, payload: string) : void {
|
||||
let reds : number = 0
|
||||
const RED_VALUES : SignalState[] = [SignalState.SIGNAL_RED, SignalState.SIGNAL_UNKNOWN]
|
||||
|
||||
this.led1Items.forEach((item: SignalItem) => {
|
||||
item.processMessage(topic, payload)
|
||||
if (RED_VALUES.indexOf(item.getSignalState()) != -1) {
|
||||
reds++
|
||||
}
|
||||
// logger.info(`DBG: TwoLedSignal ${item.getSignalState()}, ${reds}`)
|
||||
})
|
||||
let msg = (reds > 0) ? "RED" : "GREEN"
|
||||
mqttHandler.send(`${this.topicFirstPart}/led1`, msg)
|
||||
|
||||
reds = 0
|
||||
this.led2Items.forEach((item: SignalItem) => {
|
||||
item.processMessage(topic, payload)
|
||||
if (RED_VALUES.indexOf(item.getSignalState()) != -1) {
|
||||
reds++
|
||||
}
|
||||
// logger.info(`DBG: TwoLedSignal ${item.getSignalState()}, ${reds}`)
|
||||
})
|
||||
msg = (reds > 0) ? "RED" : "GREEN"
|
||||
mqttHandler.send(`${this.topicFirstPart}/led2`, msg)
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ export class UrlSwitchItem extends AItem implements HasStateAndFeedbackTopic {
|
||||
mqttHandler.send(this.stateFeedbackTopic, this.state);
|
||||
if (this.state != this.oldState) {
|
||||
if (this.state == 'ON') {
|
||||
http.get(this.onUrl)
|
||||
http.get(this.onUrl,)
|
||||
} else {
|
||||
http.get(this.offUrl)
|
||||
}
|
||||
|
36
src/main.ts
36
src/main.ts
@ -23,13 +23,14 @@ import { HueColorBulbItem } from './HueColorBulbItem'
|
||||
import { TouchSwitchMultiButtonThing, TouchSwitchButtonSingleItem } from './TouchSwitchMultiButtonThing'
|
||||
import { RelayBoxThing } from './RelayBox'
|
||||
import { HeatingScene } from './HeatingScene'
|
||||
|
||||
import { TwoLedSignal } from './TwoLedSignal'
|
||||
|
||||
logger.info("Dispatcher starting")
|
||||
|
||||
let allLabeledItems : Array<AItem> = new Array()
|
||||
let allThermostatItems : Array<HasInTopic> = new Array()
|
||||
let allWindows : Array<HasFeedbackTopic> = new Array()
|
||||
let allRelevantLights: Array<HasFeedbackTopic> = new Array()
|
||||
|
||||
|
||||
// Anna -----------------------------------------------------------------------------------------------------
|
||||
@ -53,7 +54,7 @@ aquariumLightCron.start()
|
||||
let annaBedLight = new M433SwitchItem('1st', 'Anna', 'BedLight', 'Bettlicht Anna', '14668116 24 1', '14668113 24 1')
|
||||
annaBedLight.start()
|
||||
allLabeledItems.push(annaBedLight)
|
||||
|
||||
allRelevantLights.push(annaBedLight)
|
||||
|
||||
let windowContactAnna1st = new MaxWindowContact('1st', 'Anna', 'WindowContact', 'Fenster Anna', 20)
|
||||
windowContactAnna1st.start()
|
||||
@ -84,16 +85,20 @@ thermostatAnna1stCron.start()
|
||||
let matthiasStandLights = new M433SwitchItem('1st', 'Matthias', 'StandLight', 'Stehlampen Matthias', '7 24 1', '6 24 1')
|
||||
matthiasStandLights.start()
|
||||
allLabeledItems.push(matthiasStandLights)
|
||||
allRelevantLights.push(matthiasStandLights)
|
||||
|
||||
|
||||
// Matthias Bett 15 24 1 14 24 1
|
||||
let matthiasBedLight = new M433SwitchItem('1st', 'Matthias', 'BedLight', 'Bettlicht Matthias', '15 24 1', '14 24 1')
|
||||
matthiasBedLight.start()
|
||||
allLabeledItems.push(matthiasBedLight)
|
||||
allRelevantLights.push(matthiasBedLight)
|
||||
|
||||
// Matthias Lautsprecher 11 24 1 10 24 1
|
||||
let matthiasSpeaker = new M433SwitchItem('1st', 'Matthias', 'Speaker', 'Lautsprecher Matthias', '11 24 1', '10 24 1', 'outlet')
|
||||
matthiasSpeaker.start()
|
||||
allLabeledItems.push(matthiasSpeaker)
|
||||
allRelevantLights.push(matthiasSpeaker)
|
||||
|
||||
let windowContactMatthias = new MaxWindowContact('1st', 'Matthias', 'WindowContact', 'Fenster', 24)
|
||||
windowContactMatthias.start()
|
||||
@ -107,46 +112,55 @@ allWindows.push(windowContactMatthias)
|
||||
let diningRoomSmallLight = new M433SwitchItem('Gnd', 'DiningRoom', 'SmallLight', 'kleine Lampe Esszimmer', '69653 24 1', '69652 24 1')
|
||||
diningRoomSmallLight.start()
|
||||
allLabeledItems.push(diningRoomSmallLight)
|
||||
allRelevantLights.push(diningRoomSmallLight)
|
||||
|
||||
// Esszimmer Stehlampe 86037 24 1 86036 24 1
|
||||
let diningRoomStandLight = new M433SwitchItem('Gnd', 'DiningRoom', 'StandLight', 'Stehlampe Esszimmer', '86037 24 1', '86036 24 1')
|
||||
diningRoomStandLight.start()
|
||||
allLabeledItems.push(diningRoomStandLight)
|
||||
allRelevantLights.push(diningRoomStandLight)
|
||||
|
||||
// Esszimmer Schranklicht 65813 24 1 65812 24 1
|
||||
let diningRoomCupboardLight = new M433SwitchItem('Gnd', 'DiningRoom', 'CupboardLight', 'Schranklicht Esszimmer', '65813 24 1', '65812 24 1')
|
||||
diningRoomCupboardLight.start()
|
||||
allLabeledItems.push(diningRoomCupboardLight)
|
||||
allRelevantLights.push(diningRoomCupboardLight)
|
||||
|
||||
// Esszimmer Regallicht
|
||||
let diningRoomShelfLight = new UrlSwitchItem('Gnd', 'DiningRoom', 'ShelfLight', 'Regallicht Esszimmer', 'http://regallampe/dv?dv=1023', 'http://regallampe/dv?dv=0')
|
||||
diningRoomShelfLight.start()
|
||||
allLabeledItems.push(diningRoomShelfLight)
|
||||
allRelevantLights.push(diningRoomShelfLight)
|
||||
|
||||
let diningRoomNaehkaestchenLight = new HueColorBulbItem('Gnd', 'DiningRoom', 'NaehkaestchenLight', 'Lampe Naehkaestchen', 15)
|
||||
diningRoomNaehkaestchenLight.start()
|
||||
allLabeledItems.push(diningRoomNaehkaestchenLight)
|
||||
allRelevantLights.push(diningRoomNaehkaestchenLight)
|
||||
|
||||
// Wohnzimmer -----------------------------------------------------------------------------------------------
|
||||
// Wohnzimmer grosse Lampe 65557 24 1 65556 24 1
|
||||
let livingRoomLargeLight = new M433SwitchItem('Gnd', 'LivingRoom', 'LargeLight', 'große Lampe Wohnzimmer', '65557 24 1', '65556 24 1')
|
||||
livingRoomLargeLight.start()
|
||||
allLabeledItems.push(livingRoomLargeLight)
|
||||
allRelevantLights.push(livingRoomLargeLight)
|
||||
|
||||
// Wohnzimmer kleine Lampe 87061 24 1 87060 24 1
|
||||
let livingRoomSmallLight = new M433SwitchItem('Gnd', 'LivingRoom', 'SmallLight', 'kleine Lampe Wohnzimmer', '87061 24 1', '87060 24 1')
|
||||
livingRoomSmallLight.start()
|
||||
allLabeledItems.push(livingRoomSmallLight)
|
||||
allRelevantLights.push(livingRoomSmallLight)
|
||||
|
||||
// Wohnzimmer Sterne 69909 24 1 69908 24 1
|
||||
let livingRoomStars = new M433SwitchItem('Gnd', 'LivingRoom', 'Stars', 'Sterne Wohnzimmer', '69909 24 1', '69908 24 1')
|
||||
livingRoomStars.start()
|
||||
allLabeledItems.push(livingRoomStars)
|
||||
allRelevantLights.push(livingRoomStars)
|
||||
|
||||
// Wohnzimmer kleine Stehlampe 81941 24 1 81940 24 1
|
||||
let livingRoomStandLight = new M433SwitchItem('Gnd', 'LivingRoom', 'StandLight', 'Stehlampe Wohnzimmer', '81941 24 1', '81940 24 1')
|
||||
livingRoomStandLight.start()
|
||||
allLabeledItems.push(livingRoomStandLight)
|
||||
allRelevantLights.push(livingRoomStandLight)
|
||||
|
||||
|
||||
// Flur -----------------------------------------------------------------------------------------------------
|
||||
@ -154,16 +168,19 @@ allLabeledItems.push(livingRoomStandLight)
|
||||
let hallwayDeskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', 'Schreibtischlampe Flur', '83221 24 1', '83220 24 1')
|
||||
hallwayDeskLight.start()
|
||||
allLabeledItems.push(hallwayDeskLight)
|
||||
allRelevantLights.push(hallwayDeskLight)
|
||||
|
||||
// Flur Stehlampe 8704914 24 5 8793154 24 5
|
||||
let hallwayStandLight = new M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Stehlampe Flur', '8704914 24 5', '8793154 24 5')
|
||||
hallwayStandLight.start()
|
||||
allLabeledItems.push(hallwayStandLight)
|
||||
allRelevantLights.push(hallwayStandLight)
|
||||
|
||||
// Flur Schranklicht 66581 24 1 66580 24 1
|
||||
let hallwayWardrobeLight = new M433SwitchItem('Gnd', 'Hallway', 'WardrobeLight', 'Schranklicht Flur', '66581 24 1', '66580 24 1')
|
||||
hallwayWardrobeLight.start()
|
||||
allLabeledItems.push(hallwayWardrobeLight)
|
||||
allRelevantLights.push(hallwayWardrobeLight)
|
||||
|
||||
|
||||
// Küche ----------------------------------------------------------------------------------------------------
|
||||
@ -171,11 +188,13 @@ allLabeledItems.push(hallwayWardrobeLight)
|
||||
let kitchenWindowLight = new M433SwitchItem('Gnd', 'Kitchen', 'WindowLight', 'Fensterbanklicht Küche', '66837 24 1', '66836 24 1')
|
||||
kitchenWindowLight.start()
|
||||
allLabeledItems.push(kitchenWindowLight)
|
||||
allRelevantLights.push(kitchenWindowLight)
|
||||
|
||||
// Küche Deckenlampe 82197 24 1 82196 24 1
|
||||
let kitchenCeilingLight = new M433SwitchItem('Gnd', 'Kitchen', 'CeilingLight', 'Deckenlampe Küche', '82197 24 1', '82196 24 1')
|
||||
kitchenCeilingLight.start()
|
||||
allLabeledItems.push(kitchenCeilingLight)
|
||||
allRelevantLights.push(kitchenCeilingLight)
|
||||
|
||||
|
||||
// Schlafzimmer ---------------------------------------------------------------------------------------------
|
||||
@ -183,10 +202,12 @@ allLabeledItems.push(kitchenCeilingLight)
|
||||
let bedRoomWolfgangsSide = new M433SwitchItem('1st', 'BedRoom', 'WolfgangsSide', 'Wolfgangs Seite Schlafzimmer', '13976916 24 1', '13976913 24 1')
|
||||
bedRoomWolfgangsSide.start()
|
||||
allLabeledItems.push(bedRoomWolfgangsSide)
|
||||
allRelevantLights.push(bedRoomWolfgangsSide)
|
||||
|
||||
let bedRoomWolfgangBedLight = new HueColorBulbItem('1st', 'BedRoom', 'WolfgangBedLight', 'Bettlicht', 16)
|
||||
bedRoomWolfgangBedLight.start()
|
||||
allLabeledItems.push(bedRoomWolfgangBedLight)
|
||||
allRelevantLights.push(bedRoomWolfgangBedLight)
|
||||
|
||||
let bedRoomWolfgangBedLightDimmerAdaptor = new DimmerAdaptor('1st', 'BedRoom', 'WolfgangBedLight')
|
||||
bedRoomWolfgangBedLightDimmerAdaptor.start()
|
||||
@ -199,11 +220,13 @@ touchSwitchMultiButtonThing.start()
|
||||
let bedRoomPattysSide = new M433SwitchItem('1st', 'BedRoom', 'PattysSide', 'Pattys Seite Schlafzimmer', '13980756 24 1', '13980753 24 1')
|
||||
bedRoomPattysSide.start()
|
||||
allLabeledItems.push(bedRoomPattysSide)
|
||||
allRelevantLights.push(bedRoomPattysSide)
|
||||
|
||||
// Schlafzimmer Fensterbank 13979988 24 1 13979985 24 1
|
||||
let bedRoomWindowLight = new M433SwitchItem('1st', 'BedRoom', 'WindowLight', 'Fensterbanklicht Schlafzimmer', '13979988 24 1', '13979985 24 1')
|
||||
bedRoomWindowLight.start()
|
||||
allLabeledItems.push(bedRoomWindowLight)
|
||||
allRelevantLights.push(bedRoomWindowLight)
|
||||
|
||||
|
||||
|
||||
@ -375,6 +398,14 @@ allLabeledItems.push(relayBox)
|
||||
let heatingSceneAll = new HeatingScene('Gnd', 'House', 'Heatings', 'Alle Heizungen', allThermostatItems)
|
||||
heatingSceneAll.start()
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let twoLedSignal1 = new TwoLedSignal('Gnd', 'Hallway', 'TwoLedSignal1', 'Licht- und Fenster-Anzeiger',
|
||||
allRelevantLights, "OFF", "ON",
|
||||
allWindows, "CLOSED", "OPEN")
|
||||
twoLedSignal1.start()
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
||||
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
||||
@ -450,4 +481,3 @@ fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n'))
|
||||
mqttHandler.exec()
|
||||
logger.info("Dispatcher running")
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user