typescriptifying completed
This commit is contained in:
20
src/Forwarder.js → dist/Forwarder.js
vendored
20
src/Forwarder.js → dist/Forwarder.js
vendored
@ -1,25 +1,23 @@
|
|||||||
let AItem = require('./AItem')
|
"use strict";
|
||||||
let logger = require('./log')
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
let mqtt = require('./mqttHandler');
|
const AItem_1 = require("./AItem");
|
||||||
|
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||||
|
class Forwarder extends AItem_1.AItem {
|
||||||
class Forwarder extends AItem {
|
|
||||||
constructor(floor, room, item, topicLastPart, targetTopics) {
|
constructor(floor, room, item, topicLastPart, targetTopics) {
|
||||||
super(floor, room, item);
|
super(floor, room, item);
|
||||||
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`;
|
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`;
|
||||||
this.subscribeTopics = [ this.inTopic ];
|
this.subscribeTopics = [this.inTopic];
|
||||||
this.targetTopics = targetTopics;
|
this.targetTopics = targetTopics;
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessage(topic, payload) {
|
processMessage(topic, payload) {
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
case this.inTopic:
|
case this.inTopic:
|
||||||
this.targetTopics.forEach((targetTopic) => {
|
this.targetTopics.forEach((targetTopic) => {
|
||||||
mqtt.send(targetTopic, payload, true);
|
MqttDispatcher_1.mqttHandler.send(targetTopic, payload, true);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exports.Forwarder = Forwarder;
|
||||||
module.exports = Forwarder;
|
//# sourceMappingURL=Forwarder.js.map
|
@ -1,9 +1,9 @@
|
|||||||
let logger = require('./log');
|
"use strict";
|
||||||
let mqtt = require('./mqttHandler');
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
let AHomematicItem = require('./AHomematicItem')
|
const logger = require("./log");
|
||||||
|
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||||
|
const AHomematicItem_1 = require("./AHomematicItem");
|
||||||
class HomematicDimmerItem extends AHomematicItem {
|
class HomematicDimmerItem extends AHomematicItem_1.AHomematicItem {
|
||||||
constructor(floor, room, item, hmId) {
|
constructor(floor, room, item, hmId) {
|
||||||
super(floor, room, item, hmId);
|
super(floor, room, item, hmId);
|
||||||
this.stateTopic = `${this.topicFirstPart}/state`;
|
this.stateTopic = `${this.topicFirstPart}/state`;
|
||||||
@ -26,29 +26,28 @@ class HomematicDimmerItem extends AHomematicItem {
|
|||||||
this.bright = 0.0;
|
this.bright = 0.0;
|
||||||
this.oldBright = undefined;
|
this.oldBright = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
dimmerAction() {
|
dimmerAction() {
|
||||||
if ((this.state != this.oldState) || (this.bright != this.oldBright)) {
|
if ((this.state != this.oldState) || (this.bright != this.oldBright)) {
|
||||||
if (this.state == 'ON') {
|
if (this.state == 'ON') {
|
||||||
mqtt.send(this.actionTopic, `${this.bright / 100.0}`);
|
MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${this.bright / 100.0}`);
|
||||||
} else {
|
}
|
||||||
mqtt.send(this.actionTopic, '0');
|
else {
|
||||||
|
MqttDispatcher_1.mqttHandler.send(this.actionTopic, '0');
|
||||||
}
|
}
|
||||||
this.oldState = this.state;
|
this.oldState = this.state;
|
||||||
this.oldBright = this.bright;
|
this.oldBright = this.bright;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessage(topic, payload) {
|
processMessage(topic, payload) {
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
case this.stateTopic:
|
case this.stateTopic:
|
||||||
this.state = payload;
|
this.state = payload;
|
||||||
mqtt.send(this.stateFeedbackTopic, this.state);
|
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
|
||||||
this.dimmerAction();
|
this.dimmerAction();
|
||||||
break;
|
break;
|
||||||
case this.brightTopic:
|
case this.brightTopic:
|
||||||
this.bright = parseFloat(payload);
|
this.bright = parseFloat(payload);
|
||||||
mqtt.send(this.brightFeedbackTopic, `${this.bright}`);
|
MqttDispatcher_1.mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`);
|
||||||
this.dimmerAction();
|
this.dimmerAction();
|
||||||
break;
|
break;
|
||||||
case this.errorOverheatTopic:
|
case this.errorOverheatTopic:
|
||||||
@ -61,6 +60,5 @@ class HomematicDimmerItem extends AHomematicItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exports.HomematicDimmerItem = HomematicDimmerItem;
|
||||||
module.exports = HomematicDimmerItem;
|
//# sourceMappingURL=HomematicDimmerItem.js.map
|
||||||
|
|
@ -1,9 +1,8 @@
|
|||||||
let logger = require('./log');
|
"use strict";
|
||||||
let mqtt = require('./mqttHandler');
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
let AHomematicItem = require('./AHomematicItem')
|
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||||
|
const AHomematicItem_1 = require("./AHomematicItem");
|
||||||
|
class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
|
||||||
class HomematicSwitchItem extends AHomematicItem {
|
|
||||||
constructor(floor, room, item, hmId) {
|
constructor(floor, room, item, hmId) {
|
||||||
super(floor, room, item, hmId);
|
super(floor, room, item, hmId);
|
||||||
this.stateTopic = `${this.topicFirstPart}/state`;
|
this.stateTopic = `${this.topicFirstPart}/state`;
|
||||||
@ -17,18 +16,17 @@ class HomematicSwitchItem extends AHomematicItem {
|
|||||||
this.state = 'OFF';
|
this.state = 'OFF';
|
||||||
this.oldState = undefined;
|
this.oldState = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
processMessage(topic, payload) {
|
processMessage(topic, payload) {
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
case this.stateTopic:
|
case this.stateTopic:
|
||||||
this.state = payload;
|
this.state = payload;
|
||||||
mqtt.send(this.stateFeedbackTopic, this.state);
|
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
|
||||||
if (this.state != this.oldState) {
|
if (this.state != this.oldState) {
|
||||||
if (this.state == 'ON') {
|
if (this.state == 'ON') {
|
||||||
mqtt.send(this.actionTopic, 'true');
|
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'true');
|
||||||
} else {
|
}
|
||||||
mqtt.send(this.actionTopic, 'false');
|
else {
|
||||||
|
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'false');
|
||||||
}
|
}
|
||||||
this.oldState = this.state;
|
this.oldState = this.state;
|
||||||
}
|
}
|
||||||
@ -36,15 +34,15 @@ class HomematicSwitchItem extends AHomematicItem {
|
|||||||
case this.deviceFeedbackTopic:
|
case this.deviceFeedbackTopic:
|
||||||
if (payload == 'true') {
|
if (payload == 'true') {
|
||||||
this.state = 'ON';
|
this.state = 'ON';
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.state = 'OFF';
|
this.state = 'OFF';
|
||||||
}
|
}
|
||||||
this.oldState = this.state;
|
this.oldState = this.state;
|
||||||
mqtt.send(this.stateFeedbackTopic, this.state);
|
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exports.HomematicSwitchItem = HomematicSwitchItem;
|
||||||
module.exports = HomematicSwitchItem;
|
//# sourceMappingURL=HomematicSwitchItem.js.map
|
||||||
|
|
36
src/TimerAdaptor.js → dist/TimerAdaptor.js
vendored
36
src/TimerAdaptor.js → dist/TimerAdaptor.js
vendored
@ -1,19 +1,18 @@
|
|||||||
let AItem = require('./AItem')
|
"use strict";
|
||||||
let logger = require('./log')
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
let mqtt = require('./mqttHandler');
|
const AItem_1 = require("./AItem");
|
||||||
|
const logger = require("./log");
|
||||||
|
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||||
class TimerAdaptor extends AItem {
|
class TimerAdaptor extends AItem_1.AItem {
|
||||||
constructor(floor, room, item, delay) {
|
constructor(floor, room, item, delay) {
|
||||||
super(floor, room, item);
|
super(floor, room, item);
|
||||||
this.actionStateTopic = `${this.topicFirstPart}/state`;
|
this.actionStateTopic = `${this.topicFirstPart}/state`;
|
||||||
this.inTopic = `${this.topicFirstPart}/timerIn`;
|
this.inTopic = `${this.topicFirstPart}/timerIn`;
|
||||||
this.subscribeTopics = [ this.inTopic ];
|
this.subscribeTopics = [this.inTopic];
|
||||||
this.state = 'OFF';
|
this.state = 'OFF';
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessage(topic, payload) {
|
processMessage(topic, payload) {
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
case this.inTopic:
|
case this.inTopic:
|
||||||
@ -23,28 +22,29 @@ class TimerAdaptor extends AItem {
|
|||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
}
|
}
|
||||||
this.state = 'ON';
|
this.state = 'ON';
|
||||||
mqtt.send(this.actionStateTopic, this.state, true);
|
MqttDispatcher_1.mqttHandler.send(this.actionStateTopic, this.state, true);
|
||||||
this.timer = setTimeout(() => {
|
this.timer = setTimeout(() => {
|
||||||
logger.info(`timer ${this.itemId} elapsed`);
|
logger.info(`timer ${this.itemId} elapsed`);
|
||||||
this.state = 'OFF';
|
this.state = 'OFF';
|
||||||
mqtt.send(this.actionStateTopic, this.state, true);
|
MqttDispatcher_1.mqttHandler.send(this.actionStateTopic, this.state, true);
|
||||||
}, (this.delay * 1000));
|
}, (this.delay * 1000));
|
||||||
break;
|
break;
|
||||||
case 'LONG_END':
|
case 'LONG_END':
|
||||||
clearTimeout(this.timer);
|
if (this.timer != null) {
|
||||||
|
clearTimeout(this.timer);
|
||||||
|
}
|
||||||
if (this.state == 'OFF') {
|
if (this.state == 'OFF') {
|
||||||
this.state = 'ON';
|
this.state = 'ON';
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.state = 'OFF';
|
this.state = 'OFF';
|
||||||
}
|
}
|
||||||
mqtt.send(this.actionStateTopic, this.state, true);
|
MqttDispatcher_1.mqttHandler.send(this.actionStateTopic, this.state, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exports.TimerAdaptor = TimerAdaptor;
|
||||||
|
//# sourceMappingURL=TimerAdaptor.js.map
|
||||||
module.exports = TimerAdaptor;
|
|
||||||
|
|
15
dist/main.js
vendored
15
dist/main.js
vendored
@ -5,6 +5,10 @@ const MqttDispatcher_1 = require("./MqttDispatcher");
|
|||||||
const M433SwitchItem_1 = require("./M433SwitchItem");
|
const M433SwitchItem_1 = require("./M433SwitchItem");
|
||||||
const HomematicFourButtonThing_1 = require("./HomematicFourButtonThing");
|
const HomematicFourButtonThing_1 = require("./HomematicFourButtonThing");
|
||||||
const DimmerAdaptor_1 = require("./DimmerAdaptor");
|
const DimmerAdaptor_1 = require("./DimmerAdaptor");
|
||||||
|
const TimerAdaptor_1 = require("./TimerAdaptor");
|
||||||
|
const HomematicDimmerItem_1 = require("./HomematicDimmerItem");
|
||||||
|
const HomematicSwitchItem_1 = require("./HomematicSwitchItem");
|
||||||
|
const Forwarder_1 = require("./Forwarder");
|
||||||
logger.info("Dispatcher starting");
|
logger.info("Dispatcher starting");
|
||||||
let aquariumLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
|
let aquariumLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
|
||||||
aquariumLight.start();
|
aquariumLight.start();
|
||||||
@ -19,6 +23,17 @@ let testFourButton = new HomematicFourButtonThing_1.HomematicFourButtonThing('Gn
|
|||||||
testFourButton.start();
|
testFourButton.start();
|
||||||
let testDimmerAdaptor = new DimmerAdaptor_1.DimmerAdaptor('Gnd', 'Hallway', 'Testlight');
|
let testDimmerAdaptor = new DimmerAdaptor_1.DimmerAdaptor('Gnd', 'Hallway', 'Testlight');
|
||||||
testDimmerAdaptor.start();
|
testDimmerAdaptor.start();
|
||||||
|
let testTimerAdaptor = new TimerAdaptor_1.TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10);
|
||||||
|
testTimerAdaptor.start();
|
||||||
|
let testLight = new HomematicDimmerItem_1.HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 8);
|
||||||
|
testLight.start();
|
||||||
|
let testLight2 = new HomematicSwitchItem_1.HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 5);
|
||||||
|
testLight2.start();
|
||||||
|
let testForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
|
||||||
|
'dispatcher_ng/items/Gnd/Hallway/Testlight2/state',
|
||||||
|
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
|
||||||
|
]);
|
||||||
|
testForwarder.start();
|
||||||
MqttDispatcher_1.mqttHandler.exec();
|
MqttDispatcher_1.mqttHandler.exec();
|
||||||
logger.info("Dispatcher running");
|
logger.info("Dispatcher running");
|
||||||
//# sourceMappingURL=main.js.map
|
//# sourceMappingURL=main.js.map
|
@ -4,7 +4,7 @@ import { mqttHandler } from './MqttDispatcher'
|
|||||||
|
|
||||||
export abstract class AItem {
|
export abstract class AItem {
|
||||||
protected topicFirstPart: string;
|
protected topicFirstPart: string;
|
||||||
private itemId: string;
|
protected itemId: string;
|
||||||
private item: string;
|
private item: string;
|
||||||
private room: string;
|
private room: string;
|
||||||
private floor: string
|
private floor: string
|
||||||
|
@ -22,7 +22,7 @@ export class DimmerAdaptor extends AItem {
|
|||||||
this.brightDirection = -1
|
this.brightDirection = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessage(topic: string, payload: string) {
|
processMessage(topic: string, payload: string) : void {
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
case this.inTopic:
|
case this.inTopic:
|
||||||
switch (payload) {
|
switch (payload) {
|
||||||
|
26
src/Forwarder.ts
Normal file
26
src/Forwarder.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { AItem } from './AItem'
|
||||||
|
import * as logger from './log'
|
||||||
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
|
|
||||||
|
|
||||||
|
export class Forwarder extends AItem {
|
||||||
|
private targetTopics: string[]
|
||||||
|
private inTopic: string
|
||||||
|
|
||||||
|
constructor(floor: string, room: string, item: string, topicLastPart: string, targetTopics: string[]) {
|
||||||
|
super(floor, room, item)
|
||||||
|
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`
|
||||||
|
this.subscribeTopics = [ this.inTopic ]
|
||||||
|
this.targetTopics = targetTopics
|
||||||
|
}
|
||||||
|
|
||||||
|
processMessage(topic: string, payload: string) : void {
|
||||||
|
switch (topic) {
|
||||||
|
case this.inTopic:
|
||||||
|
this.targetTopics.forEach((targetTopic) => {
|
||||||
|
mqttHandler.send(targetTopic, payload, true)
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
76
src/HomematicDimmerItem.ts
Normal file
76
src/HomematicDimmerItem.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import * as logger from './log'
|
||||||
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
|
import { AHomematicItem } from './AHomematicItem'
|
||||||
|
|
||||||
|
|
||||||
|
export class HomematicDimmerItem extends AHomematicItem {
|
||||||
|
private oldBright: number|undefined
|
||||||
|
private bright: number
|
||||||
|
private oldState: string|undefined
|
||||||
|
private state: string
|
||||||
|
private errorReducedTopic: string
|
||||||
|
private errorOverloadTopic: string
|
||||||
|
private errorOverheatTopic: string
|
||||||
|
private actionTopic: string
|
||||||
|
private brightFeedbackTopic: string
|
||||||
|
private stateFeedbackTopic: string
|
||||||
|
private brightTopic: string
|
||||||
|
private stateTopic: string
|
||||||
|
|
||||||
|
constructor(floor: string, room: string, item: string, hmId: number) {
|
||||||
|
super(floor, room, item, hmId)
|
||||||
|
this.stateTopic = `${this.topicFirstPart}/state`
|
||||||
|
this.brightTopic = `${this.topicFirstPart}/bright`
|
||||||
|
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
||||||
|
this.brightFeedbackTopic = `${this.topicFirstPart}/bright/feedback`
|
||||||
|
this.actionTopic = `${this.actionTopicPre}/1/LEVEL`
|
||||||
|
this.errorOverheatTopic = `${this.deviceTopicPre}/1/ERROR_OVERHEAT`
|
||||||
|
this.errorOverloadTopic = `${this.deviceTopicPre}/1/ERROR_OVERLOAD`
|
||||||
|
this.errorReducedTopic = `${this.deviceTopicPre}/1/ERROR_REDUCED`
|
||||||
|
this.subscribeTopics = [
|
||||||
|
this.stateTopic,
|
||||||
|
this.brightTopic,
|
||||||
|
this.errorOverheatTopic,
|
||||||
|
this.errorOverloadTopic,
|
||||||
|
this.errorReducedTopic
|
||||||
|
]
|
||||||
|
this.state = 'OFF'
|
||||||
|
this.oldState = undefined
|
||||||
|
this.bright = 0.0
|
||||||
|
this.oldBright = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
dimmerAction() : void {
|
||||||
|
if ((this.state != this.oldState) || (this.bright != this.oldBright)) {
|
||||||
|
if (this.state == 'ON') {
|
||||||
|
mqttHandler.send(this.actionTopic, `${this.bright / 100.0}`)
|
||||||
|
} else {
|
||||||
|
mqttHandler.send(this.actionTopic, '0')
|
||||||
|
}
|
||||||
|
this.oldState = this.state
|
||||||
|
this.oldBright = this.bright
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processMessage(topic: string, payload: string) : void {
|
||||||
|
switch (topic) {
|
||||||
|
case this.stateTopic:
|
||||||
|
this.state = payload
|
||||||
|
mqttHandler.send(this.stateFeedbackTopic, this.state)
|
||||||
|
this.dimmerAction()
|
||||||
|
break
|
||||||
|
case this.brightTopic:
|
||||||
|
this.bright = parseFloat(payload)
|
||||||
|
mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`)
|
||||||
|
this.dimmerAction()
|
||||||
|
break
|
||||||
|
case this.errorOverheatTopic:
|
||||||
|
case this.errorOverloadTopic:
|
||||||
|
case this.errorReducedTopic:
|
||||||
|
if (payload != 'false') {
|
||||||
|
logger.warn(`Homematic dimmer ${this.hmId}, ${this.itemId} reports: ${topic}: ${payload}`)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
src/HomematicSwitchItem.ts
Normal file
54
src/HomematicSwitchItem.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import * as logger from './log'
|
||||||
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
|
import { AHomematicItem } from './AHomematicItem'
|
||||||
|
|
||||||
|
|
||||||
|
export class HomematicSwitchItem extends AHomematicItem {
|
||||||
|
private oldState: string|undefined
|
||||||
|
private state: string
|
||||||
|
private actionTopic: string
|
||||||
|
private deviceFeedbackTopic: string
|
||||||
|
private stateFeedbackTopic: string
|
||||||
|
private stateTopic: string
|
||||||
|
|
||||||
|
constructor(floor: string, room: string, item: string, hmId: number) {
|
||||||
|
super(floor, room, item, hmId)
|
||||||
|
this.stateTopic = `${this.topicFirstPart}/state`
|
||||||
|
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
|
||||||
|
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/STATE`
|
||||||
|
this.actionTopic = `${this.actionTopicPre}/1/STATE`
|
||||||
|
this.subscribeTopics = [
|
||||||
|
this.stateTopic,
|
||||||
|
this.deviceFeedbackTopic
|
||||||
|
]
|
||||||
|
this.state = 'OFF'
|
||||||
|
this.oldState = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
processMessage(topic: string, payload: string) : void {
|
||||||
|
switch (topic) {
|
||||||
|
case this.stateTopic:
|
||||||
|
this.state = payload
|
||||||
|
mqttHandler.send(this.stateFeedbackTopic, this.state)
|
||||||
|
if (this.state != this.oldState) {
|
||||||
|
if (this.state == 'ON') {
|
||||||
|
mqttHandler.send(this.actionTopic, 'true')
|
||||||
|
} else {
|
||||||
|
mqttHandler.send(this.actionTopic, 'false')
|
||||||
|
}
|
||||||
|
this.oldState = this.state
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case this.deviceFeedbackTopic:
|
||||||
|
if (payload == 'true') {
|
||||||
|
this.state = 'ON'
|
||||||
|
} else {
|
||||||
|
this.state = 'OFF'
|
||||||
|
}
|
||||||
|
this.oldState = this.state
|
||||||
|
mqttHandler.send(this.stateFeedbackTopic, this.state)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
src/TimerAdaptor.ts
Normal file
56
src/TimerAdaptor.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import { AItem } from './AItem'
|
||||||
|
import * as logger from './log'
|
||||||
|
import { mqttHandler } from './MqttDispatcher'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export class TimerAdaptor extends AItem {
|
||||||
|
private timer: NodeJS.Timer|null
|
||||||
|
private delay: number
|
||||||
|
private state: string
|
||||||
|
private inTopic: string
|
||||||
|
private actionStateTopic: string
|
||||||
|
|
||||||
|
constructor(floor: string, room: string, item: string, delay: number) {
|
||||||
|
super(floor, room, item)
|
||||||
|
this.actionStateTopic = `${this.topicFirstPart}/state`
|
||||||
|
this.inTopic = `${this.topicFirstPart}/timerIn`
|
||||||
|
this.subscribeTopics = [ this.inTopic ]
|
||||||
|
this.state = 'OFF'
|
||||||
|
this.delay = delay
|
||||||
|
this.timer = null
|
||||||
|
}
|
||||||
|
|
||||||
|
processMessage(topic: string, payload: string) : void {
|
||||||
|
switch (topic) {
|
||||||
|
case this.inTopic:
|
||||||
|
switch (payload) {
|
||||||
|
case 'SHORT':
|
||||||
|
if ((this.state == 'ON') && (this.timer != null)) {
|
||||||
|
clearTimeout(this.timer)
|
||||||
|
}
|
||||||
|
this.state = 'ON'
|
||||||
|
mqttHandler.send(this.actionStateTopic, this.state, true)
|
||||||
|
this.timer = setTimeout(() => {
|
||||||
|
logger.info(`timer ${this.itemId} elapsed`)
|
||||||
|
this.state = 'OFF'
|
||||||
|
mqttHandler.send(this.actionStateTopic, this.state, true)
|
||||||
|
}, (this.delay * 1000))
|
||||||
|
break
|
||||||
|
case 'LONG_END':
|
||||||
|
if (this.timer != null) {
|
||||||
|
clearTimeout(this.timer)
|
||||||
|
}
|
||||||
|
if (this.state == 'OFF') {
|
||||||
|
this.state = 'ON'
|
||||||
|
} else {
|
||||||
|
this.state = 'OFF'
|
||||||
|
}
|
||||||
|
mqttHandler.send(this.actionStateTopic, this.state, true)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
53
src/main.js
53
src/main.js
@ -1,53 +0,0 @@
|
|||||||
let logger = require('./log');
|
|
||||||
let mqtt = require('./mqttHandler');
|
|
||||||
|
|
||||||
let HomematicDimmerItemClass = require('./HomematicDimmerItem');
|
|
||||||
let HomematicSwitchItemClass = require('./HomematicSwitchItem');
|
|
||||||
let M433SwitchItem = require('./M433SwitchItem');
|
|
||||||
let HomematicFourButtonThing = require('./HomematicFourButtonThing');
|
|
||||||
let HomematicFourButtonSingleItem = require('./HomematicFourButtonSingleItem');
|
|
||||||
let DimmerAdaptor = require('./DimmerAdaptor');
|
|
||||||
let TimerAdaptor = require('./TimerAdaptor');
|
|
||||||
let Forwarder = require('./Forwarder');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
|
|
||||||
aquariumLight.start();
|
|
||||||
|
|
||||||
let deskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1', '83220 24 1');
|
|
||||||
deskLight.start();
|
|
||||||
|
|
||||||
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
|
||||||
new HomematicFourButtonSingleItem('button1', 'dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
|
||||||
new HomematicFourButtonSingleItem('button2', 'dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
|
|
||||||
new HomematicFourButtonSingleItem('button3', 'test/button/3'),
|
|
||||||
new HomematicFourButtonSingleItem('button4', 'test/button/4')
|
|
||||||
]);
|
|
||||||
testFourButton.start();
|
|
||||||
|
|
||||||
let testDimmerAdaptor = new DimmerAdaptor('Gnd', 'Hallway', 'Testlight');
|
|
||||||
testDimmerAdaptor.start();
|
|
||||||
|
|
||||||
let testTimerAdaptor = new TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10);
|
|
||||||
testTimerAdaptor.start();
|
|
||||||
|
|
||||||
let testLight = new HomematicDimmerItemClass('Gnd', 'Hallway', 'Testlight', 8);
|
|
||||||
testLight.start();
|
|
||||||
|
|
||||||
let testLight2 = new HomematicSwitchItemClass('Gnd', 'Hallway', 'Testlight2', 5);
|
|
||||||
testLight2.start();
|
|
||||||
|
|
||||||
let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
|
|
||||||
'dispatcher_ng/items/Gnd/Hallway/Testlight2/state',
|
|
||||||
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
|
|
||||||
]);
|
|
||||||
testForwarder.start();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mqtt.start();
|
|
36
src/main.ts
36
src/main.ts
@ -5,26 +5,46 @@ import { mqttHandler } from './MqttDispatcher'
|
|||||||
import { M433SwitchItem } from './M433SwitchItem'
|
import { M433SwitchItem } from './M433SwitchItem'
|
||||||
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
|
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
|
||||||
import { DimmerAdaptor } from './DimmerAdaptor'
|
import { DimmerAdaptor } from './DimmerAdaptor'
|
||||||
|
import { TimerAdaptor } from './TimerAdaptor'
|
||||||
|
import { HomematicDimmerItem } from './HomematicDimmerItem'
|
||||||
|
import { HomematicSwitchItem } from './HomematicSwitchItem'
|
||||||
|
import { Forwarder } from './Forwarder'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger.info("Dispatcher starting")
|
logger.info("Dispatcher starting")
|
||||||
|
|
||||||
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
|
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1')
|
||||||
aquariumLight.start();
|
aquariumLight.start()
|
||||||
|
|
||||||
let deskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1', '83220 24 1');
|
let deskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1', '83220 24 1')
|
||||||
deskLight.start();
|
deskLight.start()
|
||||||
|
|
||||||
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
||||||
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
||||||
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
|
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
|
||||||
new HomematicFourButtonSingleItem('test/button/3'),
|
new HomematicFourButtonSingleItem('test/button/3'),
|
||||||
new HomematicFourButtonSingleItem('test/button/4')
|
new HomematicFourButtonSingleItem('test/button/4')
|
||||||
]);
|
])
|
||||||
testFourButton.start();
|
testFourButton.start()
|
||||||
|
|
||||||
let testDimmerAdaptor = new DimmerAdaptor('Gnd', 'Hallway', 'Testlight');
|
let testDimmerAdaptor = new DimmerAdaptor('Gnd', 'Hallway', 'Testlight')
|
||||||
testDimmerAdaptor.start();
|
testDimmerAdaptor.start()
|
||||||
|
|
||||||
|
let testTimerAdaptor = new TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10)
|
||||||
|
testTimerAdaptor.start()
|
||||||
|
|
||||||
|
let testLight = new HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 8)
|
||||||
|
testLight.start()
|
||||||
|
|
||||||
|
let testLight2 = new HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 5)
|
||||||
|
testLight2.start()
|
||||||
|
|
||||||
|
let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
|
||||||
|
'dispatcher_ng/items/Gnd/Hallway/Testlight2/state',
|
||||||
|
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
|
||||||
|
])
|
||||||
|
testForwarder.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user