Updates based om comments from @SweVictor
This commit is contained in:
parent
531aa8ee3e
commit
c8890b8cd7
5 changed files with 29 additions and 15 deletions
|
|
@ -42,7 +42,9 @@ class DeviceRegistry {
|
||||||
Object.keys(this.inputDevices).length
|
Object.keys(this.inputDevices).length
|
||||||
} output devices in total.`,
|
} output devices in total.`,
|
||||||
);
|
);
|
||||||
this.outputUniqueIdByBleOutputAddress[`${inputDevice.bleInputAddress}_${inputDevice.input}`] = inputDevice.uniqueId;
|
this.outputUniqueIdByBleOutputAddress[
|
||||||
|
this.getUniqueBLEId(inputDevice.bleInputAddress, inputDevice.input)
|
||||||
|
] = inputDevice.uniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
|
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
|
||||||
|
|
@ -159,7 +161,7 @@ class DeviceRegistry {
|
||||||
/** @returns {import('./types/DeviceRegistry').InputDevice} */
|
/** @returns {import('./types/DeviceRegistry').InputDevice} */
|
||||||
getInputDeviceByBleInputAddress(bleInputAddress, inputButton) {
|
getInputDeviceByBleInputAddress(bleInputAddress, inputButton) {
|
||||||
return this.inputDevices[
|
return this.inputDevices[
|
||||||
this.outputUniqueIdByBleOutputAddress[`${bleInputAddress}_${inputButton}`]
|
this.outputUniqueIdByBleOutputAddress[this.getUniqueBLEId(bleInputAddress, inputButton)]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,7 +218,12 @@ class DeviceRegistry {
|
||||||
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
// eslint-disable-next-line class-methods-use-this
|
||||||
getUniqueInputId(deviceId, inputIndex) {
|
getUniqueInputId(deviceId, inputIndex) {
|
||||||
return `${deviceId}_${inputIndex}`;
|
return `${deviceId}_I_${inputIndex}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line class-methods-use-this
|
||||||
|
getUniqueBLEId(bleAdress, inputIndex) {
|
||||||
|
return `${bleAdress}_${inputIndex}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param apiSite {import('./types/ApiSite').ApiSite} */
|
/** @param apiSite {import('./types/ApiSite').ApiSite} */
|
||||||
|
|
|
||||||
|
|
@ -446,9 +446,13 @@ class MqttClient extends EventEmitter {
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonPressed(data) {
|
/**
|
||||||
logger.verbose(`Button ${data.deviceInput} pressed for deviceId ${data.deviceId}`);
|
* @param {string} deviceId
|
||||||
this.client.publish(getButtonEventTopic(data.deviceId), `${data.deviceInput}`, { qos: 1 });
|
* @param {string} deviceInput
|
||||||
|
*/
|
||||||
|
buttonPressed(deviceId, deviceInput) {
|
||||||
|
logger.verbose(`Button ${deviceInput} pressed for deviceId ${deviceId}`);
|
||||||
|
this.client.publish(getButtonEventTopic(deviceId), `${deviceInput}`, { qos: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -126,13 +126,16 @@ class PlejdAddon extends EventEmitter {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
this.plejdDeviceCommunication.on(PlejdDeviceCommunication.EVENTS.buttonPressed, (data) => {
|
this.plejdDeviceCommunication.on(
|
||||||
try {
|
PlejdDeviceCommunication.EVENTS.buttonPressed,
|
||||||
this.mqttClient.buttonPressed(data);
|
(deviceId, deviceInput) => {
|
||||||
} catch (err) {
|
try {
|
||||||
logger.error('Error in PlejdService.sceneTriggered callback', err);
|
this.mqttClient.buttonPressed(deviceId, deviceInput);
|
||||||
}
|
} catch (err) {
|
||||||
});
|
logger.error('Error in PlejdService.buttonPressed callback', err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
this.plejdDeviceCommunication.on(PlejdDeviceCommunication.EVENTS.sceneTriggered, (sceneId) => {
|
this.plejdDeviceCommunication.on(PlejdDeviceCommunication.EVENTS.sceneTriggered, (sceneId) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -922,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}`,
|
`A button (eg. WPH-01, WRT-01) ${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 };
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ class PlejdDeviceCommunication extends EventEmitter {
|
||||||
} else if (command === COMMANDS.TRIGGER_SCENE) {
|
} else if (command === COMMANDS.TRIGGER_SCENE) {
|
||||||
this.emit(PlejdDeviceCommunication.EVENTS.sceneTriggered, data.sceneId);
|
this.emit(PlejdDeviceCommunication.EVENTS.sceneTriggered, data.sceneId);
|
||||||
} else if (command === COMMANDS.BUTTON_CLICK) {
|
} else if (command === COMMANDS.BUTTON_CLICK) {
|
||||||
this.emit(PlejdDeviceCommunication.EVENTS.buttonPressed, data);
|
this.emit(PlejdDeviceCommunication.EVENTS.buttonPressed, data.deviceId, data.deviceInput);
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`Unknown ble command ${command}`);
|
logger.warn(`Unknown ble command ${command}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue