Lint and code style fixes

This commit is contained in:
swevictor 2023-10-06 14:11:23 +02:00
parent 1f2c2df5ca
commit 9146f9c7d3
3 changed files with 28 additions and 14 deletions

View file

@ -55,9 +55,13 @@ class DeviceRegistry {
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
addOutputDevice(outputDevice) {
const alreadyExistingBLEDevice = this.getOutputDeviceByBleOutputAddress(outputDevice.bleOutputAddress);
const alreadyExistingBLEDevice = this.getOutputDeviceByBleOutputAddress(
outputDevice.bleOutputAddress,
);
if (alreadyExistingBLEDevice) {
logger.warn(`Device with output id ${outputDevice.bleOutputAddress} already exists named ${alreadyExistingBLEDevice.name}. These two devices are probably grouped in the Plejd app. If this seems to be an error, please log a GitHub issue.`);
logger.warn(
`Device with output id ${outputDevice.bleOutputAddress} already exists named ${alreadyExistingBLEDevice.name}. These two devices are probably grouped in the Plejd app. If this seems to be an error, please log a GitHub issue.`,
);
logger.info(`NOT adding ${outputDevice.name} to device registry`);
logger.verbose(`Details of device NOT added: ${JSON.stringify(outputDevice)}`);
return;
@ -195,7 +199,6 @@ class DeviceRegistry {
return this.mainBleIdByDeviceId[deviceId];
}
/**
* @param {string } deviceId The physical device serial number
* @return {import('./types/ApiSite').Device}

View file

@ -398,7 +398,7 @@ class PlejdApi {
broadcastClicks: false,
};
// PLEASE CREATE AN ISSUE WITH THE HARDWARE ID if you own one of these devices!
// case
// case
// return {
// name: 'DWN-02',
// description: 'Smart tunable downlight with a built-in dimmer function, 8W',
@ -406,7 +406,7 @@ class PlejdApi {
// dimmable: true,
// broadcastClicks: false,
// };
// case
// case
// return {
// name: 'OUT-01',
// description: 'Outdoor wall light with built-in LED, 2x5W',
@ -415,7 +415,9 @@ class PlejdApi {
// broadcastClicks: false,
// };
default:
throw new Error(`Unknown device type with hardware id ${plejdDevice.hardwareId}. --- PLEASE POST THIS AND THE NEXT LOG ROWS to https://github.com/icanos/hassio-plejd/issues/ --- `);
throw new Error(
`Unknown device type with hardware id ${plejdDevice.hardwareId}. --- PLEASE POST THIS AND THE NEXT LOG ROWS to https://github.com/icanos/hassio-plejd/issues/ --- `,
);
}
}

View file

@ -778,10 +778,14 @@ class PlejBLEHandler extends EventEmitter {
}
this.connectedDevice = device.device;
this.connectedDeviceId = this.deviceRegistry.getMainBleIdByDeviceId(this.connectedDevice.deviceId);
this.connectedDeviceId = this.deviceRegistry.getMainBleIdByDeviceId(
this.connectedDevice.deviceId,
);
logger.verbose('The connected Plejd device has the right charecteristics!');
logger.info(`Connected to Plejd device ${this.connectedDevice.title} (${this.connectedDevice.deviceId}, BLE id ${this.connectedDeviceId}).`);
logger.info(
`Connected to Plejd device ${this.connectedDevice.title} (${this.connectedDevice.deviceId}, BLE id ${this.connectedDeviceId}).`,
);
await this._authenticate();
@ -820,13 +824,18 @@ class PlejBLEHandler extends EventEmitter {
// Bytes 2-3 is Command/Request
const cmd = decoded.readUInt16BE(3);
const state = decoded.length > PAYLOAD_POSITION_OFFSET ? decoded.readUInt8(PAYLOAD_POSITION_OFFSET) : 0;
const state =
decoded.length > PAYLOAD_POSITION_OFFSET ? decoded.readUInt8(PAYLOAD_POSITION_OFFSET) : 0;
const dim = decoded.length > DIM_LEVEL_POSITION_OFFSET ? decoded.readUInt8(DIM_LEVEL_POSITION_OFFSET) : 0;
const dim =
decoded.length > DIM_LEVEL_POSITION_OFFSET ? decoded.readUInt8(DIM_LEVEL_POSITION_OFFSET) : 0;
if (Logger.shouldLog('silly')) {
// Full dim level is 2 bytes, we could potentially use this
const dimFull = decoded.length > DIM_LEVEL_POSITION_OFFSET ? decoded.readUInt16LE(DIM_LEVEL_POSITION_OFFSET - 1) : 0;
const dimFull =
decoded.length > DIM_LEVEL_POSITION_OFFSET
? decoded.readUInt16LE(DIM_LEVEL_POSITION_OFFSET - 1)
: 0;
logger.silly(`Dim: ${dim.toString(16)}, full precision: ${dimFull.toString(16)}`);
}
@ -877,7 +886,6 @@ class PlejBLEHandler extends EventEmitter {
data = { sceneId: scene.uniqueId };
this.emit(PlejBLEHandler.EVENTS.commandReceived, outputUniqueId, command, data);
} else if (cmd === BLE_CMD_TIME_UPDATE) {
if (decoded.length < PAYLOAD_POSITION_OFFSET + 4) {
if (Logger.shouldLog('debug')) {
// decoded.toString() could potentially be expensive
@ -886,13 +894,14 @@ class PlejBLEHandler extends EventEmitter {
// ignore the notification since too small
return;
}
const now = new Date();
// Guess Plejd timezone based on HA time zone
const offsetSecondsGuess = now.getTimezoneOffset() * 60 + 250; // Todo: 4 min off
// Plejd reports local unix timestamp adjust to local time zone
const plejdTimestampUTC = (decoded.readInt32LE(PAYLOAD_POSITION_OFFSET) + offsetSecondsGuess) * 1000;
const plejdTimestampUTC =
(decoded.readInt32LE(PAYLOAD_POSITION_OFFSET) + offsetSecondsGuess) * 1000;
const diffSeconds = Math.round((plejdTimestampUTC - now.getTime()) / 1000);
if (
bleOutputAddress !== BLE_BROADCAST_DEVICE_ID ||