diff --git a/plejd/DeviceRegistry.js b/plejd/DeviceRegistry.js index 91efd55..951652e 100644 --- a/plejd/DeviceRegistry.js +++ b/plejd/DeviceRegistry.js @@ -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( diff --git a/plejd/Logger.js b/plejd/Logger.js index 19bf436..3b6f7b7 100644 --- a/plejd/Logger.js +++ b/plejd/Logger.js @@ -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]; } diff --git a/plejd/MqttClient.js b/plejd/MqttClient.js index 5be9434..57f1262 100644 --- a/plejd/MqttClient.js +++ b/plejd/MqttClient.js @@ -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( diff --git a/plejd/PlejdApi.js b/plejd/PlejdApi.js index 4c847f8..cc12990 100644 --- a/plejd/PlejdApi.js +++ b/plejd/PlejdApi.js @@ -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, @@ -391,7 +392,7 @@ class PlejdApi { dimmable: true, broadcastClicks: false, }; - default: + default: throw new Error(`Unknown device type with id ${plejdDevice.hardwareId}`); } } @@ -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, ); diff --git a/plejd/PlejdBLEHandler.js b/plejd/PlejdBLEHandler.js index 0a69961..6e943d8 100644 --- a/plejd/PlejdBLEHandler.js +++ b/plejd/PlejdBLEHandler.js @@ -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( diff --git a/plejd/PlejdDeviceCommunication.js b/plejd/PlejdDeviceCommunication.js index 8626b69..9b38604 100644 --- a/plejd/PlejdDeviceCommunication.js +++ b/plejd/PlejdDeviceCommunication.js @@ -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 diff --git a/plejd/package.json b/plejd/package.json index fc10eb1..0dc856a 100644 --- a/plejd/package.json +++ b/plejd/package.json @@ -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\"" }