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