MySwitch, first test passed
This commit is contained in:
52
dist/MySwitchThing.js
vendored
Normal file
52
dist/MySwitchThing.js
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const logger = require("./log");
|
||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
const AItem_1 = require("./AItem");
|
||||
class MySwitchSingleItem {
|
||||
constructor(actionTopic) {
|
||||
this.actionTopic = actionTopic;
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
switch (payload) {
|
||||
case 'PRESS_SHORT':
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'SHORT', true);
|
||||
break;
|
||||
case 'PRESS_LONG':
|
||||
case 'PRESS_CONT':
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'LONG_HOLD', true);
|
||||
break;
|
||||
case 'PRESS_LONG_RELEASE':
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'LONG_END', true);
|
||||
break;
|
||||
default:
|
||||
logger.warn(`HM4BSI: no handling available for ${topic}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.MySwitchSingleItem = MySwitchSingleItem;
|
||||
class MySwitchThing extends AItem_1.AItem {
|
||||
constructor(floor, room, item, itemObjs) {
|
||||
super(floor, room, item, '');
|
||||
this.itemObjs = itemObjs;
|
||||
if (this.itemObjs.length != 3) {
|
||||
throw new Error('itemObjs for MySwitchThing must have three elements');
|
||||
}
|
||||
this.subscribeTopics = [
|
||||
`${this.topicFirstPart}/#`
|
||||
];
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
logger.info(`MyT: ${topic}, ${payload}`);
|
||||
let buttonIdx = parseInt(topic.substring(this.topicFirstPart.length + 1));
|
||||
if (buttonIdx >= 1 && buttonIdx <= 3) {
|
||||
this.itemObjs[buttonIdx - 1].processMessage('', payload);
|
||||
}
|
||||
else {
|
||||
logger.warn(`MyT: no handling available for ${topic}, ${buttonIdx}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.MySwitchThing = MySwitchThing;
|
||||
//# sourceMappingURL=MySwitchThing.js.map
|
Reference in New Issue
Block a user