getDeviceCurrentTH: improved error handling

This commit is contained in:
Martín M
2020-10-21 21:18:21 -03:00
parent bf6ab11590
commit e5242589f8

View File

@@ -10,16 +10,12 @@ module.exports = {
*/
async getDeviceCurrentTH(deviceId, type = '') {
const device = await this.getDevice(deviceId);
const error = _get(device, 'error', false);
const temperature = _get(device, 'params.currentTemperature', false);
const humidity = _get(device, 'params.currentHumidity', false);
if (error) {
return device;
}
if (!temperature || !humidity) {
return { error: 404, msg: errors.noSensor };
throw new Error(`${errors.noSensor}`);
}
const data = { status: 'ok', temperature, humidity };