Fix type-o in writeFailed error handling
This commit is contained in:
parent
853511a755
commit
d133efe228
2 changed files with 24 additions and 15 deletions
|
|
@ -123,14 +123,19 @@ class MqttClient extends EventEmitter {
|
|||
|
||||
const messageString = message.toString();
|
||||
const isJsonMessage = messageString.startsWith('{');
|
||||
const command = isJsonMessage
|
||||
? JSON.parse(messageString)
|
||||
: messageString;
|
||||
const command = isJsonMessage ? JSON.parse(messageString) : messageString;
|
||||
|
||||
if (!isJsonMessage && messageString === 'ON' && this.deviceRegistry.getScene(decodedTopic.id)) {
|
||||
if (
|
||||
!isJsonMessage
|
||||
&& messageString === 'ON'
|
||||
&& this.deviceRegistry.getScene(decodedTopic.id)
|
||||
) {
|
||||
// Guess that id that got state command without dim value belongs to Scene, not Device
|
||||
// This guess could very well be wrong depending on the installation...
|
||||
logger.warn(`Device id ${decodedTopic.id} belongs to both scene and device, guessing Scene is what should be set to ON. OFF commands still sent to device.`);
|
||||
logger.warn(
|
||||
`Device id ${decodedTopic.id} belongs to both scene and device, guessing Scene is what should be set to ON.`
|
||||
+ 'OFF commands still sent to device.',
|
||||
);
|
||||
device = this.deviceRegistry.getScene(decodedTopic.id);
|
||||
}
|
||||
const deviceName = device ? device.name : '';
|
||||
|
|
@ -164,7 +169,9 @@ class MqttClient extends EventEmitter {
|
|||
logger.verbose(`Warning: Unknown command ${decodedTopic.command} in decoded topic`);
|
||||
}
|
||||
} else {
|
||||
logger.verbose(`Warning: Got unrecognized mqtt command on '${topic}': ${message.toString()}`);
|
||||
logger.verbose(
|
||||
`Warning: Got unrecognized mqtt command on '${topic}': ${message.toString()}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -617,17 +617,17 @@ class PlejBLEHandler extends EventEmitter {
|
|||
logger.verbose(`Error message: ${error.message}`);
|
||||
|
||||
let errorIndicatesDisconnected = false;
|
||||
if (error.message.contains('error: 0x0e')) {
|
||||
|
||||
if (error.message.includes('error: 0x0e')) {
|
||||
logger.error("'Unlikely error' (0x0e) writing to Plejd. Will retry.", error);
|
||||
} else if (error.message.contains('Not connected')) {
|
||||
logger.error(
|
||||
"'Not connected' (0x0e) writing to Plejd. Plejd device is probably disconnected.",
|
||||
);
|
||||
} else if (error.message.includes('Not connected')) {
|
||||
logger.error("'Not connected' writing to Plejd. Plejd device is probably disconnected.");
|
||||
errorIndicatesDisconnected = true;
|
||||
} else if (error.message.contains('Method "WriteValue" with signature')) {
|
||||
} else if (error.message.includes('Method "WriteValue" with signature')) {
|
||||
logger.error("'Method \"WriteValue\" doesn't exist'. Plejd device is probably disconnected.");
|
||||
errorIndicatesDisconnected = true;
|
||||
}
|
||||
logger.verbose(`Made it ${errorIndicatesDisconnected} || ${this.consecutiveWriteFails >= 5}`);
|
||||
|
||||
if (errorIndicatesDisconnected || this.consecutiveWriteFails >= 5) {
|
||||
logger.warn(
|
||||
|
|
@ -647,14 +647,14 @@ class PlejBLEHandler extends EventEmitter {
|
|||
await this.characteristics.ping.WriteValue([...ping], {});
|
||||
pong = await this.characteristics.ping.ReadValue({});
|
||||
} catch (err) {
|
||||
logger.error(`Error pinging Plejd ${err.message}`);
|
||||
logger.verbose(`Error pinging Plejd, calling onWriteFailed... ${err.message}`);
|
||||
await this.onWriteFailed(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-bitwise
|
||||
if (((ping[0] + 1) & 0xff) !== pong[0]) {
|
||||
logger.error('Plejd ping failed');
|
||||
logger.verbose('Plejd ping failed, pong contains wrong data. Calling onWriteFailed...');
|
||||
await this.onWriteFailed(new Error(`plejd ping failed ${ping[0]} - ${pong[0]}`));
|
||||
return;
|
||||
}
|
||||
|
|
@ -901,7 +901,9 @@ class PlejBLEHandler extends EventEmitter {
|
|||
|
||||
this.emit('sceneTriggered', deviceId, sceneId);
|
||||
} else if (cmd === 0x1b) {
|
||||
logger.silly('Command 001b seems to be some kind of often repeating ping/mesh data');
|
||||
logger.silly(
|
||||
'Command 001b is the time of the Plejd devices command, not implemented currently',
|
||||
);
|
||||
} else {
|
||||
logger.verbose(
|
||||
`Command ${cmd.toString(16)} unknown. ${decoded.toString(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue