added support for DIM-02 and to detect dim func
This commit is contained in:
parent
bedcd550ad
commit
457b41cb3c
2 changed files with 41 additions and 8 deletions
35
api.js
35
api.js
|
|
@ -90,14 +90,37 @@ class PlejdApi extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this.site.devices.length; i++) {
|
for (let i = 0; i < this.site.devices.length; i++) {
|
||||||
let device = this.site.devices[i];
|
const device = this.site.devices[i];
|
||||||
let deviceId = device.deviceId;
|
const deviceId = device.deviceId;
|
||||||
|
|
||||||
devices.push({
|
const settings = this.site.outputSettings.find(x => x.deviceParseId == device.objectId);
|
||||||
id: this.site.deviceAddress[deviceId],
|
let deviceNum = this.site.deviceAddress[deviceId];
|
||||||
|
|
||||||
|
if (settings) {
|
||||||
|
const outputs = this.site.outputAddress[deviceId];
|
||||||
|
deviceNum = outputs[settings.output];
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if device is dimmable
|
||||||
|
let dimmable = false;
|
||||||
|
if (device.hardware) {
|
||||||
|
dimmable = device.hardware.name == 'DIM-01';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings) {
|
||||||
|
dimmable = settings.dimCurve != 'NonDimmable';
|
||||||
|
}
|
||||||
|
|
||||||
|
const newDevice = {
|
||||||
|
id: deviceNum,
|
||||||
name: device.title,
|
name: device.title,
|
||||||
type: 'light'
|
type: 'light',
|
||||||
});
|
supportsDim: dimmable
|
||||||
|
};
|
||||||
|
|
||||||
|
logger(JSON.stringify(newDevice));
|
||||||
|
|
||||||
|
devices.push(newDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
return devices;
|
return devices;
|
||||||
|
|
|
||||||
14
mqtt.js
14
mqtt.js
|
|
@ -33,7 +33,7 @@ const getBrightnessCommandTopic = plug => `${getPath(plug)}/setBrightness`;
|
||||||
const getBrightnessTopic = plug => `${getPath(plug)}/brightness`;
|
const getBrightnessTopic = plug => `${getPath(plug)}/brightness`;
|
||||||
const getCommandTopic = plug => `${getPath(plug)}/set`;
|
const getCommandTopic = plug => `${getPath(plug)}/set`;
|
||||||
|
|
||||||
const getDiscoveryPayload = device => ({
|
const getDiscoveryDimmablePayload = device => ({
|
||||||
name: device.name,
|
name: device.name,
|
||||||
unique_id: `light.plejd.${device.name.toLowerCase().replace(/ /g, '')}`,
|
unique_id: `light.plejd.${device.name.toLowerCase().replace(/ /g, '')}`,
|
||||||
state_topic: getStateTopic(device),
|
state_topic: getStateTopic(device),
|
||||||
|
|
@ -45,6 +45,16 @@ const getDiscoveryPayload = device => ({
|
||||||
optimistic: false
|
optimistic: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getDiscoveryPayload = device => ({
|
||||||
|
name: device.name,
|
||||||
|
unique_id: `light.plejd.${device.name.toLowerCase().replace(/ /g, '')}`,
|
||||||
|
state_topic: getStateTopic(device),
|
||||||
|
command_topic: getCommandTopic(device),
|
||||||
|
payload_on: 1,
|
||||||
|
payload_off: 0,
|
||||||
|
optimistic: false
|
||||||
|
});
|
||||||
|
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
class MqttClient extends EventEmitter {
|
class MqttClient extends EventEmitter {
|
||||||
|
|
@ -124,7 +134,7 @@ class MqttClient extends EventEmitter {
|
||||||
devices.forEach((device) => {
|
devices.forEach((device) => {
|
||||||
logger(`sending discovery for ${device.name}`);
|
logger(`sending discovery for ${device.name}`);
|
||||||
|
|
||||||
const payload = getDiscoveryPayload(device);
|
const payload = device.supportsDim ? getDiscoveryDimmablePayload(device) : getDiscoveryPayload(device);
|
||||||
self.deviceMap[device.id] = payload.unique_id;
|
self.deviceMap[device.id] = payload.unique_id;
|
||||||
|
|
||||||
self.client.publish(
|
self.client.publish(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue