added switch support
This commit is contained in:
parent
6d6d225b65
commit
c171b2ba3a
2 changed files with 48 additions and 5 deletions
31
plejd/api.js
31
plejd/api.js
|
|
@ -149,7 +149,15 @@ class PlejdApi extends EventEmitter {
|
|||
serialNumber: plejdDevice.deviceId
|
||||
};
|
||||
|
||||
logger(JSON.stringify(newDevice));
|
||||
if (newDevice.typeName === 'WPH-01') {
|
||||
// WPH-01 is special, it has two buttons which needs to be
|
||||
// registered separately.
|
||||
const inputs = this.site.inputAddress[deviceId];
|
||||
const first = inputs[0];
|
||||
const second = inputs[1];
|
||||
|
||||
newDevice.id = first;
|
||||
newDevice.name += ' knapp vä';
|
||||
|
||||
if (roomDevices[device.roomId]) {
|
||||
roomDevices[device.roomId].push(newDevice);
|
||||
|
|
@ -157,6 +165,27 @@ class PlejdApi extends EventEmitter {
|
|||
else {
|
||||
roomDevices[device.roomId] = [newDevice];
|
||||
}
|
||||
devices.push(newDevice);
|
||||
|
||||
newDevice.id = second;
|
||||
newDevice.name = device.title + ' knapp hö';
|
||||
|
||||
if (roomDevices[device.roomId]) {
|
||||
roomDevices[device.roomId].push(newDevice);
|
||||
}
|
||||
else {
|
||||
roomDevices[device.roomId] = [newDevice];
|
||||
}
|
||||
devices.push(newDevice);
|
||||
}
|
||||
else {
|
||||
if (roomDevices[device.roomId]) {
|
||||
roomDevices[device.roomId].push(newDevice);
|
||||
}
|
||||
else {
|
||||
roomDevices[device.roomId] = [newDevice];
|
||||
}
|
||||
}
|
||||
|
||||
devices.push(newDevice);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,20 @@ const getDiscoveryPayload = device => ({
|
|||
}
|
||||
});
|
||||
|
||||
const getSwitchPayload = device => ({
|
||||
name: device.name,
|
||||
state_topic: getStateTopic(device),
|
||||
command_topic: getCommandTopic(device),
|
||||
optimistic: false,
|
||||
device: {
|
||||
identifiers: device.serialNumber + '_' + device.id,
|
||||
manufacturer: 'Plejd',
|
||||
model: device.typeName,
|
||||
name: device.name,
|
||||
sw_version: device.version
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
class MqttClient extends EventEmitter {
|
||||
|
|
@ -139,7 +153,7 @@ class MqttClient extends EventEmitter {
|
|||
devices.forEach((device) => {
|
||||
logger(`sending discovery for ${device.name}`);
|
||||
|
||||
let payload = getDiscoveryPayload(device);
|
||||
let payload = device.type === 'switch' ? getSwitchPayload(device) : getDiscoveryPayload(device);
|
||||
console.log(`plejd-mqtt: discovered ${device.type} named ${device.name} with PID ${device.id}.`);
|
||||
|
||||
self.deviceMap[device.id] = payload.unique_id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue