mirror of
https://github.com/skydiver/ewelink-api.git
synced 2026-01-02 11:07:28 +01:00
getDeviceCurrentTH: improved error handling
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user