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
|
8
dist/main.js
vendored
8
dist/main.js
vendored
@ -22,6 +22,7 @@ const TouchSwitchMultiButtonThing_1 = require("./TouchSwitchMultiButtonThing");
|
||||
const RelayBox_1 = require("./RelayBox");
|
||||
const HeatingScene_1 = require("./HeatingScene");
|
||||
const TwoLedSignal_1 = require("./TwoLedSignal");
|
||||
const MySwitchThing_1 = require("./MySwitchThing");
|
||||
logger.info("Dispatcher starting");
|
||||
let allLabeledItems = new Array();
|
||||
let allThermostatItems = new Array();
|
||||
@ -222,6 +223,13 @@ let bedRoomWindowLight = new M433SwitchItem_1.M433SwitchItem('1st', 'BedRoom', '
|
||||
bedRoomWindowLight.start();
|
||||
allLabeledItems.push(bedRoomWindowLight);
|
||||
allRelevantLights.push(bedRoomWindowLight);
|
||||
// MySwitchTHing
|
||||
let mySwitchThingWolfgang = new MySwitchThing_1.MySwitchThing('1st', 'BedRoom', 'WolfgangsSwitch', [
|
||||
new MySwitchThing_1.MySwitchSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic()),
|
||||
new MySwitchThing_1.MySwitchSingleItem('IoT/InsLeere/1'),
|
||||
new MySwitchThing_1.MySwitchSingleItem('IoT/InsLeere/2'),
|
||||
]);
|
||||
mySwitchThingWolfgang.start();
|
||||
let windowContactBedroomStreet1st = new MaxWindowContact_1.MaxWindowContact('1st', 'Bedroom', 'WindowContactStreet', 'Fenster Schlafzimmer Strasse', 17);
|
||||
windowContactBedroomStreet1st.start();
|
||||
allLabeledItems.push(windowContactBedroomStreet1st);
|
||||
|
56
src/MySwitchThing.ts
Normal file
56
src/MySwitchThing.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AItem } from './AItem'
|
||||
|
||||
export class MySwitchSingleItem {
|
||||
private actionTopic: string
|
||||
|
||||
constructor(actionTopic: string) {
|
||||
this.actionTopic = actionTopic
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) {
|
||||
switch(payload) {
|
||||
case 'PRESS_SHORT':
|
||||
mqttHandler.send(this.actionTopic, 'SHORT', true)
|
||||
break
|
||||
case 'PRESS_LONG':
|
||||
case 'PRESS_CONT':
|
||||
mqttHandler.send(this.actionTopic, 'LONG_HOLD', true)
|
||||
break
|
||||
case 'PRESS_LONG_RELEASE':
|
||||
mqttHandler.send(this.actionTopic, 'LONG_END', true)
|
||||
break
|
||||
default:
|
||||
logger.warn(`HM4BSI: no handling available for ${topic}`)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class MySwitchThing extends AItem {
|
||||
private itemObjs: MySwitchSingleItem[]
|
||||
|
||||
constructor(floor: string, room: string, item: string, itemObjs: MySwitchSingleItem[]) {
|
||||
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: string, payload: string) {
|
||||
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}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,8 @@ import { TouchSwitchMultiButtonThing, TouchSwitchButtonSingleItem } from './Touc
|
||||
import { RelayBoxThing } from './RelayBox'
|
||||
import { HeatingScene } from './HeatingScene'
|
||||
import { TwoLedSignal } from './TwoLedSignal'
|
||||
import { MySwitchThing, MySwitchSingleItem } from './MySwitchThing'
|
||||
|
||||
|
||||
logger.info("Dispatcher starting")
|
||||
|
||||
@ -273,6 +275,13 @@ bedRoomWindowLight.start()
|
||||
allLabeledItems.push(bedRoomWindowLight)
|
||||
allRelevantLights.push(bedRoomWindowLight)
|
||||
|
||||
// MySwitchTHing
|
||||
let mySwitchThingWolfgang = new MySwitchThing('1st', 'BedRoom', 'WolfgangsSwitch', [
|
||||
new MySwitchSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic()),
|
||||
new MySwitchSingleItem('IoT/InsLeere/1'),
|
||||
new MySwitchSingleItem('IoT/InsLeere/2'),
|
||||
])
|
||||
mySwitchThingWolfgang.start()
|
||||
|
||||
|
||||
let windowContactBedroomStreet1st = new MaxWindowContact('1st', 'Bedroom', 'WindowContactStreet', 'Fenster Schlafzimmer Strasse', 17)
|
||||
|
Reference in New Issue
Block a user