UNPKG

@trusthab/composable-resources

Version:

migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable

56 lines (44 loc) 1.07 kB
const _ = require('lodash'); const composer = require('../../mixin_loader'); module.exports = (App) => { class ThermostatModeResource { static mixins() { return ['Kpi']; } getMetricId() { return 'thermostat_mode'; } getMetricType() { return 'gauge'; } getValue() { const { climate_mode } = this.get('obj'); const modes = { off: 0, cool: 1, heat: 2, auto: 3 }; const value = modes[climate_mode] || modes['off']; return 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(ThermostatModeResource, App); };