relaybox stuff
This commit is contained in:
42
dist/RelayBox.js
vendored
Normal file
42
dist/RelayBox.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const logger = require("./log");
|
||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
const AItem_1 = require("./AItem");
|
||||
class RelayBoxThing extends AItem_1.AItem {
|
||||
constructor(floor, room, item, deviceCommandTopic, deviceStatusTopic, itemNames) {
|
||||
super(floor, room, item, '');
|
||||
this.itemNames = itemNames;
|
||||
this.deviceCommandTopic = deviceCommandTopic;
|
||||
this.deviceStatusTopic = deviceStatusTopic;
|
||||
this.stateTopicPre = `${this.topicFirstPart}/state`;
|
||||
this.subscribeTopics = [
|
||||
`${this.deviceStatusTopic}`,
|
||||
`${this.stateTopicPre}/#`
|
||||
];
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
logger.info(`RT: ${topic}, ${payload}`);
|
||||
if (topic == this.deviceStatusTopic) {
|
||||
logger.info(`RT: status received`);
|
||||
}
|
||||
else {
|
||||
let thingRelatedPart = topic.substring(this.stateTopicPre.length + 1);
|
||||
let itemIdx = parseInt(thingRelatedPart);
|
||||
logger.info(`RT: pre: ${this.stateTopicPre}, thingRelatedPart: ${thingRelatedPart}, itemIdx: ${itemIdx}`);
|
||||
if (itemIdx >= 0 && itemIdx < this.itemNames.length) {
|
||||
if (payload == 'ON') {
|
||||
MqttDispatcher_1.mqttHandler.send(this.deviceCommandTopic, `switch ${itemIdx} on`);
|
||||
}
|
||||
else {
|
||||
MqttDispatcher_1.mqttHandler.send(this.deviceCommandTopic, `switch ${itemIdx} off`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.warn(`RT: no handling available for ${topic}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.RelayBoxThing = RelayBoxThing;
|
||||
//# sourceMappingURL=RelayBox.js.map
|
6
dist/main.js
vendored
6
dist/main.js
vendored
@ -19,6 +19,7 @@ const UrlSwitchItem_1 = require("./UrlSwitchItem");
|
||||
const Cron_1 = require("./Cron");
|
||||
const HueColorBulbItem_1 = require("./HueColorBulbItem");
|
||||
const TouchSwitchMultiButtonThing_1 = require("./TouchSwitchMultiButtonThing");
|
||||
const RelayBox_1 = require("./RelayBox");
|
||||
logger.info("Dispatcher starting");
|
||||
let allLabeledItems = new Array();
|
||||
// Anna -----------------------------------------------------------------------------------------------------
|
||||
@ -249,6 +250,11 @@ let thermostatKitchenCron = new Cron_1.Cron('thermostatKitchenCron', thermostatK
|
||||
]);
|
||||
thermostatKitchenCron.start();
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let relayBox = new RelayBox_1.RelayBoxThing('base', 'labor', 'relaybox', 'IoT/Command/RelayBox', 'IoT/Status/RelayBox', [
|
||||
"Küche", "Herd", "Waschküche", "Licht Keller", "Licht EG", "Licht OG"
|
||||
]);
|
||||
relayBox.start();
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let testFourButton = new HomematicFourButtonThing_1.HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
||||
new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
||||
new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
|
||||
|
@ -1,28 +0,0 @@
|
||||
let mqtt = require('./mqttHandler');
|
||||
let logger = require('./log');
|
||||
|
||||
|
||||
|
||||
class Switch {
|
||||
|
||||
}
|
||||
|
||||
class RelayBox {
|
||||
constructor(switches) {
|
||||
this.switches = switches;
|
||||
|
||||
}
|
||||
|
||||
start() {
|
||||
mqtt.register(this.subscribeTopics, (topic, payload) => {
|
||||
logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
|
||||
this.processMessage(topic, payload);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RelayBox,
|
||||
Switch
|
||||
};
|
||||
|
47
src/RelayBox.ts
Normal file
47
src/RelayBox.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AItem } from './AItem'
|
||||
|
||||
|
||||
|
||||
export class RelayBoxThing extends AItem {
|
||||
private itemNames: string[]
|
||||
private readonly deviceCommandTopic: string
|
||||
private readonly deviceStatusTopic: string
|
||||
private readonly stateTopicPre: string
|
||||
|
||||
constructor(floor: string, room: string, item: string, deviceCommandTopic: string,
|
||||
deviceStatusTopic: string, itemNames: string[]) {
|
||||
super(floor, room, item, '')
|
||||
this.itemNames = itemNames
|
||||
this.deviceCommandTopic = deviceCommandTopic
|
||||
this.deviceStatusTopic = deviceStatusTopic
|
||||
this.stateTopicPre = `${this.topicFirstPart}/state`
|
||||
this.subscribeTopics = [
|
||||
`${this.deviceStatusTopic}`,
|
||||
`${this.stateTopicPre}/#`
|
||||
]
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) {
|
||||
logger.info(`RT: ${topic}, ${payload}`)
|
||||
if (topic == this.deviceStatusTopic) {
|
||||
logger.info(`RT: status received`)
|
||||
} else {
|
||||
let thingRelatedPart = topic.substring(this.stateTopicPre.length+1)
|
||||
let itemIdx = parseInt(thingRelatedPart)
|
||||
logger.info(`RT: pre: ${this.stateTopicPre}, thingRelatedPart: ${thingRelatedPart}, itemIdx: ${itemIdx}`)
|
||||
if (itemIdx >= 0 && itemIdx < this.itemNames.length) {
|
||||
if (payload == 'ON') {
|
||||
mqttHandler.send(this.deviceCommandTopic, `switch ${itemIdx} on`)
|
||||
} else {
|
||||
mqttHandler.send(this.deviceCommandTopic, `switch ${itemIdx} off`)
|
||||
}
|
||||
} else {
|
||||
logger.warn(`RT: no handling available for ${topic}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ import { UrlSwitchItem } from './UrlSwitchItem'
|
||||
import { Cron } from './Cron'
|
||||
import { HueColorBulbItem } from './HueColorBulbItem'
|
||||
import { TouchSwitchMultiButtonThing, TouchSwitchButtonSingleItem } from './TouchSwitchMultiButtonThing'
|
||||
import { RelayBoxThing } from './RelayBox'
|
||||
|
||||
|
||||
logger.info("Dispatcher starting")
|
||||
|
||||
@ -319,6 +321,12 @@ let thermostatKitchenCron = new Cron('thermostatKitchenCron', thermostatKitchen,
|
||||
])
|
||||
thermostatKitchenCron.start()
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let relayBox = new RelayBoxThing('base', 'labor', 'relaybox', 'IoT/Command/RelayBox', 'IoT/Status/RelayBox', [
|
||||
"Küche", "Herd", "Waschküche", "Licht Keller", "Licht EG", "Licht OG"
|
||||
])
|
||||
relayBox.start()
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
||||
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
||||
|
Reference in New Issue
Block a user