added info about device type and ids
This commit is contained in:
parent
75e9539b5a
commit
a7e491adf6
2 changed files with 62 additions and 8 deletions
58
api.js
58
api.js
|
|
@ -101,11 +101,9 @@ class PlejdApi extends EventEmitter {
|
|||
deviceNum = outputs[settings.output];
|
||||
}
|
||||
|
||||
// check if device is dimmable
|
||||
let dimmable = false;
|
||||
if (device.hardware) {
|
||||
dimmable = device.hardware.name == 'DIM-01';
|
||||
}
|
||||
// check if device is dimmable
|
||||
const plejdDevice = this.site.plejdDevices.find(x => x.deviceId == deviceId);
|
||||
let { name, type, dimmable } = this._getDeviceType(plejdDevice.hardwareId);
|
||||
|
||||
if (settings) {
|
||||
dimmable = settings.dimCurve != 'NonDimmable';
|
||||
|
|
@ -114,8 +112,9 @@ class PlejdApi extends EventEmitter {
|
|||
const newDevice = {
|
||||
id: deviceNum,
|
||||
name: device.title,
|
||||
type: 'light',
|
||||
supportsDim: dimmable
|
||||
type: type,
|
||||
typeName: name,
|
||||
dimmable: dimmable
|
||||
};
|
||||
|
||||
logger(JSON.stringify(newDevice));
|
||||
|
|
@ -125,6 +124,51 @@ class PlejdApi extends EventEmitter {
|
|||
|
||||
return devices;
|
||||
}
|
||||
|
||||
_getDeviceType(hardwareId) {
|
||||
switch (parseInt(hardwareId)) {
|
||||
case 1:
|
||||
case 11:
|
||||
return { name: "DIM-01", type: 'light', dimmable: true };
|
||||
case 2:
|
||||
return { name: "DIM-02", type: 'light', dimmable: true };
|
||||
case 3:
|
||||
return { name: "CTR-01", type: 'light', dimmable: false };
|
||||
case 4:
|
||||
return { name: "GWY-01", type: 'sensor', dimmable: false };
|
||||
case 5:
|
||||
return { name: "LED-10", type: 'light', dimmable: true };
|
||||
case 6:
|
||||
return { name: "WPH-01", type: 'switch', dimmable: false };
|
||||
case 7:
|
||||
return { name: "REL-01", type: 'switch', dimmable: false };
|
||||
case 8:
|
||||
case 9:
|
||||
// Unknown
|
||||
return { name: "-unknown-", type: 'light', dimmable: false };
|
||||
case 10:
|
||||
return { name: "-unknown-", type: 'light', dimmable: false };
|
||||
case 12:
|
||||
// Unknown
|
||||
return { name: "-unknown-", type: 'light', dimmable: false };
|
||||
case 13:
|
||||
return { name: "Generic", type: 'light', dimmable: false };
|
||||
case 14:
|
||||
case 15:
|
||||
case 16:
|
||||
// Unknown
|
||||
return { name: "-unknown-", type: 'light', dimmable: false };
|
||||
case 17:
|
||||
return { name: "REL-01", type: 'switch', dimmable: false };
|
||||
case 18:
|
||||
return { name: "REL-02", type: 'switch', dimmable: false };
|
||||
case 19:
|
||||
// Unknown
|
||||
return { name: "-unknown-", type: 'light', dimmable: false };
|
||||
case 20:
|
||||
return { name: "SPR-01", type: 'switch', dimmable: false };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { PlejdApi };
|
||||
12
mqtt.js
12
mqtt.js
|
|
@ -134,7 +134,17 @@ class MqttClient extends EventEmitter {
|
|||
devices.forEach((device) => {
|
||||
logger(`sending discovery for ${device.name}`);
|
||||
|
||||
const payload = device.supportsDim ? getDiscoveryDimmablePayload(device) : getDiscoveryPayload(device);
|
||||
let payload = null;
|
||||
|
||||
if (device.type === 'switch') {
|
||||
payload = getDiscoveryPayload(device);
|
||||
}
|
||||
else {
|
||||
payload = device.dimmable ? getDiscoveryDimmablePayload(device) : getDiscoveryPayload(device);
|
||||
}
|
||||
|
||||
console.log(`discovered ${device.name} with Plejd ID ${device.id}.`);
|
||||
|
||||
self.deviceMap[device.id] = payload.unique_id;
|
||||
|
||||
self.client.publish(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue