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 ZonesNotHeatingResource { static mixins() { return ['Kpi']; } getMetricId() { return 'zones_not_heating'; } getMetricType() { return 'gauge'; } getValue() { const { value, oldValue } = this.get('diff'); const { device_type, climate_mode, heat_target } = this.get('obj'); if (device_type !== 'thermostat') { return 0; } /* * Alert should trigger: * * IF Unit is set to climate mode=Heat * AND Set Point is ABOVE Ambient Temperature (e.g. setpoint is 70, ambient temp is 65) * IF Ambient Temperature has not gone up by a degree towards the setpoint after 30m * * OR ambient temperature drops */ if (climate_mode === 'heat' || climate_mode === 'auto') { const currentValue = parseInt(value); const isSetPointAboveAmbientTemp = heat_target > currentValue; const isTempIncreasing = currentValue > oldValue; return isSetPointAboveAmbientTemp && !isTempIncreasing ? 1 : 0; } return 0; } } return composer(ZonesNotHeatingResource, App); };