Code lint fixes
This commit is contained in:
parent
20b64c9acb
commit
5af6a8c452
2 changed files with 6 additions and 9 deletions
|
|
@ -15,7 +15,7 @@ const getSubscribePath = () => `${discoveryPrefix}/+/${nodeId}/#`;
|
||||||
const getPath = ({ id, type }) => `${discoveryPrefix}/${type}/${nodeId}/${id}`;
|
const getPath = ({ id, type }) => `${discoveryPrefix}/${type}/${nodeId}/${id}`;
|
||||||
const getConfigPath = (plug) => `${getPath(plug)}/config`;
|
const getConfigPath = (plug) => `${getPath(plug)}/config`;
|
||||||
const getStateTopic = (plug) => `${getPath(plug)}/state`;
|
const getStateTopic = (plug) => `${getPath(plug)}/state`;
|
||||||
const getAvailabilityTopic = plug => `${getPath(plug)}/availability`;
|
const getAvailabilityTopic = (plug) => `${getPath(plug)}/availability`;
|
||||||
const getCommandTopic = (plug) => `${getPath(plug)}/set`;
|
const getCommandTopic = (plug) => `${getPath(plug)}/set`;
|
||||||
const getSceneEventTopic = () => 'plejd/event/scene';
|
const getSceneEventTopic = () => 'plejd/event/scene';
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ class MqttClient extends EventEmitter {
|
||||||
|
|
||||||
this.client.subscribe(startTopics, (err) => {
|
this.client.subscribe(startTopics, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error(`Unable to subscribe to status topics`);
|
logger.error('Unable to subscribe to status topics');
|
||||||
}
|
}
|
||||||
|
|
||||||
self.emit('connected');
|
self.emit('connected');
|
||||||
|
|
@ -129,10 +129,7 @@ class MqttClient extends EventEmitter {
|
||||||
|
|
||||||
disconnect(callback) {
|
disconnect(callback) {
|
||||||
this.devices.forEach((device) => {
|
this.devices.forEach((device) => {
|
||||||
this.client.publish(
|
this.client.publish(getAvailabilityTopic(device), 'offline');
|
||||||
getAvailabilityTopic(device),
|
|
||||||
"offline"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
this.client.end(callback);
|
this.client.end(callback);
|
||||||
}
|
}
|
||||||
|
|
@ -155,7 +152,7 @@ class MqttClient extends EventEmitter {
|
||||||
|
|
||||||
self.client.publish(getConfigPath(device), JSON.stringify(payload));
|
self.client.publish(getConfigPath(device), JSON.stringify(payload));
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
self.client.publish(getAvailabilityTopic(device), "online");
|
self.client.publish(getAvailabilityTopic(device), 'online');
|
||||||
}, 2000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +190,7 @@ class MqttClient extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.client.publish(getStateTopic(device), payload);
|
this.client.publish(getStateTopic(device), payload);
|
||||||
this.client.publish(getAvailabilityTopic(device), "online");
|
this.client.publish(getAvailabilityTopic(device), 'online');
|
||||||
}
|
}
|
||||||
|
|
||||||
sceneTriggered(scene) {
|
sceneTriggered(scene) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ async function main() {
|
||||||
);
|
);
|
||||||
const client = new MqttClient(config.mqttBroker, config.mqttUsername, config.mqttPassword);
|
const client = new MqttClient(config.mqttBroker, config.mqttUsername, config.mqttPassword);
|
||||||
|
|
||||||
['SIGINT', 'SIGHUP', 'SIGTERM'].forEach(signal => {
|
['SIGINT', 'SIGHUP', 'SIGTERM'].forEach((signal) => {
|
||||||
process.on(signal, () => {
|
process.on(signal, () => {
|
||||||
client.disconnect(() => process.exit(0));
|
client.disconnect(() => process.exit(0));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue