Lint and style fixes
This commit is contained in:
parent
4e7ec6a1da
commit
898a9d822f
4 changed files with 29 additions and 30 deletions
|
|
@ -23,6 +23,7 @@ module.exports = {
|
||||||
|
|
||||||
function getRules() {
|
function getRules() {
|
||||||
return {
|
return {
|
||||||
|
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
|
||||||
// Allows modification of properties passed to functions.
|
// Allows modification of properties passed to functions.
|
||||||
// Notably used in array.forEach(e => {e.prop = val;})
|
// Notably used in array.forEach(e => {e.prop = val;})
|
||||||
'no-param-reassign': ['error', { props: false }],
|
'no-param-reassign': ['error', { props: false }],
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class Configuration {
|
||||||
|
|
||||||
Configuration._options = { ...defaultConfig, ...config };
|
Configuration._options = { ...defaultConfig, ...config };
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
console.log('Config:', {
|
console.log('Config:', {
|
||||||
...Configuration._options,
|
...Configuration._options,
|
||||||
username: '---scrubbed---',
|
username: '---scrubbed---',
|
||||||
|
|
|
||||||
|
|
@ -109,12 +109,6 @@ class MqttClient extends EventEmitter {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.client.on('message', (topic, message) => {
|
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)) {
|
if (startTopics.includes(topic)) {
|
||||||
logger.info('Home Assistant has started. lets do discovery.');
|
logger.info('Home Assistant has started. lets do discovery.');
|
||||||
this.emit('connected');
|
this.emit('connected');
|
||||||
|
|
@ -124,6 +118,10 @@ class MqttClient extends EventEmitter {
|
||||||
const device = this.deviceRegistry.getDevice(decodedTopic.id);
|
const device = this.deviceRegistry.getDevice(decodedTopic.id);
|
||||||
const deviceName = device ? device.name : '';
|
const deviceName = device ? device.name : '';
|
||||||
|
|
||||||
|
const command = message.toString().substring(0, 1) === '{'
|
||||||
|
? JSON.parse(message.toString())
|
||||||
|
: message.toString();
|
||||||
|
|
||||||
switch (decodedTopic.command) {
|
switch (decodedTopic.command) {
|
||||||
case 'set':
|
case 'set':
|
||||||
logger.verbose(
|
logger.verbose(
|
||||||
|
|
@ -142,7 +140,11 @@ class MqttClient extends EventEmitter {
|
||||||
case 'config':
|
case 'config':
|
||||||
case 'availability':
|
case 'availability':
|
||||||
logger.verbose(
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -172,8 +174,7 @@ class MqttClient extends EventEmitter {
|
||||||
this.deviceRegistry.allDevices.forEach((device) => {
|
this.deviceRegistry.allDevices.forEach((device) => {
|
||||||
logger.debug(`Sending discovery for ${device.name}`);
|
logger.debug(`Sending discovery for ${device.name}`);
|
||||||
|
|
||||||
const payload =
|
const payload = device.type === 'switch' ? getSwitchPayload(device) : getDiscoveryPayload(device);
|
||||||
device.type === 'switch' ? getSwitchPayload(device) : getDiscoveryPayload(device);
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`Discovered ${device.type} (${device.typeName}) named ${device.name} with PID ${device.id}.`,
|
`Discovered ${device.type} (${device.typeName}) named ${device.name} with PID ${device.id}.`,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -149,9 +149,7 @@ class PlejBLE extends EventEmitter {
|
||||||
logger.verbose('All active BLE device connections cleaned up.');
|
logger.verbose('All active BLE device connections cleaned up.');
|
||||||
|
|
||||||
logger.verbose('Setting up interfacesAdded subscription and discovery filter');
|
logger.verbose('Setting up interfacesAdded subscription and discovery filter');
|
||||||
this.objectManager.on('InterfacesAdded', (path, interfaces) =>
|
this.objectManager.on('InterfacesAdded', (path, interfaces) => this.onInterfacesAdded(path, interfaces));
|
||||||
this.onInterfacesAdded(path, interfaces),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.adapter.SetDiscoveryFilter({
|
this.adapter.SetDiscoveryFilter({
|
||||||
UUIDs: new dbus.Variant('as', [PLEJD_SERVICE]),
|
UUIDs: new dbus.Variant('as', [PLEJD_SERVICE]),
|
||||||
|
|
@ -313,11 +311,11 @@ class PlejBLE extends EventEmitter {
|
||||||
const isDimmable = this.deviceRegistry.getDevice(deviceId).dimmable;
|
const isDimmable = this.deviceRegistry.getDevice(deviceId).dimmable;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
transition > 1 &&
|
transition > 1
|
||||||
isDimmable &&
|
&& isDimmable
|
||||||
(initialBrightness || initialBrightness === 0) &&
|
&& (initialBrightness || initialBrightness === 0)
|
||||||
(targetBrightness || targetBrightness === 0) &&
|
&& (targetBrightness || targetBrightness === 0)
|
||||||
targetBrightness !== initialBrightness
|
&& targetBrightness !== initialBrightness
|
||||||
) {
|
) {
|
||||||
// Transition time set, known initial and target brightness
|
// Transition time set, known initial and target brightness
|
||||||
// Calculate transition interval time based on delta brightness and max steps per second
|
// Calculate transition interval time based on delta brightness and max steps per second
|
||||||
|
|
@ -452,23 +450,21 @@ class PlejBLE extends EventEmitter {
|
||||||
this.characteristics.lastData.StartNotify();
|
this.characteristics.lastData.StartNotify();
|
||||||
}
|
}
|
||||||
|
|
||||||
async throttledInit(delay) {
|
async throttledInit(delayMs) {
|
||||||
if (this.initInProgress) {
|
if (this.initInProgress) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'ThrottledInit already in progress. Skipping this call and returning existing promise.',
|
'ThrottledInit already in progress. Skipping this call and returning existing promise.',
|
||||||
);
|
);
|
||||||
return this.initInProgress;
|
return this.initInProgress;
|
||||||
}
|
}
|
||||||
this.initInProgress = new Promise((resolve) =>
|
this.initInProgress = new Promise((resolve) => setTimeout(async () => {
|
||||||
setTimeout(async () => {
|
|
||||||
const result = await this.init().catch((err) => {
|
const result = await this.init().catch((err) => {
|
||||||
logger.error('TrottledInit exception calling init(). Will re-throw.', err);
|
logger.error('TrottledInit exception calling init(). Will re-throw.', err);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
this.initInProgress = null;
|
this.initInProgress = null;
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}, delay),
|
}, delayMs));
|
||||||
);
|
|
||||||
return this.initInProgress;
|
return this.initInProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -562,8 +558,8 @@ class PlejBLE extends EventEmitter {
|
||||||
|
|
||||||
if (this.writeQueue.some((item) => item.deviceId === queueItem.deviceId)) {
|
if (this.writeQueue.some((item) => item.deviceId === queueItem.deviceId)) {
|
||||||
logger.verbose(
|
logger.verbose(
|
||||||
`Skipping ${deviceName} (${queueItem.deviceId}) ` +
|
`Skipping ${deviceName} (${queueItem.deviceId}) `
|
||||||
`${queueItem.log} due to more recent command in queue.`,
|
+ `${queueItem.log} due to more recent command in queue.`,
|
||||||
);
|
);
|
||||||
// Skip commands if new ones exist for the same deviceId
|
// Skip commands if new ones exist for the same deviceId
|
||||||
// still process all messages in order
|
// still process all messages in order
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue