Scene implemented
This commit is contained in:
85
dist/Scene.js
vendored
Normal file
85
dist/Scene.js
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const AItem_1 = require("./AItem");
|
||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
const Export_1 = require("./Export");
|
||||
class LightScene extends AItem_1.AItem {
|
||||
constructor(floor, room, item, label = '', onItems, offItems) {
|
||||
super(floor, room, item, label);
|
||||
this.onItems = onItems;
|
||||
this.offItems = offItems;
|
||||
this.stateTopic = `${this.topicFirstPart}/state`;
|
||||
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
|
||||
this.subscribeTopics = [];
|
||||
this.subscribeTopics.push(this.stateTopic);
|
||||
this.onFeedbackTopics = [];
|
||||
this.onTopics = [];
|
||||
this.onFeedbackMap = {};
|
||||
this.onItems.forEach((item) => {
|
||||
this.subscribeTopics.push(item.getStateFeedbackTopic());
|
||||
this.onFeedbackTopics.push(item.getStateFeedbackTopic());
|
||||
this.onTopics.push(item.getStateTopic());
|
||||
this.onFeedbackMap[item.getStateFeedbackTopic()] = '-';
|
||||
});
|
||||
this.offFeedbackTopics = [];
|
||||
this.offTopics = [];
|
||||
this.offFeedbackMap = {};
|
||||
this.offItems.forEach((item) => {
|
||||
this.subscribeTopics.push(item.getStateFeedbackTopic());
|
||||
this.offFeedbackTopics.push(item.getStateFeedbackTopic());
|
||||
this.offTopics.push(item.getStateTopic());
|
||||
this.offFeedbackMap[item.getStateFeedbackTopic()] = '-';
|
||||
});
|
||||
this.state = 'OFF';
|
||||
this.myLastFeedbackState = '-';
|
||||
}
|
||||
exportItem() {
|
||||
return Export_1.SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, 'Switch');
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
if (topic == this.stateTopic) {
|
||||
this.state = payload;
|
||||
if (this.state == 'ON') {
|
||||
this.onTopics.forEach((topic2) => {
|
||||
MqttDispatcher_1.mqttHandler.send(topic2, 'ON');
|
||||
});
|
||||
this.offTopics.forEach((topic2) => {
|
||||
MqttDispatcher_1.mqttHandler.send(topic2, 'OFF');
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.onTopics.forEach((topic2) => {
|
||||
MqttDispatcher_1.mqttHandler.send(topic2, 'OFF');
|
||||
});
|
||||
this.offTopics.forEach((topic2) => {
|
||||
MqttDispatcher_1.mqttHandler.send(topic2, 'OFF');
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (this.onFeedbackTopics.some((x) => { return x == topic; })) {
|
||||
let feedbackState = payload;
|
||||
this.onFeedbackMap[topic] = feedbackState;
|
||||
}
|
||||
else if (this.offFeedbackTopics.some((x) => { return x == topic; })) {
|
||||
let feedbackState = payload;
|
||||
this.offFeedbackMap[topic] = feedbackState;
|
||||
}
|
||||
let myFeedbackState = 'ON';
|
||||
Object.values(this.onFeedbackMap).forEach((v) => {
|
||||
if (v != 'ON') {
|
||||
myFeedbackState = 'OFF';
|
||||
}
|
||||
});
|
||||
Object.values(this.offFeedbackMap).forEach((v) => {
|
||||
if (v != 'OFF') {
|
||||
myFeedbackState = 'OFF';
|
||||
}
|
||||
});
|
||||
if (myFeedbackState != this.myLastFeedbackState) {
|
||||
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, myFeedbackState);
|
||||
this.myLastFeedbackState = myFeedbackState;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.LightScene = LightScene;
|
||||
//# sourceMappingURL=Scene.js.map
|
3
dist/main.js
vendored
3
dist/main.js
vendored
@ -11,6 +11,7 @@ const TimerAdaptor_1 = require("./TimerAdaptor");
|
||||
const HomematicDimmerItem_1 = require("./HomematicDimmerItem");
|
||||
const HomematicSwitchItem_1 = require("./HomematicSwitchItem");
|
||||
const Forwarder_1 = require("./Forwarder");
|
||||
const Scene_1 = require("./Scene");
|
||||
logger.info("Dispatcher starting");
|
||||
let allLabeledItems = new Array();
|
||||
// Anna -----------------------------------------------------------------------------------------------------
|
||||
@ -156,6 +157,8 @@ let testForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'TestForwarder',
|
||||
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
|
||||
]);
|
||||
testForwarder.start();
|
||||
let testScene = new Scene_1.LightScene('Gnd', 'Hallway', 'TestScene', 'TestScene', [aquariumLight, annaBedLight], [matthiasStandLights, matthiasBedLight]);
|
||||
testScene.start();
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// Homekit export
|
||||
let homekitObject = {};
|
||||
|
Reference in New Issue
Block a user