touch switch support
This commit is contained in:
65
dist/HueColorBulbItem.js
vendored
65
dist/HueColorBulbItem.js
vendored
@ -4,17 +4,11 @@ const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
const AHomegearItem_1 = require("./AHomegearItem");
|
||||
const Export_1 = require("./Export");
|
||||
class HueColorBulbItem extends AHomegearItem_1.AHomegearItem {
|
||||
getStateTopic() {
|
||||
return this.stateTopic;
|
||||
}
|
||||
getInTopic() {
|
||||
return this.stateTopic;
|
||||
}
|
||||
getStateFeedbackTopic() {
|
||||
return this.stateFeedbackTopic;
|
||||
}
|
||||
constructor(floor, room, item, label, hmId) {
|
||||
super(floor, room, item, label, hmId);
|
||||
this.BRIGHT_FACTOR = 2.54;
|
||||
this.HUE_FACTOR = (65535 / 360);
|
||||
this.SATURATION_FACTOR = 2.54;
|
||||
this.stateTopic = `${this.topicFirstPart}/state`;
|
||||
this.brightTopic = `${this.topicFirstPart}/bright`;
|
||||
this.colorTemperatureTopic = `${this.topicFirstPart}/colorTemperature`;
|
||||
@ -30,12 +24,22 @@ class HueColorBulbItem extends AHomegearItem_1.AHomegearItem {
|
||||
this.hueActionTopic = `${this.actionTopicPre}/1/HUE`;
|
||||
this.saturationActionTopic = `${this.actionTopicPre}/1/SATURATION`;
|
||||
this.colorTemperatureActionTopic = `${this.actionTopicPre}/1/COLOR_TEMPERATURE`;
|
||||
this.stateDeviceTopic = `${this.deviceTopicPre}/1/STATE`;
|
||||
this.brightDeviceTopic = `${this.deviceTopicPre}/1/FAST_BRIGHTNESS`;
|
||||
this.hueDeviceTopic = `${this.deviceTopicPre}/1/HUE`;
|
||||
this.saturationDeviceTopic = `${this.deviceTopicPre}/1/SATURATION`;
|
||||
this.colorTemperatureDeviceTopic = `${this.deviceTopicPre}/1/COLOR_TEMPERATURE`;
|
||||
this.subscribeTopics = [
|
||||
this.stateTopic,
|
||||
this.brightTopic,
|
||||
this.colorTemperatureTopic,
|
||||
this.hueTopic,
|
||||
this.saturationTopic
|
||||
this.saturationTopic,
|
||||
this.stateDeviceTopic,
|
||||
this.brightDeviceTopic,
|
||||
this.colorTemperatureDeviceTopic,
|
||||
this.hueDeviceTopic,
|
||||
this.saturationDeviceTopic
|
||||
];
|
||||
this.state = 'OFF';
|
||||
this.bright = 0;
|
||||
@ -43,6 +47,15 @@ class HueColorBulbItem extends AHomegearItem_1.AHomegearItem {
|
||||
this.hue = 0;
|
||||
this.saturation = 0;
|
||||
}
|
||||
getStateTopic() {
|
||||
return this.stateTopic;
|
||||
}
|
||||
getInTopic() {
|
||||
return this.stateTopic;
|
||||
}
|
||||
getStateFeedbackTopic() {
|
||||
return this.stateFeedbackTopic;
|
||||
}
|
||||
exportItem() {
|
||||
return Export_1.HueColorLightExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.brightTopic, this.brightFeedbackTopic, this.hueTopic, this.hueFeedbackTopic, this.saturationTopic, this.saturationFeedbackTopic, this.colorTemperatureTopic, this.colorTemperatureFeedbackTopic);
|
||||
}
|
||||
@ -58,26 +71,52 @@ class HueColorBulbItem extends AHomegearItem_1.AHomegearItem {
|
||||
MqttDispatcher_1.mqttHandler.send(this.stateActionTopic, "false");
|
||||
}
|
||||
break;
|
||||
case this.stateDeviceTopic:
|
||||
this.state = payload;
|
||||
if (payload == "true") {
|
||||
this.state = "ON";
|
||||
}
|
||||
else {
|
||||
this.state = "OFF";
|
||||
}
|
||||
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
|
||||
break;
|
||||
case this.brightTopic:
|
||||
this.bright = parseFloat(payload);
|
||||
MqttDispatcher_1.mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.brightActionTopic, `${this.bright * 2.54}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.brightActionTopic, `${this.bright * this.BRIGHT_FACTOR}`);
|
||||
break;
|
||||
case this.brightDeviceTopic:
|
||||
this.bright = parseFloat(payload) / this.BRIGHT_FACTOR;
|
||||
MqttDispatcher_1.mqttHandler.send(this.brightFeedbackTopic, `${this.bright}`);
|
||||
break;
|
||||
case this.hueTopic:
|
||||
this.hue = parseFloat(payload);
|
||||
MqttDispatcher_1.mqttHandler.send(this.hueFeedbackTopic, `${this.hue}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.hueActionTopic, `${this.hue * 65535.0 / 360.0}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.hueActionTopic, `${this.hue * this.HUE_FACTOR}`);
|
||||
break;
|
||||
case this.hueDeviceTopic:
|
||||
this.hue = parseFloat(payload) / this.HUE_FACTOR;
|
||||
MqttDispatcher_1.mqttHandler.send(this.hueFeedbackTopic, `${this.hue}`);
|
||||
break;
|
||||
case this.saturationTopic:
|
||||
this.saturation = parseFloat(payload);
|
||||
MqttDispatcher_1.mqttHandler.send(this.saturationFeedbackTopic, `${this.saturation}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.saturationActionTopic, `${this.saturation * 2.54}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.saturationActionTopic, `${this.saturation * this.SATURATION_FACTOR}`);
|
||||
break;
|
||||
case this.saturationDeviceTopic:
|
||||
this.saturation = parseFloat(payload) / this.SATURATION_FACTOR;
|
||||
MqttDispatcher_1.mqttHandler.send(this.saturationFeedbackTopic, `${this.saturation}`);
|
||||
break;
|
||||
case this.colorTemperatureTopic:
|
||||
this.colorTemperature = parseInt(payload);
|
||||
MqttDispatcher_1.mqttHandler.send(this.colorTemperatureFeedbackTopic, `${this.colorTemperature}`);
|
||||
MqttDispatcher_1.mqttHandler.send(this.colorTemperatureActionTopic, `${this.colorTemperature}`);
|
||||
break;
|
||||
case this.colorTemperatureDeviceTopic:
|
||||
this.colorTemperature = parseInt(payload);
|
||||
MqttDispatcher_1.mqttHandler.send(this.colorTemperatureFeedbackTopic, `${this.colorTemperature}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
51
dist/TouchSwitchMultiButtonThing.js
vendored
Normal file
51
dist/TouchSwitchMultiButtonThing.js
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const logger = require("./log");
|
||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
const AItem_1 = require("./AItem");
|
||||
class TouchSwitchButtonSingleItem {
|
||||
constructor(actionTopic) {
|
||||
this.actionTopic = actionTopic;
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
switch (topic) {
|
||||
case 'SHORT':
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'SHORT', true);
|
||||
break;
|
||||
case 'LONG_BEGIN':
|
||||
case 'LONG_CONT':
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'LONG_HOLD', true);
|
||||
break;
|
||||
case 'LONG_END':
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'LONG_END', true);
|
||||
break;
|
||||
default:
|
||||
logger.warn(`TWBSI: no handling available for ${topic}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.TouchSwitchButtonSingleItem = TouchSwitchButtonSingleItem;
|
||||
class TouchSwitchMultiButtonThing extends AItem_1.AItem {
|
||||
constructor(floor, room, item, hmId, itemObjs) {
|
||||
super(floor, room, item, '');
|
||||
this.itemObjs = itemObjs;
|
||||
this.deviceTopicPre = `IoT/Touchswitch/${this.floor}/${this.room}/${this.item}`;
|
||||
this.subscribeTopics = [
|
||||
`${this.deviceTopicPre}/#`
|
||||
];
|
||||
}
|
||||
processMessage(topic, payload) {
|
||||
logger.info(`TSMBT: ${topic}, ${payload}`);
|
||||
let buttonRelatedPart = topic.substring(this.deviceTopicPre.length + 1);
|
||||
let buttonIdx = parseInt(buttonRelatedPart.substring(0, buttonRelatedPart.indexOf('/')));
|
||||
if (buttonIdx >= 1 && buttonIdx <= this.itemObjs.length) {
|
||||
this.itemObjs[buttonIdx - 1].processMessage(buttonRelatedPart.substring(buttonRelatedPart.indexOf('/') + 1), payload);
|
||||
}
|
||||
else {
|
||||
logger.warn(`TSMBT: no handling available for ${topic}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.TouchSwitchMultiButtonThing = TouchSwitchMultiButtonThing;
|
||||
//# sourceMappingURL=TouchSwitchMultiButtonThing.js.map
|
@ -20,9 +20,9 @@ export abstract class AItem {
|
||||
protected topicFirstPart: string
|
||||
protected itemId: string
|
||||
protected label: string
|
||||
private item: string
|
||||
private room: string
|
||||
private floor: string
|
||||
protected item: string
|
||||
protected room: string
|
||||
protected floor: string
|
||||
protected subscribeTopics: string[]
|
||||
|
||||
|
||||
|
57
src/TouchSwitchMultiButtonThing.ts
Normal file
57
src/TouchSwitchMultiButtonThing.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import * as logger from './log'
|
||||
import { mqttHandler } from './MqttDispatcher'
|
||||
import { AItem } from './AItem'
|
||||
|
||||
|
||||
export class TouchSwitchButtonSingleItem {
|
||||
private actionTopic: string
|
||||
|
||||
constructor(actionTopic: string) {
|
||||
this.actionTopic = actionTopic
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) {
|
||||
switch(topic) {
|
||||
case 'SHORT':
|
||||
mqttHandler.send(this.actionTopic, 'SHORT', true)
|
||||
break
|
||||
case 'LONG_BEGIN':
|
||||
case 'LONG_CONT':
|
||||
mqttHandler.send(this.actionTopic, 'LONG_HOLD', true)
|
||||
break
|
||||
case 'LONG_END':
|
||||
mqttHandler.send(this.actionTopic, 'LONG_END', true)
|
||||
break
|
||||
default:
|
||||
logger.warn(`TWBSI: no handling available for ${topic}`)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class TouchSwitchMultiButtonThing extends AItem {
|
||||
private itemObjs: TouchSwitchButtonSingleItem[]
|
||||
private readonly deviceTopicPre: string
|
||||
|
||||
constructor(floor: string, room: string, item: string, hmId: number, itemObjs: TouchSwitchButtonSingleItem[]) {
|
||||
super(floor, room, item, '')
|
||||
this.itemObjs = itemObjs
|
||||
this.deviceTopicPre = `IoT/Touchswitch/${this.floor}/${this.room}/${this.item}`
|
||||
this.subscribeTopics = [
|
||||
`${this.deviceTopicPre}/#`
|
||||
]
|
||||
}
|
||||
|
||||
processMessage(topic: string, payload: string) {
|
||||
logger.info(`TSMBT: ${topic}, ${payload}`)
|
||||
let buttonRelatedPart = topic.substring(this.deviceTopicPre.length+1)
|
||||
let buttonIdx = parseInt(buttonRelatedPart.substring(0, buttonRelatedPart.indexOf('/')))
|
||||
if (buttonIdx >= 1 && buttonIdx <= this.itemObjs.length) {
|
||||
this.itemObjs[buttonIdx-1].processMessage(buttonRelatedPart.substring(buttonRelatedPart.indexOf('/')+1), payload)
|
||||
} else {
|
||||
logger.warn(`TSMBT: no handling available for ${topic}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user