Lint and code style fixes
This commit is contained in:
parent
1f2c2df5ca
commit
9146f9c7d3
3 changed files with 28 additions and 14 deletions
|
|
@ -55,9 +55,13 @@ class DeviceRegistry {
|
||||||
|
|
||||||
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
|
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
|
||||||
addOutputDevice(outputDevice) {
|
addOutputDevice(outputDevice) {
|
||||||
const alreadyExistingBLEDevice = this.getOutputDeviceByBleOutputAddress(outputDevice.bleOutputAddress);
|
const alreadyExistingBLEDevice = this.getOutputDeviceByBleOutputAddress(
|
||||||
|
outputDevice.bleOutputAddress,
|
||||||
|
);
|
||||||
if (alreadyExistingBLEDevice) {
|
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.info(`NOT adding ${outputDevice.name} to device registry`);
|
||||||
logger.verbose(`Details of device NOT added: ${JSON.stringify(outputDevice)}`);
|
logger.verbose(`Details of device NOT added: ${JSON.stringify(outputDevice)}`);
|
||||||
return;
|
return;
|
||||||
|
|
@ -195,7 +199,6 @@ class DeviceRegistry {
|
||||||
return this.mainBleIdByDeviceId[deviceId];
|
return this.mainBleIdByDeviceId[deviceId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string } deviceId The physical device serial number
|
* @param {string } deviceId The physical device serial number
|
||||||
* @return {import('./types/ApiSite').Device}
|
* @return {import('./types/ApiSite').Device}
|
||||||
|
|
|
||||||
|
|
@ -415,7 +415,9 @@ class PlejdApi {
|
||||||
// broadcastClicks: false,
|
// broadcastClicks: false,
|
||||||
// };
|
// };
|
||||||
default:
|
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/ --- `,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -778,10 +778,14 @@ class PlejBLEHandler extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.connectedDevice = device.device;
|
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.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();
|
await this._authenticate();
|
||||||
|
|
||||||
|
|
@ -820,13 +824,18 @@ class PlejBLEHandler extends EventEmitter {
|
||||||
// Bytes 2-3 is Command/Request
|
// Bytes 2-3 is Command/Request
|
||||||
const cmd = decoded.readUInt16BE(3);
|
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')) {
|
if (Logger.shouldLog('silly')) {
|
||||||
// Full dim level is 2 bytes, we could potentially use this
|
// 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)}`);
|
logger.silly(`Dim: ${dim.toString(16)}, full precision: ${dimFull.toString(16)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -877,7 +886,6 @@ class PlejBLEHandler extends EventEmitter {
|
||||||
data = { sceneId: scene.uniqueId };
|
data = { sceneId: scene.uniqueId };
|
||||||
this.emit(PlejBLEHandler.EVENTS.commandReceived, outputUniqueId, command, data);
|
this.emit(PlejBLEHandler.EVENTS.commandReceived, outputUniqueId, command, data);
|
||||||
} else if (cmd === BLE_CMD_TIME_UPDATE) {
|
} else if (cmd === BLE_CMD_TIME_UPDATE) {
|
||||||
|
|
||||||
if (decoded.length < PAYLOAD_POSITION_OFFSET + 4) {
|
if (decoded.length < PAYLOAD_POSITION_OFFSET + 4) {
|
||||||
if (Logger.shouldLog('debug')) {
|
if (Logger.shouldLog('debug')) {
|
||||||
// decoded.toString() could potentially be expensive
|
// decoded.toString() could potentially be expensive
|
||||||
|
|
@ -892,7 +900,8 @@ class PlejBLEHandler extends EventEmitter {
|
||||||
const offsetSecondsGuess = now.getTimezoneOffset() * 60 + 250; // Todo: 4 min off
|
const offsetSecondsGuess = now.getTimezoneOffset() * 60 + 250; // Todo: 4 min off
|
||||||
|
|
||||||
// Plejd reports local unix timestamp adjust to local time zone
|
// 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);
|
const diffSeconds = Math.round((plejdTimestampUTC - now.getTime()) / 1000);
|
||||||
if (
|
if (
|
||||||
bleOutputAddress !== BLE_BROADCAST_DEVICE_ID ||
|
bleOutputAddress !== BLE_BROADCAST_DEVICE_ID ||
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue