added switch support
This commit is contained in:
parent
6d6d225b65
commit
c171b2ba3a
2 changed files with 48 additions and 5 deletions
37
plejd/api.js
37
plejd/api.js
|
|
@ -149,13 +149,42 @@ class PlejdApi extends EventEmitter {
|
||||||
serialNumber: plejdDevice.deviceId
|
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];
|
||||||
|
|
||||||
if (roomDevices[device.roomId]) {
|
newDevice.id = first;
|
||||||
roomDevices[device.roomId].push(newDevice);
|
newDevice.name += ' knapp vä';
|
||||||
|
|
||||||
|
if (roomDevices[device.roomId]) {
|
||||||
|
roomDevices[device.roomId].push(newDevice);
|
||||||
|
}
|
||||||
|
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 {
|
else {
|
||||||
roomDevices[device.roomId] = [newDevice];
|
if (roomDevices[device.roomId]) {
|
||||||
|
roomDevices[device.roomId].push(newDevice);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
roomDevices[device.roomId] = [newDevice];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
devices.push(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
|
// #endregion
|
||||||
|
|
||||||
class MqttClient extends EventEmitter {
|
class MqttClient extends EventEmitter {
|
||||||
|
|
@ -139,7 +153,7 @@ class MqttClient extends EventEmitter {
|
||||||
devices.forEach((device) => {
|
devices.forEach((device) => {
|
||||||
logger(`sending discovery for ${device.name}`);
|
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}.`);
|
console.log(`plejd-mqtt: discovered ${device.type} named ${device.name} with PID ${device.id}.`);
|
||||||
|
|
||||||
self.deviceMap[device.id] = payload.unique_id;
|
self.deviceMap[device.id] = payload.unique_id;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue