Lint and style fixes
This commit is contained in:
parent
4e7ec6a1da
commit
898a9d822f
4 changed files with 29 additions and 30 deletions
|
|
@ -109,12 +109,6 @@ class MqttClient extends EventEmitter {
|
|||
});
|
||||
|
||||
this.client.on('message', (topic, message) => {
|
||||
// const command = message.toString();
|
||||
const command =
|
||||
message.toString().substring(0, 1) === '{'
|
||||
? JSON.parse(message.toString())
|
||||
: message.toString();
|
||||
|
||||
if (startTopics.includes(topic)) {
|
||||
logger.info('Home Assistant has started. lets do discovery.');
|
||||
this.emit('connected');
|
||||
|
|
@ -124,6 +118,10 @@ class MqttClient extends EventEmitter {
|
|||
const device = this.deviceRegistry.getDevice(decodedTopic.id);
|
||||
const deviceName = device ? device.name : '';
|
||||
|
||||
const command = message.toString().substring(0, 1) === '{'
|
||||
? JSON.parse(message.toString())
|
||||
: message.toString();
|
||||
|
||||
switch (decodedTopic.command) {
|
||||
case 'set':
|
||||
logger.verbose(
|
||||
|
|
@ -142,7 +140,11 @@ class MqttClient extends EventEmitter {
|
|||
case 'config':
|
||||
case 'availability':
|
||||
logger.verbose(
|
||||
`Sent mqtt ${decodedTopic.command} command for ${decodedTopic.type}, ${deviceName} (${decodedTopic.id}). ${decodedTopic.command === 'availability' ? message : ''}`,
|
||||
`Sent mqtt ${decodedTopic.command} command for ${
|
||||
decodedTopic.type
|
||||
}, ${deviceName} (${decodedTopic.id}). ${
|
||||
decodedTopic.command === 'availability' ? message : ''
|
||||
}`,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -172,8 +174,7 @@ class MqttClient extends EventEmitter {
|
|||
this.deviceRegistry.allDevices.forEach((device) => {
|
||||
logger.debug(`Sending discovery for ${device.name}`);
|
||||
|
||||
const payload =
|
||||
device.type === 'switch' ? getSwitchPayload(device) : getDiscoveryPayload(device);
|
||||
const payload = device.type === 'switch' ? getSwitchPayload(device) : getDiscoveryPayload(device);
|
||||
logger.info(
|
||||
`Discovered ${device.type} (${device.typeName}) named ${device.name} with PID ${device.id}.`,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue