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
|
Object.keys(this.inputDevices).length
|
||||||
} output devices in total.`,
|
} 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} */
|
/** @param outputDevice {import('types/DeviceRegistry').OutputDevice} */
|
||||||
|
|
@ -157,7 +157,7 @@ class DeviceRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {import('./types/DeviceRegistry').InputDevice} */
|
/** @returns {import('./types/DeviceRegistry').InputDevice} */
|
||||||
getInputDeviceByBleOutputAddress(bleInputAddress, inputButton) {
|
getInputDeviceByBleInputAddress(bleInputAddress, inputButton) {
|
||||||
return this.inputDevices[this.outputUniqueIdByBleOutputAddress[`${bleInputAddress}_${inputButton}`]];
|
return this.inputDevices[this.outputUniqueIdByBleOutputAddress[`${bleInputAddress}_${inputButton}`]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ const getTopicName = (
|
||||||
/** @type { import('./types/Mqtt').TopicType } */ topicType,
|
/** @type { import('./types/Mqtt').TopicType } */ topicType,
|
||||||
) => `${getBaseTopic(uniqueId, mqttDeviceType)}/${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 getTriggerUniqueId = (/** @type { string } */ uniqueId) => `${uniqueId}_trigger`;
|
||||||
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 getSubscribePath = () => `${discoveryPrefix}/+/${nodeId}/#`;
|
||||||
|
|
@ -93,12 +93,9 @@ const getInputDeviceTriggerDiscoveryPayload = (
|
||||||
) => ({
|
) => ({
|
||||||
automation_type: 'trigger',
|
automation_type: 'trigger',
|
||||||
payload: `${inputDevice.input}`,
|
payload: `${inputDevice.input}`,
|
||||||
'~': getBaseTopic({
|
'~': getBaseTopic(inputDevice.deviceId, MQTT_TYPES.DEVICE_AUTOMATION),
|
||||||
uniqueId: inputDevice.deviceId,
|
|
||||||
type: 'device_automation',
|
|
||||||
}),
|
|
||||||
qos: 1,
|
qos: 1,
|
||||||
topic: `~/${TOPICS.STATE}`,
|
topic: `~/${TOPIC_TYPES.STATE}`,
|
||||||
type: 'button_short_press',
|
type: 'button_short_press',
|
||||||
subtype: `button_${inputDevice.input+1}`,
|
subtype: `button_${inputDevice.input+1}`,
|
||||||
device: {
|
device: {
|
||||||
|
|
@ -336,11 +333,11 @@ class MqttClient extends EventEmitter {
|
||||||
logger.debug(`Sending discovery for ${inputDevice.name}`);
|
logger.debug(`Sending discovery for ${inputDevice.name}`);
|
||||||
const inputInputPayload = getInputDeviceTriggerDiscoveryPayload(inputDevice);
|
const inputInputPayload = getInputDeviceTriggerDiscoveryPayload(inputDevice);
|
||||||
logger.info(
|
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,
|
retain: true,
|
||||||
qos: 1,
|
qos: 1,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @ts-ignore
|
|
||||||
const axios = require('axios').default;
|
const axios = require('axios').default;
|
||||||
const fs = require('fs');
|
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
|
// 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) => {
|
||||||
|
|
@ -403,7 +402,7 @@ class PlejdApi {
|
||||||
|
|
||||||
/** @type {import('types/DeviceRegistry').InputDevice} */
|
/** @type {import('types/DeviceRegistry').InputDevice} */
|
||||||
const inputDevice = {
|
const inputDevice = {
|
||||||
bleOutputAddress: bleInputAddress,
|
bleInputAddress: bleInputAddress,
|
||||||
deviceId: device.deviceId,
|
deviceId: device.deviceId,
|
||||||
name: device.title,
|
name: device.title,
|
||||||
input: input.input,
|
input: input.input,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// @ts-ignore
|
|
||||||
const dbus = require('dbus-next');
|
const dbus = require('dbus-next');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const xor = require('buffer-xor');
|
const xor = require('buffer-xor');
|
||||||
|
|
@ -912,7 +911,7 @@ 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.getInputDeviceByBleOutputAddress(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`,
|
||||||
|
|
|
||||||
2
plejd/types/ApiSite.d.ts
vendored
2
plejd/types/ApiSite.d.ts
vendored
|
|
@ -280,6 +280,8 @@ export interface InputSetting {
|
||||||
|
|
||||||
export enum ButtonType {
|
export enum ButtonType {
|
||||||
PushButton = 'PushButton',
|
PushButton = 'PushButton',
|
||||||
|
DirectionUp = 'DirectionUp',
|
||||||
|
DirectionDown = 'DirectionDown',
|
||||||
RotateMesh = 'RotateMesh',
|
RotateMesh = 'RotateMesh',
|
||||||
Scene = 'Scene',
|
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 type InputDevices = { [deviceIdAndOutput: string]: InputDevice };
|
||||||
|
|
||||||
export interface InputDevice {
|
export interface InputDevice {
|
||||||
bleOutputAddress: number;
|
bleInputAddress: number;
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
name: string;
|
name: string;
|
||||||
input: number;
|
input: number;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue