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.`,
);
this.outputUniqueIdByBleOutputAddress[`${inputDevice.bleInputAddress}_${inputDevice.input}`] = inputDevice.uniqueId;
};
}
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
addOutputDevice(outputDevice) {
@ -158,7 +158,9 @@ class DeviceRegistry {
/** @returns {import('./types/DeviceRegistry').InputDevice} */
getInputDeviceByBleInputAddress(bleInputAddress, inputButton) {
return this.inputDevices[this.outputUniqueIdByBleOutputAddress[`${bleInputAddress}_${inputButton}`]];
return this.inputDevices[
this.outputUniqueIdByBleOutputAddress[`${bleInputAddress}_${inputButton}`]
];
}
/** @returns {string[]} */

View file

@ -96,7 +96,7 @@ const getInputDeviceTriggerDiscoveryPayload = (
qos: 1,
topic: `~/${TOPIC_TYPES.STATE}`,
type: 'button_short_press',
subtype: `button_${inputDevice.input+1}`,
subtype: `button_${inputDevice.input + 1}`,
device: {
identifiers: `${inputDevice.deviceId}`,
manufacturer: 'Plejd',
@ -105,7 +105,6 @@ const getInputDeviceTriggerDiscoveryPayload = (
},
});
const getSceneDeviceTriggerhDiscoveryPayload = (
/** @type {import('./types/DeviceRegistry').OutputDevice} */ sceneDevice,
) => ({
@ -334,15 +333,24 @@ class MqttClient extends EventEmitter {
logger.info(
`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,
qos: 1,
},
);
});
})
const allSceneDevices = this.deviceRegistry.getAllSceneDevices();
logger.info(`Sending discovery for ${allSceneDevices.length} Plejd scene devices`);
allSceneDevices.forEach((sceneDevice) => {
@ -442,6 +450,7 @@ class MqttClient extends EventEmitter {
logger.verbose(`Button ${data.deviceInput} pressed for deviceId ${data.deviceId}`);
this.client.publish(getButtonEventTopic(data.deviceId), `${data.deviceInput}`, { qos: 1 });
}
/**
* @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
// Filter inputSettings for available buttons
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
inputSettings.forEach((input) => {
const bleInputAddress = this.siteDetails.deviceAddress[input.deviceId];
logger.verbose(
`Found input device (${input.deviceId}), with input ${input.input} having BLE address (${bleInputAddress})`,
@ -393,16 +396,13 @@ class PlejdApi {
(x) => x.deviceId === device.deviceId,
);
const uniqueInputId = this.deviceRegistry.getUniqueInputId(
device.deviceId,
input.input,
);
const uniqueInputId = this.deviceRegistry.getUniqueInputId(device.deviceId, input.input);
const { name: typeName, type } = this._getDeviceType(plejdDevice);
/** @type {import('types/DeviceRegistry').InputDevice} */
const inputDevice = {
bleInputAddress: bleInputAddress,
bleInputAddress,
deviceId: device.deviceId,
name: device.title,
input: input.input,
@ -414,7 +414,7 @@ class PlejdApi {
};
this.deviceRegistry.addInputDevice(inputDevice);
});
};
}
});
}

View file

@ -911,7 +911,10 @@ class PlejBLEHandler extends EventEmitter {
const inputBleAddress = state;
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) {
logger.warn(
`Scene with BLE address ${inputBleAddress} could not be found, can't process message`,
@ -919,10 +922,10 @@ class PlejBLEHandler extends EventEmitter {
return;
}
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;
data = { deviceId: sourceDevice.deviceId, deviceInput: sourceDevice.input};
data = { deviceId: sourceDevice.deviceId, deviceInput: sourceDevice.input };
this.emit(PlejBLEHandler.EVENTS.commandReceived, outputUniqueId, command, data);
} else {
logger.verbose(