UNPKG

@trusthab/composable-resources

Version:

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

52 lines (41 loc) 1.29 kB
const composer = require('../../mixin_loader'); module.exports = (App) => { const { underscore } = require('inflected'); class ZonesNotCoolingResource { static mixins() { return ['Kpi']; } getMetricId() { return 'zones_not_cooling'; } getMetricType() { return 'gauge'; } getValue() { const { value, oldValue } = this.get('diff'); const { device_type, climate_mode, cool_target } = this.get('obj'); if (device_type !== 'thermostat') { return 0; } /* * Alert should trigger: * * IF Unit is set to climate mode=Cool * AND Set Point is BELOW Ambient Temperature (e.g. setpoint is 70, ambient temp is 75) * IF Ambient Temperature has not gone down by a degree towards the setpoint after 30m * * OR ambient temperature rises */ if (climate_mode === 'cool' || climate_mode === 'auto') { const currentValue = parseInt(value); const isSetPointBelowAmbientTemp = cool_target < currentValue; const isTempDecreasing = currentValue < oldValue; return isSetPointBelowAmbientTemp && !isTempDecreasing ? 1 : 0; } return 0; } } return composer(ZonesNotCoolingResource, App); };