Updated to match the latest developer branch and modified according to feedback from review.
This commit is contained in:
parent
cbcd33fde6
commit
78e1616b4e
6 changed files with 14 additions and 17 deletions
|
|
@ -42,7 +42,7 @@ class DeviceRegistry {
|
|||
Object.keys(this.inputDevices).length
|
||||
} output devices in total.`,
|
||||
);
|
||||
this.outputUniqueIdByBleOutputAddress[`${inputDevice.bleOutputAddress}_${inputDevice.input}`] = inputDevice.uniqueId;
|
||||
this.outputUniqueIdByBleOutputAddress[`${inputDevice.bleInputAddress}_${inputDevice.input}`] = inputDevice.uniqueId;
|
||||
};
|
||||
|
||||
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
|
||||
|
|
@ -157,7 +157,7 @@ class DeviceRegistry {
|
|||
}
|
||||
|
||||
/** @returns {import('./types/DeviceRegistry').InputDevice} */
|
||||
getInputDeviceByBleOutputAddress(bleInputAddress, inputButton) {
|
||||
getInputDeviceByBleInputAddress(bleInputAddress, inputButton) {
|
||||
return this.inputDevices[this.outputUniqueIdByBleOutputAddress[`${bleInputAddress}_${inputButton}`]];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ const getTopicName = (
|
|||
/** @type { import('./types/Mqtt').TopicType } */ topicType,
|
||||
) => `${getBaseTopic(uniqueId, mqttDeviceType)}/${topicType}`;
|
||||
|
||||
const getButtonEventTopic = (deviceId) => `${getTopicName({ uniqueId: `${deviceId}`, type: 'device_automation' }, 'state')}`;
|
||||
const getButtonEventTopic = (/** @type {string} */ deviceId) => `${getTopicName(getTriggerUniqueId(deviceId), MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`;
|
||||
const getTriggerUniqueId = (/** @type { string } */ uniqueId) => `${uniqueId}_trigger`;
|
||||
const getSceneEventTopic = (/** @type {string} */ sceneId) => `${getTopicName(getTriggerUniqueId(sceneId), MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.STATE)}`;
|
||||
const getSubscribePath = () => `${discoveryPrefix}/+/${nodeId}/#`;
|
||||
|
|
@ -93,12 +93,9 @@ const getInputDeviceTriggerDiscoveryPayload = (
|
|||
) => ({
|
||||
automation_type: 'trigger',
|
||||
payload: `${inputDevice.input}`,
|
||||
'~': getBaseTopic({
|
||||
uniqueId: inputDevice.deviceId,
|
||||
type: 'device_automation',
|
||||
}),
|
||||
'~': getBaseTopic(inputDevice.deviceId, MQTT_TYPES.DEVICE_AUTOMATION),
|
||||
qos: 1,
|
||||
topic: `~/${TOPICS.STATE}`,
|
||||
topic: `~/${TOPIC_TYPES.STATE}`,
|
||||
type: 'button_short_press',
|
||||
subtype: `button_${inputDevice.input+1}`,
|
||||
device: {
|
||||
|
|
@ -336,11 +333,11 @@ class MqttClient extends EventEmitter {
|
|||
logger.debug(`Sending discovery for ${inputDevice.name}`);
|
||||
const inputInputPayload = getInputDeviceTriggerDiscoveryPayload(inputDevice);
|
||||
logger.info(
|
||||
`Discovered ${inputDevice.typeName} (${inputDevice.type}) named ${inputDevice.name} (${inputDevice.bleOutputAddress} : ${inputDevice.uniqueId}).`,
|
||||
`Discovered ${inputDevice.typeName} (${inputDevice.type}) named ${inputDevice.name} (${inputDevice.bleInputAddress} : ${inputDevice.uniqueId}).`,
|
||||
);
|
||||
logger.verbose(`Publishing ${getTopicName(inputDevice, '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, 'config'), JSON.stringify(inputInputPayload), {
|
||||
this.client.publish(getTopicName(inputDevice.uniqueId, MQTT_TYPES.DEVICE_AUTOMATION, TOPIC_TYPES.CONFIG), JSON.stringify(inputInputPayload), {
|
||||
retain: true,
|
||||
qos: 1,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
// @ts-ignore
|
||||
const axios = require('axios').default;
|
||||
const fs = require('fs');
|
||||
|
||||
|
|
@ -380,7 +379,7 @@ 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) => {
|
||||
|
|
@ -403,7 +402,7 @@ class PlejdApi {
|
|||
|
||||
/** @type {import('types/DeviceRegistry').InputDevice} */
|
||||
const inputDevice = {
|
||||
bleOutputAddress: bleInputAddress,
|
||||
bleInputAddress: bleInputAddress,
|
||||
deviceId: device.deviceId,
|
||||
name: device.title,
|
||||
input: input.input,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
// @ts-ignore
|
||||
const dbus = require('dbus-next');
|
||||
const crypto = require('crypto');
|
||||
const xor = require('buffer-xor');
|
||||
|
|
@ -912,7 +911,7 @@ class PlejBLEHandler extends EventEmitter {
|
|||
const inputBleAddress = state;
|
||||
const inputButton = decoded.length > 7 ? decoded.readUInt8(6) : 0;
|
||||
|
||||
const sourceDevice = this.deviceRegistry.getInputDeviceByBleOutputAddress(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`,
|
||||
|
|
|
|||
2
plejd/types/ApiSite.d.ts
vendored
2
plejd/types/ApiSite.d.ts
vendored
|
|
@ -280,6 +280,8 @@ export interface InputSetting {
|
|||
|
||||
export enum ButtonType {
|
||||
PushButton = 'PushButton',
|
||||
DirectionUp = 'DirectionUp',
|
||||
DirectionDown = 'DirectionDown',
|
||||
RotateMesh = 'RotateMesh',
|
||||
Scene = 'Scene',
|
||||
}
|
||||
|
|
|
|||
2
plejd/types/DeviceRegistry.d.ts
vendored
2
plejd/types/DeviceRegistry.d.ts
vendored
|
|
@ -23,7 +23,7 @@ export interface OutputDevice {
|
|||
export type InputDevices = { [deviceIdAndOutput: string]: InputDevice };
|
||||
|
||||
export interface InputDevice {
|
||||
bleOutputAddress: number;
|
||||
bleInputAddress: number;
|
||||
deviceId: string;
|
||||
name: string;
|
||||
input: number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue