Catch errors due to unknown device type to avoid addon crashing
This commit is contained in:
parent
d987a6f2cc
commit
12a8f4e475
2 changed files with 58 additions and 42 deletions
|
|
@ -428,7 +428,9 @@ class PlejdApi {
|
|||
const dimmable = device.traits === TRAITS.DIMMABLE;
|
||||
// dimmable = settings.dimCurve !== 'NonDimmable';
|
||||
|
||||
try {
|
||||
const { name: typeName, type: deviceType } = this._getDeviceType(plejdDevice);
|
||||
|
||||
let loadType = deviceType;
|
||||
if (device.outputType === 'RELAY') {
|
||||
loadType = 'switch';
|
||||
|
|
@ -456,6 +458,13 @@ class PlejdApi {
|
|||
};
|
||||
|
||||
this.deviceRegistry.addOutputDevice(outputDevice);
|
||||
|
||||
} catch (error) {
|
||||
logger.error(`Error trying to create output device: ${error}`);
|
||||
logger.warn(`device (from API response) when error happened: ${JSON.stringify(device, null, 2)}`);
|
||||
logger.warn(`plejdDevice (from API response) when error happened: ${JSON.stringify(plejdDevice, null, 2)}`);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// The device does not have an output. It can be assumed to be a WPH-01 or a WRT-01
|
||||
|
|
@ -476,6 +485,8 @@ class PlejdApi {
|
|||
);
|
||||
|
||||
const uniqueInputId = this.deviceRegistry.getUniqueInputId(device.deviceId, input.input);
|
||||
|
||||
try {
|
||||
const { name: typeName, type, broadcastClicks } = this._getDeviceType(plejdDevice);
|
||||
if (broadcastClicks) {
|
||||
/** @type {import('types/DeviceRegistry').InputDevice} */
|
||||
|
|
@ -492,6 +503,11 @@ class PlejdApi {
|
|||
};
|
||||
this.deviceRegistry.addInputDevice(inputDevice);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Error trying to create input device: ${error}`);
|
||||
logger.warn(`device (from API response) when error happened: ${JSON.stringify(device, null, 2)}`);
|
||||
logger.warn(`plejdDevice (from API response) when error happened: ${JSON.stringify(plejdDevice, null, 2)}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Plejd",
|
||||
"version": "0.9.1",
|
||||
"version": "0.10.0-alpha",
|
||||
"slug": "plejd",
|
||||
"description": "Adds support for the Swedish home automation devices from Plejd.",
|
||||
"url": "https://github.com/icanos/hassio-plejd/",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue