UNPKG

@trusthab/composable-resources

Version:

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

187 lines (176 loc) 5.11 kB
const composer = require('../mixin_loader'); module.exports = (App) => { const { underscore } = require('inflected'); class DeviceThermostatResource { static mixins() { return [ 'DeviceBase' ]; } static fields() { return { locked: { type: 'boolean', or: ['null'], path: 'additional_properties.locked.value' }, fan_speed: { type: 'text', or: ['null'], path: 'additional_properties.fan_speed.value' }, climate_mode: { type: 'text', or: ['null'], path: 'additional_properties.climate_mode.value' }, max_temp: { type: 'integer', or: ['null'], path: 'additional_properties.max_temp.value' }, min_temp: { type: 'integer', or: ['null'], path: 'additional_properties.min_temp.value' }, target_temp: { type: 'integer', or: ['null'], path: 'additional_properties.target_temp.value' }, cool_min: { type: 'integer', or: ['null'], path: 'additional_properties.cool_min.value' }, cool_max: { type: 'integer', or: ['null'], path: 'additional_properties.cool_max.value' }, cool_target: { type: 'integer', or: ['null'], path: 'additional_properties.cool_target.value' }, heat_min: { type: 'integer', or: ['null'], path: 'additional_properties.heat_min.value' }, heat_max: { type: 'integer', or: ['null'], path: 'additional_properties.heat_max.value' }, heat_target: { type: 'integer', or: ['null'], path: 'additional_properties.heat_target.value' }, auto_min: { type: 'integer', or: ['null'], path: 'additional_properties.auto_min.value' }, auto_max: { type: 'integer', or: ['null'], path: 'additional_properties.auto_max.value' }, temp_unit: { type: 'text', or: ['null'], path: 'additional_properties.temp_unit.value' }, current_temp: { type: 'integer', or: ['null'], path: 'additional_properties.current_temp.value' }, // outside_temp: { // type: 'integer', // or: ['null'], // path: 'additional_properties.outside_temp.value' // }, delta: { type: 'integer', or: ['null'], path: 'additional_properties.delta.value' }, fan_status: { type: 'text', or: ['null'], path: 'additional_properties.fan_status.value' }, humidity: { type: 'double', or: ['null'], path: 'additional_properties.humidity.value' }, synced: { type: 'boolean', or: ['null'], path: 'additional_properties.synced.value' } // KNIO transaction data // last_climate_mode_change: { // schema_ignore: true, // type: 'integer', // or: ['null'], // path: 'additional_properties.last_climate_mode_change.value' // }, // last_connected_change: { // schema_ignore: true, // type: 'integer', // or: ['null'], // path: 'additional_properties.last_connected_change.value' // }, // last_starting_temp: { // schema_ignore: true, // type: 'integer', // or: ['null'], // path: 'additional_properties.last_starting_temp.value' // }, // last_running_mode_change: { // schema_ignore: true, // type: 'integer', // or: ['null'], // path: 'additional_properties.last_running_mode_change.value' // }, // last_target_temp_change: { // schema_ignore: true, // type: 'integer', // or: ['null'], // path: 'additional_properties.last_target_temp_change.value' // }, // last_fan_state_change: { // schema_ignore: true, // type: 'integer', // or: ['null'], // path: 'additional_properties.last_fan_state_change.value' // } }; } static knetikCloudMethods() { const methods = require('./device_base')(App).knetikCloudMethods(); return { ...methods, search: { index: 'devices', template: 'hab', paramsBuilder: (params) => { const { filter } = params; const default_filters = 'device_type:thermostat'; params.filter = filter ? `${filter}|${default_filters}` : default_filters; return params; } } }; } } return composer(DeviceThermostatResource, App); };