@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
41 lines (30 loc) • 990 B
JavaScript
const composer = require('../../mixin_loader');
module.exports = (App) => {
const { underscore } = require('inflected');
class DevicesProfileViolationsDetectedResource {
static mixins() {
return ['Kpi'];
}
getMetricId() {
return `devices_profile_violations_detected`;
}
getMetricType() {
return 'gauge';
}
getValue() {
const { key, value } = this.get('diff');
const {
device_type,
cool_min = Number.MIN_SAFE_INTEGER,
cool_max = Number.MAX_SAFE_INTEGER,
heat_min = Number.MIN_SAFE_INTEGER,
heat_max = Number.MAX_SAFE_INTEGER
} = this.get('obj');
if (device_type !== 'thermostat') { return 0; }
if (key === 'cool_target' && (value > cool_max || value < cool_min)) { return 1; }
if (key === 'heat_target' && (value > heat_max || value < heat_min)) { return 1; }
return 0;
}
}
return composer(DevicesProfileViolationsDetectedResource, App);
};