Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const settings = require('../util/settings');
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
const logger = require('../util/logger');
const utils = require('../util/utils');
const assert = require('assert');
const BaseExtension = require('./baseExtension');
const postfixes = utils.getPostfixes();
const topicRegex = new RegExp(`^(.+?)(?:/(${postfixes.join('|')}))?/(get|set)(?:/(.+))?`);
const groupConverters = [
zigbeeHerdsmanConverters.toZigbeeConverters.light_onoff_brightness,
zigbeeHerdsmanConverters.toZigbeeConverters.light_colortemp,
zigbeeHerdsmanConverters.toZigbeeConverters.light_color,
zigbeeHerdsmanConverters.toZigbeeConverters.light_alert,
zigbeeHerdsmanConverters.toZigbeeConverters.ignore_transition,
];
class EntityPublish extends BaseExtension {
onMQTTConnected() {
// Subscribe to topics.
const baseTopic = settings.get().mqtt.base_topic;
for (let step = 1; step < 20; step++) {
const topic = `${baseTopic}/${'+/'.repeat(step)}`;
this.mqtt.subscribe(`${topic}set`);
this.mqtt.subscribe(`${topic}set/+`);
this.mqtt.subscribe(`${topic}get`);
this.mqtt.subscribe(`${topic}get/+`);
}
const settings = require('../util/settings');
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
const logger = require('../util/logger');
const utils = require('../util/utils');
const assert = require('assert');
const BaseExtension = require('./baseExtension');
const postfixes = utils.getPostfixes();
const topicRegex = new RegExp(`^(.+?)(?:/(${postfixes.join('|')}))?/(get|set)(?:/(.+))?`);
const groupConverters = [
zigbeeHerdsmanConverters.toZigbeeConverters.light_onoff_brightness,
zigbeeHerdsmanConverters.toZigbeeConverters.light_colortemp,
zigbeeHerdsmanConverters.toZigbeeConverters.light_color,
zigbeeHerdsmanConverters.toZigbeeConverters.light_alert,
zigbeeHerdsmanConverters.toZigbeeConverters.ignore_transition,
];
class EntityPublish extends BaseExtension {
onMQTTConnected() {
// Subscribe to topics.
const baseTopic = settings.get().mqtt.base_topic;
for (let step = 1; step < 20; step++) {
const topic = `${baseTopic}/${'+/'.repeat(step)}`;
this.mqtt.subscribe(`${topic}set`);
this.mqtt.subscribe(`${topic}set/+`);
this.mqtt.subscribe(`${topic}get`);
this.mqtt.subscribe(`${topic}get/+`);
if (!shepherdNode) {
this.error('missing herdsman');
return;
}
this.models = new Map();
this.herdsman = shepherdNode.herdsman;
this.ieeeAddresses = {};
this.names = {};
const groupConverters = [
herdsmanConverters.toZigbeeConverters.light_onoff_brightness,
herdsmanConverters.toZigbeeConverters.light_colortemp,
herdsmanConverters.toZigbeeConverters.light_color,
herdsmanConverters.toZigbeeConverters.light_alert,
herdsmanConverters.toZigbeeConverters.ignore_transition
];
const getDevices = () => {
this.debug('getDevices');
const devices = this.herdsman.getDevices();
devices.forEach(device => {
this.ieeeAddresses[device.ieeeAddr] = device;
this.names[device.meta.name] = device;
});
this.groups = this.herdsman.getGroups();
this.gotDevices = true;
};
const readyHandler = () => {
this.debug('readyHandler');
if (!this.gotDevices) {
RED.nodes.createNode(this, config);
const shepherdNode = RED.nodes.getNode(config.shepherd);
if (!shepherdNode) {
this.error('missing herdsman');
return;
}
this.models = new Map();
this.herdsman = shepherdNode.herdsman;
this.ieeeAddresses = {};
this.names = {};
const groupConverters = [
herdsmanConverters.toZigbeeConverters.light_onoff_brightness,
herdsmanConverters.toZigbeeConverters.light_colortemp,
herdsmanConverters.toZigbeeConverters.light_color,
herdsmanConverters.toZigbeeConverters.light_alert,
herdsmanConverters.toZigbeeConverters.ignore_transition
];
const getDevices = () => {
this.debug('getDevices');
const devices = this.herdsman.getDevices();
devices.forEach(device => {
this.ieeeAddresses[device.ieeeAddr] = device;
this.names[device.meta.name] = device;
});
this.groups = this.herdsman.getGroups();
this.gotDevices = true;
};