Linting of all fixes
This commit is contained in:
parent
fc23230490
commit
cacd9fc4ba
7 changed files with 55 additions and 34 deletions
|
|
@ -66,8 +66,8 @@ class DeviceRegistry {
|
|||
this.outputDeviceUniqueIdsByRoomId[outputDevice.roomId] = [];
|
||||
}
|
||||
if (
|
||||
outputDevice.roomId !== outputDevice.uniqueId
|
||||
&& !this.outputDeviceUniqueIdsByRoomId[outputDevice.roomId].includes(outputDevice.uniqueId)
|
||||
outputDevice.roomId !== outputDevice.uniqueId &&
|
||||
!this.outputDeviceUniqueIdsByRoomId[outputDevice.roomId].includes(outputDevice.uniqueId)
|
||||
) {
|
||||
this.outputDeviceUniqueIdsByRoomId[outputDevice.roomId].push(outputDevice.uniqueId);
|
||||
logger.verbose(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
const winston = require('winston');
|
||||
|
||||
const {
|
||||
colorize, combine, label, printf, timestamp,
|
||||
} = winston.format;
|
||||
const { colorize, combine, label, printf, timestamp } = winston.format;
|
||||
|
||||
const Configuration = require('./Configuration');
|
||||
|
||||
|
|
@ -34,15 +32,17 @@ class Logger {
|
|||
static getLogLevel() {
|
||||
const config = Configuration.getOptions();
|
||||
// eslint-disable-next-line max-len
|
||||
const level = (config.logLevel && LEVELS.find((l) => l.startsWith(config.logLevel[0].toLowerCase())))
|
||||
|| 'info';
|
||||
const level =
|
||||
(config.logLevel && LEVELS.find((l) => l.startsWith(config.logLevel[0].toLowerCase()))) ||
|
||||
'info';
|
||||
return level;
|
||||
}
|
||||
|
||||
static shouldLog(logLevel) {
|
||||
if (!Logger.shouldLogLookup[logLevel]) {
|
||||
// eslint-disable-next-line max-len
|
||||
Logger.shouldLogLookup[logLevel] = Logger.logLevels().levels[logLevel] <= Logger.logLevels().levels[Logger.getLogLevel()];
|
||||
Logger.shouldLogLookup[logLevel] =
|
||||
Logger.logLevels().levels[logLevel] <= Logger.logLevels().levels[Logger.getLogLevel()];
|
||||
}
|
||||
return Logger.shouldLogLookup[logLevel];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ const TOPIC_TYPES = {
|
|||
COMMAND: 'set',
|
||||
};
|
||||
|
||||
const getBaseTopic = (/** @type { string } */ uniqueId, /** @type { string } */ mqttDeviceType) => `${discoveryPrefix}/${mqttDeviceType}/${nodeId}/${uniqueId}`;
|
||||
const getBaseTopic = (/** @type { string } */ uniqueId, /** @type { string } */ mqttDeviceType) =>
|
||||
`${discoveryPrefix}/${mqttDeviceType}/${nodeId}/${uniqueId}`;
|
||||
|
||||
const getTopicName = (
|
||||
/** @type { string } */ uniqueId,
|
||||
|
|
@ -35,9 +36,11 @@ const getTopicName = (
|
|||
/** @type { import('./types/Mqtt').TopicType } */ topicType,
|
||||
) => `${getBaseTopic(uniqueId, mqttDeviceType)}/${topicType}`;
|
||||
|
||||
const getButtonEventTopic = (/** @type {string} */ deviceId) => `${getTopicName(deviceId, MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`;
|
||||
const getButtonEventTopic = (/** @type {string} */ deviceId) =>
|
||||
`${getTopicName(deviceId, MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`;
|
||||
const getTriggerUniqueId = (/** @type { string } */ uniqueId) => `${uniqueId}_trig`;
|
||||
const getSceneEventTopic = (/** @type {string} */ sceneId) => `${getTopicName(getTriggerUniqueId(sceneId), MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`;
|
||||
const getSceneEventTopic = (/** @type {string} */ sceneId) =>
|
||||
`${getTopicName(getTriggerUniqueId(sceneId), MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`;
|
||||
const getSubscribePath = () => `${discoveryPrefix}/+/${nodeId}/#`;
|
||||
|
||||
const decodeTopicRegexp = new RegExp(
|
||||
|
|
|
|||
|
|
@ -293,7 +293,8 @@ class PlejdApi {
|
|||
case 6:
|
||||
return {
|
||||
name: 'WPH-01',
|
||||
description: 'Wireless push button, 4 buttons. 2 channels, on and off buttons for each channel',
|
||||
description:
|
||||
'Wireless push button, 4 buttons. 2 channels, on and off buttons for each channel',
|
||||
type: 'device_automation',
|
||||
dimmable: false,
|
||||
broadcastClicks: true,
|
||||
|
|
@ -481,13 +482,19 @@ class PlejdApi {
|
|||
};
|
||||
|
||||
this.deviceRegistry.addOutputDevice(outputDevice);
|
||||
|
||||
} catch (error) {
|
||||
logger.error(`Error trying to create output device: ${error}`);
|
||||
logger.warn(`device (from API response) when error happened: ${JSON.stringify(device, null, 2)}`);
|
||||
logger.warn(`plejdDevice (from API response) when error happened: ${JSON.stringify(plejdDevice, null, 2)}`);
|
||||
logger.warn(
|
||||
`device (from API response) when error happened: ${JSON.stringify(device, null, 2)}`,
|
||||
);
|
||||
logger.warn(
|
||||
`plejdDevice (from API response) when error happened: ${JSON.stringify(
|
||||
plejdDevice,
|
||||
null,
|
||||
2,
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// The device does not have an output. It can be assumed to be a WPH-01 or a WRT-01
|
||||
|
|
@ -530,8 +537,16 @@ class PlejdApi {
|
|||
}
|
||||
} catch (error) {
|
||||
logger.error(`Error trying to create input device: ${error}`);
|
||||
logger.warn(`device (from API response) when error happened: ${JSON.stringify(device, null, 2)}`);
|
||||
logger.warn(`plejdDevice (from API response) when error happened: ${JSON.stringify(plejdDevice, null, 2)}`);
|
||||
logger.warn(
|
||||
`device (from API response) when error happened: ${JSON.stringify(device, null, 2)}`,
|
||||
);
|
||||
logger.warn(
|
||||
`plejdDevice (from API response) when error happened: ${JSON.stringify(
|
||||
plejdDevice,
|
||||
null,
|
||||
2,
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -547,8 +562,9 @@ class PlejdApi {
|
|||
|
||||
const deviceIdsByRoom = this.deviceRegistry.getOutputDeviceIdsByRoomId(roomId);
|
||||
|
||||
const dimmable = deviceIdsByRoom
|
||||
&& deviceIdsByRoom.some(
|
||||
const dimmable =
|
||||
deviceIdsByRoom &&
|
||||
deviceIdsByRoom.some(
|
||||
(deviceId) => this.deviceRegistry.getOutputDevice(deviceId).dimmable,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -414,7 +414,9 @@ class PlejBLEHandler extends EventEmitter {
|
|||
|
||||
async _startGetPlejdDevice() {
|
||||
logger.verbose('Setting up interfacesAdded subscription and discovery filter');
|
||||
this.objectManager.on('InterfacesAdded', (path, interfaces) => this._onInterfacesAdded(path, interfaces));
|
||||
this.objectManager.on('InterfacesAdded', (path, interfaces) =>
|
||||
this._onInterfacesAdded(path, interfaces),
|
||||
);
|
||||
|
||||
this.adapter.SetDiscoveryFilter({
|
||||
UUIDs: new dbus.Variant('as', [PLEJD_SERVICE]),
|
||||
|
|
@ -873,9 +875,9 @@ class PlejBLEHandler extends EventEmitter {
|
|||
const plejdTimestampUTC = (decoded.readInt32LE(5) + offsetSecondsGuess) * 1000;
|
||||
const diffSeconds = Math.round((plejdTimestampUTC - now.getTime()) / 1000);
|
||||
if (
|
||||
bleOutputAddress !== BLE_BROADCAST_DEVICE_ID
|
||||
|| Logger.shouldLog('verbose')
|
||||
|| Math.abs(diffSeconds) > 60
|
||||
bleOutputAddress !== BLE_BROADCAST_DEVICE_ID ||
|
||||
Logger.shouldLog('verbose') ||
|
||||
Math.abs(diffSeconds) > 60
|
||||
) {
|
||||
const plejdTime = new Date(plejdTimestampUTC);
|
||||
logger.debug(
|
||||
|
|
|
|||
|
|
@ -140,11 +140,11 @@ class PlejdDeviceCommunication extends EventEmitter {
|
|||
const isDimmable = this.deviceRegistry.getOutputDevice(uniqueOutputId).dimmable;
|
||||
|
||||
if (
|
||||
transition > 1
|
||||
&& isDimmable
|
||||
&& (initialBrightness || initialBrightness === 0)
|
||||
&& (targetBrightness || targetBrightness === 0)
|
||||
&& targetBrightness !== initialBrightness
|
||||
transition > 1 &&
|
||||
isDimmable &&
|
||||
(initialBrightness || initialBrightness === 0) &&
|
||||
(targetBrightness || targetBrightness === 0) &&
|
||||
targetBrightness !== initialBrightness
|
||||
) {
|
||||
// Transition time set, known initial and target brightness
|
||||
// Calculate transition interval time based on delta brightness and max steps per second
|
||||
|
|
@ -269,8 +269,8 @@ class PlejdDeviceCommunication extends EventEmitter {
|
|||
|
||||
if (this.writeQueue.some((item) => item.uniqueOutputId === queueItem.uniqueOutputId)) {
|
||||
logger.verbose(
|
||||
`Skipping ${device.name} (${queueItem.uniqueOutputId}) `
|
||||
+ `${queueItem.command} due to more recent command in queue.`,
|
||||
`Skipping ${device.name} (${queueItem.uniqueOutputId}) ` +
|
||||
`${queueItem.command} due to more recent command in queue.`,
|
||||
);
|
||||
// Skip commands if new ones exist for the same uniqueOutputId
|
||||
// still process all messages in order
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@
|
|||
"scripts": {
|
||||
"lint": "npm run lint:prettier & npm run lint:scripts",
|
||||
"lint:fix": "npm run lint:prettier:fix & npm run lint:scripts:fix",
|
||||
"lint:prettier": "prettier --check \"**/*.{js*,md}\"",
|
||||
"lint:prettier:fix": "prettier --check --write \"**/*.{js*,md}\"",
|
||||
"lint:prettier": "prettier --check --config ../.prettierrc.js \"**/*.{js*,md}\"",
|
||||
"lint:prettier:fix": "prettier --check --config ../.prettierrc.js --write \"**/*.{js*,md}\"",
|
||||
"lint:scripts": "eslint --config ./.eslintrc.js \"**/*.js\"",
|
||||
"lint:scripts:fix": "eslint --config ./.eslintrc.js --fix \"**/*.js\""
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue