Fixed errors from npm run lint:fix

This commit is contained in:
faanskit 2021-05-05 19:34:34 +02:00
parent 2610c1eaa4
commit 531aa8ee3e
4 changed files with 63 additions and 49 deletions

View file

@ -43,7 +43,7 @@ class DeviceRegistry {
} output devices in total.`, } output devices in total.`,
); );
this.outputUniqueIdByBleOutputAddress[`${inputDevice.bleInputAddress}_${inputDevice.input}`] = inputDevice.uniqueId; this.outputUniqueIdByBleOutputAddress[`${inputDevice.bleInputAddress}_${inputDevice.input}`] = inputDevice.uniqueId;
}; }
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */ /** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
addOutputDevice(outputDevice) { addOutputDevice(outputDevice) {
@ -158,7 +158,9 @@ class DeviceRegistry {
/** @returns {import('./types/DeviceRegistry').InputDevice} */ /** @returns {import('./types/DeviceRegistry').InputDevice} */
getInputDeviceByBleInputAddress(bleInputAddress, inputButton) { getInputDeviceByBleInputAddress(bleInputAddress, inputButton) {
return this.inputDevices[this.outputUniqueIdByBleOutputAddress[`${bleInputAddress}_${inputButton}`]]; return this.inputDevices[
this.outputUniqueIdByBleOutputAddress[`${bleInputAddress}_${inputButton}`]
];
} }
/** @returns {string[]} */ /** @returns {string[]} */

View file

@ -105,7 +105,6 @@ const getInputDeviceTriggerDiscoveryPayload = (
}, },
}); });
const getSceneDeviceTriggerhDiscoveryPayload = ( const getSceneDeviceTriggerhDiscoveryPayload = (
/** @type {import('./types/DeviceRegistry').OutputDevice} */ sceneDevice, /** @type {import('./types/DeviceRegistry').OutputDevice} */ sceneDevice,
) => ({ ) => ({
@ -334,15 +333,24 @@ class MqttClient extends EventEmitter {
logger.info( logger.info(
`Discovered ${inputDevice.typeName} (${inputDevice.type}) named ${inputDevice.name} (${inputDevice.bleInputAddress} : ${inputDevice.uniqueId}).`, `Discovered ${inputDevice.typeName} (${inputDevice.type}) named ${inputDevice.name} (${inputDevice.bleInputAddress} : ${inputDevice.uniqueId}).`,
); );
logger.verbose(`Publishing ${getTopicName(inputDevice.uniqueId, MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.CONFIG)} with payload ${JSON.stringify(inputInputPayload)}`); logger.verbose(
`Publishing ${getTopicName(
inputDevice.uniqueId,
MQTT_TYPES.DEVICE_AUTOMATION,
TOPIC_TYPES.CONFIG,
)} with payload ${JSON.stringify(inputInputPayload)}`,
);
this.client.publish(getTopicName(inputDevice.uniqueId, MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.CONFIG), JSON.stringify(inputInputPayload), { this.client.publish(
getTopicName(inputDevice.uniqueId, MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.CONFIG),
JSON.stringify(inputInputPayload),
{
retain: true, retain: true,
qos: 1, qos: 1,
},
);
}); });
})
const allSceneDevices = this.deviceRegistry.getAllSceneDevices(); const allSceneDevices = this.deviceRegistry.getAllSceneDevices();
logger.info(`Sending discovery for ${allSceneDevices.length} Plejd scene devices`); logger.info(`Sending discovery for ${allSceneDevices.length} Plejd scene devices`);
allSceneDevices.forEach((sceneDevice) => { allSceneDevices.forEach((sceneDevice) => {
@ -442,6 +450,7 @@ class MqttClient extends EventEmitter {
logger.verbose(`Button ${data.deviceInput} pressed for deviceId ${data.deviceId}`); logger.verbose(`Button ${data.deviceInput} pressed for deviceId ${data.deviceId}`);
this.client.publish(getButtonEventTopic(data.deviceId), `${data.deviceInput}`, { qos: 1 }); this.client.publish(getButtonEventTopic(data.deviceId), `${data.deviceInput}`, { qos: 1 });
} }
/** /**
* @param {string} sceneId * @param {string} sceneId
*/ */

View file

@ -379,11 +379,14 @@ class PlejdApi {
// The device does not have an output. It can be assumed to be a WPH-01 or a WRT-01 // The device does not have an output. It can be assumed to be a WPH-01 or a WRT-01
// Filter inputSettings for available buttons // Filter inputSettings for available buttons
const inputSettings = this.siteDetails.inputSettings.filter( const inputSettings = this.siteDetails.inputSettings.filter(
(x) => x.deviceId === device.deviceId && ((x.buttonType == 'DirectionUp') || (x.buttonType == 'DirectionDown') || (x.buttonType == 'RotateMesh'))); (x) => x.deviceId === device.deviceId
&& (x.buttonType === 'DirectionUp'
|| x.buttonType === 'DirectionDown'
|| x.buttonType === 'RotateMesh'),
);
// For each found button, register the device as an inputDevice // For each found button, register the device as an inputDevice
inputSettings.forEach((input) => { inputSettings.forEach((input) => {
const bleInputAddress = this.siteDetails.deviceAddress[input.deviceId]; const bleInputAddress = this.siteDetails.deviceAddress[input.deviceId];
logger.verbose( logger.verbose(
`Found input device (${input.deviceId}), with input ${input.input} having BLE address (${bleInputAddress})`, `Found input device (${input.deviceId}), with input ${input.input} having BLE address (${bleInputAddress})`,
@ -393,16 +396,13 @@ class PlejdApi {
(x) => x.deviceId === device.deviceId, (x) => x.deviceId === device.deviceId,
); );
const uniqueInputId = this.deviceRegistry.getUniqueInputId( const uniqueInputId = this.deviceRegistry.getUniqueInputId(device.deviceId, input.input);
device.deviceId,
input.input,
);
const { name: typeName, type } = this._getDeviceType(plejdDevice); const { name: typeName, type } = this._getDeviceType(plejdDevice);
/** @type {import('types/DeviceRegistry').InputDevice} */ /** @type {import('types/DeviceRegistry').InputDevice} */
const inputDevice = { const inputDevice = {
bleInputAddress: bleInputAddress, bleInputAddress,
deviceId: device.deviceId, deviceId: device.deviceId,
name: device.title, name: device.title,
input: input.input, input: input.input,
@ -414,7 +414,7 @@ class PlejdApi {
}; };
this.deviceRegistry.addInputDevice(inputDevice); this.deviceRegistry.addInputDevice(inputDevice);
}); });
}; }
}); });
} }

View file

@ -911,7 +911,10 @@ class PlejBLEHandler extends EventEmitter {
const inputBleAddress = state; const inputBleAddress = state;
const inputButton = decoded.length > 7 ? decoded.readUInt8(6) : 0; const inputButton = decoded.length > 7 ? decoded.readUInt8(6) : 0;
const sourceDevice = this.deviceRegistry.getInputDeviceByBleInputAddress(inputBleAddress, inputButton); const sourceDevice = this.deviceRegistry.getInputDeviceByBleInputAddress(
inputBleAddress,
inputButton,
);
if (!sourceDevice) { if (!sourceDevice) {
logger.warn( logger.warn(
`Scene with BLE address ${inputBleAddress} could not be found, can't process message`, `Scene with BLE address ${inputBleAddress} could not be found, can't process message`,
@ -919,7 +922,7 @@ class PlejBLEHandler extends EventEmitter {
return; return;
} }
logger.verbose( logger.verbose(
`WPH-10 button ${inputButton} at BLE address ${inputBleAddress} was pressed. Unique Id is ${sourceDevice.uniqueId}` `WPH-10 button ${inputButton} at BLE address ${inputBleAddress} was pressed. Unique Id is ${sourceDevice.uniqueId}`,
); );
command = COMMANDS.BUTTON_CLICK; command = COMMANDS.BUTTON_CLICK;
data = { deviceId: sourceDevice.deviceId, deviceInput: sourceDevice.input }; data = { deviceId: sourceDevice.deviceId, deviceInput: sourceDevice.input };