@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
49 lines (38 loc) • 972 B
JavaScript
const _ = require('lodash');
const composer = require('../../mixin_loader');
module.exports = (App) => {
const { underscore } = require('inflected');
class HumidityOutsideResource {
static mixins() {
return ['Kpi'];
}
getMetricId() {
return 'humidity_outside';
}
getMetricType() {
return 'gauge';
}
getValue() {
if (this.get('obj').device_type !== 'thermostat') { return null; }
return this.get('value');
}
customDimensions() {
return true;
}
getDimensions() {
const dimensions = _.pick(this.get('obj'), [
'id',
'location_id',
'parent_location_id',
'root_location_id'
]);
return {
device_id: dimensions.id,
unit_id: dimensions.location_id,
building_id: dimensions.parent_location_id,
property_id: dimensions.root_location_id
};
}
}
return composer(HumidityOutsideResource, App);
};