Files
ewelink-api/mixins/humidity/getDeviceCurrentHumidityMixin.js
Martin M 1cd87a8d90 Release v1.5.1 (#14)
* updated dependencies

* disabled temp/humidity test

* refactor big main class into smaller mixins

* updated jest config

* version bump
2019-09-14 22:12:56 -03:00

29 lines
803 B
JavaScript

const { _get } = require('../../lib/helpers');
const getDeviceCurrentHumidityMixin = {
/**
* Get device current humidity
*
* @param deviceId
*
* @returns {Promise<{humidity: *, status: string}|{msg: string, error: *}>}
*/
async getDeviceCurrentHumidity(deviceId) {
const device = await this.getDevice(deviceId);
const error = _get(device, 'error', false);
const model = _get(device, 'extra.extra.model', '');
const humidity = _get(device, 'params.currentHumidity', false);
if (error || model !== 'PSA-BHA-GL' || !humidity) {
if (error && parseInt(error) === 401) {
return device;
}
return { error, msg: 'Device does not exist' };
}
return { status: 'ok', humidity };
},
};
module.exports = getDeviceCurrentHumidityMixin;