UNPKG

homebridge-miot

Version:

Homebridge plugin for devices supporting the miot protocol

206 lines (141 loc) 4.29 kB
const BaseDevice = require('../../base/BaseDevice.js'); const Constants = require('../../constants/Constants.js'); const DevTypes = require('../../constants/DevTypes.js'); const PropFormat = require('../../constants/PropFormat.js'); const PropUnit = require('../../constants/PropUnit.js'); const PropAccess = require('../../constants/PropAccess.js'); class OvenDevice extends BaseDevice { constructor(device, name, logger) { super(device, name, logger); } /*----------========== LIFECYCLE ==========----------*/ initialPropertyFetchDone() { super.initialPropertyFetchDone(); } /*----------========== DEVICE INFO ==========----------*/ getType() { return DevTypes.OVEN; } getDeviceName() { return 'Unknown oven device'; } /*----------========== CONFIG ==========----------*/ propertiesToMonitor() { return ['oven:status', 'oven:fault', 'oven:target-temperature', 'oven:left-time', 'oven:temperature', 'microwave-oven:left-time', 'microwave-oven:status', 'microwave-oven:heat-level' ]; } /*----------========== VALUES ==========----------*/ statusIdleValue() { return this.getValueForStatus('Idle'); } statusBusyValue() { return this.getValueForStatus(['Busy', 'Cooking']); } statusDelayValue() { return this.getValueForStatus('Delay'); } statusFaultValue() { return this.getValueForStatus('Fault'); } statusPausedValue() { return this.getValueForStatus('Paused'); } statusCompletedValue() { return this.getValueForStatus('Completed'); } statusSleepValue() { return this.getValueForStatus('Sleep'); } statusPreheatValue() { return this.getValueForStatus('Preheat'); } /*----------========== PROPERTIES ==========----------*/ //overrides statusProp() { return this.getProperty('oven:status'); } faultProp() { return this.getProperty('oven:fault'); } targetTemperatureProp() { return this.getProperty('oven:target-temperature'); } //device specific leftTimeProp() { return this.getProperty('oven:left-time'); } temperatureProp() { return this.getProperty('oven:temperature'); } /*----------========== ACTIONS ==========----------*/ startCookAction() { return this.getAction('oven:start-cook'); } cancelCookAction() { return this.getAction('oven:cancel-cooking'); } pauseCookAction() { return this.getAction('oven:pause'); } resumeCookAction() { return this.getAction('custom:proceed-cooking'); } /*----------========== FEATURES ==========----------*/ // left time supportsLeftTimeReporting() { return !!this.leftTimeProp(); } //cooking complete supportsCookingCompleteStatus() { return this.supportsStatusReporting() && this.statusCompletedValue() !== -1; } /*----------========== GETTERS ==========----------*/ getLeftTime() { return this.getPropertyValue(this.leftTimeProp()); } /*----------========== SETTERS ==========----------*/ /*----------========== CONVENIENCE ==========----------*/ async setCookingActive(active) { if (active) { return this.fireAction(this.startCookAction()); } else { return this.fireAction(this.cancelCookAction()); } } isHeating() { return this.isStatusBusy() || this.isStatusPreheat(); } async startHeatIfNecessary() { if (this.isHeating() === false) { return this.setCookingActive(true); } } /*----------========== VALUE CONVENIENCE ==========----------*/ isStatusIdle() { return this.getStatus() === this.statusIdleValue(); } isStatusBusy() { return this.getStatus() === this.statusBusyValue(); } isStatusDelay() { return this.getStatus() === this.statusDelayValue(); } isStatusFault() { return this.getStatus() === this.statusFaultValue(); } isStatusPaused() { return this.getStatus() === this.statusPausedValue(); } isStatusCompleted() { return this.getStatus() === this.statusCompletedValue(); } isStatusSleep() { return this.getStatus() === this.statusSleepValue(); } isStatusPreheat() { return this.getStatus() === this.statusPreheatValue(); } /*----------========== HELPERS ==========----------*/ } module.exports = OvenDevice;