@elshaer/homebridge-lg-thinq
Version:
A Homebridge plugin for controlling/monitoring LG ThinQ device via LG ThinQ platform.
891 lines • 100 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MicrowaveStatus = void 0;
/**
* Special thank to carlosgamezvillegas (https://github.com/carlosgamezvillegas) for the initial work on the Microwave device.
*/
const baseDevice_1 = require("../baseDevice");
class Microwave extends baseDevice_1.baseDevice {
constructor(platform, accessory) {
var _b;
super(platform, accessory);
this.platform = platform;
this.accessory = accessory;
this.inputNameStatus = 'Microwave Status';
this.inputNameMode = 'Microwave Mode';
this.inputNameTempString = 'Microwave Temperature';
this.courseStartString = 'Microwave Start Time Not Set';
this.courseTimeString = 'Microwave Cook Time Not Set';
this.courseTimerString = 'Microwave Cook Timer Not Set';
this.courseTimeEndString = 'Microwave End Time Not Set';
this.inputNameOptions = 'Microwave Options';
this.firstStart = true;
this.firstDuration = 0;
this.firstTimer = 0;
this.courseStartMS = 0;
this.inputID = 1;
this.temperatureFCommand = 0;
this.thermostatSel = 0;
this.timerAlarmSec = 0;
this.pauseUpdate = false;
this.firstPause = true;
this.ventSpeed = 0;
this.lampLevel = 0;
this.mwPower = 50;
this.localTemperature = 22;
this.localHumidity = 50;
this.defaultTemp = 0;
this.waitingForCommand = false;
this.ovenCommandList = { ovenMode: 'WARM', ovenSetTemperature: 0, tempUnits: (_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.LWOTargetTemperatureUnit, ovenSetDuration: 0, subCookNumber: 0, weightUnits: 'KG', microwavePower: '100', targetWeight: 0 };
this.showTime = true;
this.showTimer = true;
this.monitorOnly = false;
this.timeOut = 0;
const { Service: { Valve, Fan, Lightbulb, ContactSensor, OccupancySensor, IrrigationSystem }, Characteristic } = this.platform;
const device = accessory.context.device;
this.serviceHood = this.accessory.getService('Microwave Fan') ||
this.accessory.addService(this.platform.Service.Fanv2, 'Microwave Fan', 'YourUniqueIdentifier-59F');
this.serviceHood.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.serviceHood.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Fan');
this.serviceHood.getCharacteristic(Characteristic.Active)
.on('get', (callback) => {
var _b;
let currentValue = 0;
if (((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.mwoVentSpeedLevel) > 0) {
currentValue = 1;
}
callback(null, currentValue);
})
.on('set', (value, callback) => {
var _b;
this.ventSpeed = value;
if (this.ventSpeed !== ((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.mwoVentSpeedLevel)) {
this.sendLightVentCommand();
}
callback(null);
});
this.serviceHood.getCharacteristic(Characteristic.RotationSpeed)
.on('get', (callback) => {
var _b;
this.ventSpeed = (_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.mwoVentSpeedLevel;
callback(null, this.ventSpeed);
})
.on('set', (value, callback) => {
this.ventSpeed = value;
this.sendLightVentCommand();
callback(null);
});
this.serviceHood.getCharacteristic(Characteristic.RotationSpeed)
.setProps({
minValue: 0,
maxValue: 5,
minStep: 1,
});
// vent lamp
this.serviceLight = this.accessory.getService('Microwave Light') ||
this.accessory.addService(this.platform.Service.Lightbulb, 'Microwave Light', 'YourUniqueIdentifier-59L');
this.serviceLight.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.serviceLight.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Light');
this.serviceLight.getCharacteristic(Characteristic.On)
.on('set', (value, callback) => {
if (value === false) {
this.lampLevel = 0;
this.sendLightVentCommand();
}
else {
this.lampLevel = 2;
this.sendLightVentCommand();
}
callback(null);
})
.on('get', (callback) => {
var _b;
let currentValue = false;
if (((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.mwoLampLevel) > 0) {
currentValue = true;
}
callback(null, currentValue);
});
this.serviceLight.getCharacteristic(Characteristic.Brightness)
.on('get', (callback) => {
var _b;
this.lampLevel = (_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.mwoLampLevel;
callback(null, this.lampLevel);
})
.on('set', (value, callback) => {
var _b;
this.lampLevel = value;
if (this.lampLevel !== ((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.mwoLampLevel)) {
this.sendLightVentCommand();
}
callback(null);
});
this.serviceLight.getCharacteristic(Characteristic.Brightness)
.setProps({
minValue: 0,
maxValue: 2,
minStep: 1,
});
this.offSwitch = accessory.getService('Turn Off Microwave') ||
accessory.addService(this.platform.Service.Switch, 'Turn Off Microwave', 'CataNicoGaTa-Control8Off');
this.offSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.offSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Turn Off the Microwave');
this.offSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
var _b, _c;
if (value) {
if (((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.mwoVentSpeedLevel) !== 0 || ((_c = this.Status.data) === null || _c === void 0 ? void 0 : _c.mwoLampLevel) !== 0) {
this.lampLevel = 0;
this.ventSpeed = 0;
this.sendLightVentCommand();
}
setTimeout(() => {
this.offSwitch.updateCharacteristic(this.platform.Characteristic.On, false);
}, 1000);
}
callback(null);
});
this.microwavePower = this.accessory.getService('Microwave Power') ||
this.accessory.addService(this.platform.Service.Lightbulb, 'Microwave Power', 'YourUniqueIdentifier-59SP');
this.microwavePower.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.microwavePower.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Power');
this.microwavePower.getCharacteristic(this.platform.Characteristic.On)
.on('set', (value, callback) => {
if (value == false) {
this.mwPower = 0;
}
else {
this.mwPower = 100;
}
callback(null);
})
.on('get', (callback) => {
var _b;
let currentValue = false;
if (parseInt((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.LWOMGTPowerLevel) * 10 > 0) {
currentValue = true;
}
callback(null, currentValue);
});
this.microwavePower.getCharacteristic(this.platform.Characteristic.Brightness)
.on('get', (callback) => {
var _b;
const currentValue = parseInt((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.LWOMGTPowerLevel) * 10;
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.mwPower = value;
callback(null);
});
this.microwavePower.getCharacteristic(this.platform.Characteristic.Brightness)
.setProps({
minValue: 0,
maxValue: 100,
minStep: 10,
});
/////////////
this.ovenService = this.accessory.getService(this.config.name) ||
this.accessory.addService(this.platform.Service.Television, this.config.name, 'NicoCataGaTa-OvenOven7');
this.ovenService.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'LG Microwave Oven');
this.ovenService.setPrimaryService(true);
this.ovenService.setCharacteristic(this.platform
.Characteristic.SleepDiscoveryMode, this.platform.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
this.ovenService.getCharacteristic(this.platform.Characteristic.Active)
.on('get', (callback) => {
const currentValue = this.ovenServiceActive();
callback(null, currentValue);
})
.on('set', (value, callback) => {
var _b, _c, _d;
if (value === 0) {
if ((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.LWOState.includes('INITIAL')) {
this.stopOven();
this.timeOut = 1500;
setTimeout(() => {
this.timeOut = 0;
}, this.timeOut);
}
setTimeout(() => {
var _b, _c;
if (((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.mwoVentSpeedLevel) !== 0 || ((_c = this.Status.data) === null || _c === void 0 ? void 0 : _c.mwoLampLevel) !== 0) {
this.lampLevel = 0;
this.ventSpeed = 0;
this.sendLightVentCommand();
}
}, this.timeOut);
}
else {
if (((_c = this.Status.data) === null || _c === void 0 ? void 0 : _c.mwoVentSpeedLevel) === 0 || ((_d = this.Status.data) === null || _d === void 0 ? void 0 : _d.mwoLampLevel) === 0) {
this.lampLevel = 2;
this.ventSpeed = 2;
this.sendLightVentCommand();
}
}
callback(null);
});
this.ovenService
.setCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.inputID);
this.ovenService
.getCharacteristic(this.platform.Characteristic.ActiveIdentifier)
.on('set', (inputIdentifier, callback) => {
if (inputIdentifier > 9 || inputIdentifier < 1) {
this.inputID = 1;
}
else {
this.inputID = inputIdentifier;
}
callback();
})
.on('get', (callback) => {
const currentValue = this.inputID;
callback(null, currentValue);
});
this.ovenState = this.accessory.getService('Microwave Status') ||
this.accessory.addService(this.platform.Service.InputSource, 'Microwave Status', 'NicoCataGaTa-Oven1003')
.setCharacteristic(this.platform.Characteristic.Identifier, 1)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenStatus())
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.platform.Characteristic.CurrentVisibilityState.SHOWN);
this.ovenState.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.ovenStatus();
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.ovenState);
this.lightVent = this.accessory.getService('Light and Vent Status') ||
this.accessory.addService(this.platform.Service.InputSource, 'Light and Vent Status', 'NicoCata-Always15')
.setCharacteristic(this.platform.Characteristic.Identifier, 2)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.lightVentStatus())
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.lightVentState() ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.lightVentState() ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.lightVent.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.lightVentStatus();
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.lightVent);
this.ovenMode = this.accessory.getService('Microwave Cooking Mode') ||
this.accessory.addService(this.platform.Service.InputSource, 'Microwave Cooking Mode', 'NicoCataGaTa-Oven1004')
.setCharacteristic(this.platform.Characteristic.Identifier, 3)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenModeName())
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.onStatus() ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.onStatus() ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.ovenMode.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.ovenModeName();
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.ovenMode);
this.ovenTemp = this.accessory.getService('Microwave Oven Temperature') ||
this.accessory.addService(this.platform.Service.InputSource, 'Microwave Oven Temperature', 'NicoCataGaTa-Oven1004T')
.setCharacteristic(this.platform.Characteristic.Identifier, 4)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenTemperature())
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.onStatus() ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.onStatus() ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.ovenTemp.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.ovenTemperature();
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.ovenTemp);
this.ovenOptions = this.accessory.getService('Microwave Options') ||
this.accessory.addService(this.platform.Service.InputSource, 'Microwave Options', 'NicoCata-Always4')
.setCharacteristic(this.platform.Characteristic.Identifier, 5)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.oventOptions())
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.onStatus() ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.onStatus() ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.ovenOptions.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.oventOptions();
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.ovenOptions);
this.ovenStart = this.accessory.getService('Microwave Start Time') ||
this.accessory.addService(this.platform.Service.InputSource, 'Microwave Start Time', 'NicoCata-Always1')
.setCharacteristic(this.platform.Characteristic.Identifier, 6)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.courseStartString)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showTime ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showTime ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.ovenStart.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.courseStartString;
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.ovenStart);
this.ovenTimer = this.accessory.getService('Microwave Timer Status') ||
this.accessory.addService(this.platform.Service.InputSource, 'Microwave Timer Status', 'NicoCata-Always2')
.setCharacteristic(this.platform.Characteristic.Identifier, 7)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.courseTimerString)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showTimer ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showTimer ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.ovenTimer.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.courseTimerString;
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.ovenTimer);
this.ovenTime = this.accessory.getService('Microwave Cook Time Status') ||
this.accessory.addService(this.platform.Service.InputSource, 'Microwave Cook Time Status', 'NicoCata-Always2T')
.setCharacteristic(this.platform.Characteristic.Identifier, 8)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.courseTimeString)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showTime ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showTime ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.ovenTime.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.courseTimeString;
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.ovenTime);
this.ovenEndTime = this.accessory.getService('Microwave End Time') ||
this.accessory.addService(this.platform.Service.InputSource, 'Microwave End Time', 'NicoCata-Always3')
.setCharacteristic(this.platform.Characteristic.Identifier, 9)
.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.courseTimeEndString)
.setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
.setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
.setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showTime ? this.platform.Characteristic.TargetVisibilityState.SHOWN : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
.setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showTime ? this.platform.Characteristic.CurrentVisibilityState.SHOWN : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
this.ovenEndTime.getCharacteristic(this.platform.Characteristic.ConfiguredName)
.on('get', (callback) => {
const currentValue = this.courseTimeEndString;
callback(null, currentValue);
});
this.ovenService.addLinkedService(this.ovenEndTime);
//////////Timers
this.ovenTimerService = this.accessory.getService('Microwave Cook Time') ||
this.accessory.addService(this.platform.Service.Valve, 'Microwave Cook Time', 'NicoCataGaTa-OvenT2');
this.ovenTimerService.setCharacteristic(Characteristic.Name, 'Microwave Cook Time');
this.ovenTimerService.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.ovenTimerService.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Cook Time');
this.ovenTimerService.setCharacteristic(Characteristic.ValveType, Characteristic.ValveType.IRRIGATION);
this.ovenTimerService.getCharacteristic(Characteristic.Active)
.on('get', (callback) => {
let currentValue = 0;
if (this.remainTime() != 0) {
currentValue = 1;
}
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value == 0) {
this.stopOven();
this.ovenTimerService.updateCharacteristic(Characteristic.Active, 0);
this.ovenTimerService.updateCharacteristic(Characteristic.RemainingDuration, 0);
this.ovenTimerService.updateCharacteristic(Characteristic.InUse, 0);
}
else {
this.sendOvenCommand();
}
callback(null);
});
this.ovenTimerService.setCharacteristic(Characteristic.InUse, this.remainTime() > 0 ? Characteristic.InUse.IN_USE : Characteristic.InUse.NOT_IN_USE);
this.ovenTimerService.getCharacteristic(Characteristic.RemainingDuration)
.setProps({
maxValue: 32400, // 9hours
})
.on('get', (callback) => {
const currentValue = this.remainTime();
callback(null, currentValue);
});
this.ovenTimerService.getCharacteristic(this.platform.Characteristic.SetDuration)
.setProps({
maxValue: 32400, // 9hours
})
.on('get', (callback) => {
const currentValue = this.oventTargetTime();
callback(null, currentValue);
})
.on('set', (value, callback) => {
this.pauseUpdate = true;
this.platform.log.debug('Cooking Duration set to to: ' + this.secondsToTime(value));
this.ovenCommandList.ovenSetDuration = value;
callback(null);
});
this.ovenAlarmService = this.accessory.getService('Microwave Timer') ||
this.accessory.addService(this.platform.Service.Valve, 'Microwave Timer', 'NicoCataGaTa-OvenT32');
this.ovenAlarmService.setCharacteristic(Characteristic.Name, 'Microwave Timer');
this.ovenAlarmService.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.ovenAlarmService.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Timer');
this.ovenAlarmService.setCharacteristic(Characteristic.ValveType, Characteristic.ValveType.IRRIGATION);
this.ovenAlarmService.getCharacteristic(Characteristic.Active)
.on('get', (callback) => {
let currentValue = 0;
if (this.ovenTimerTime() != 0) {
currentValue = 1;
}
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value == 0) {
this.timerAlarmSec = 0;
this.sendTimerCommand(0);
this.ovenAlarmService.updateCharacteristic(Characteristic.Active, 0);
this.ovenAlarmService.updateCharacteristic(Characteristic.RemainingDuration, 0);
this.ovenAlarmService.updateCharacteristic(Characteristic.InUse, 0);
}
else {
this.sendTimerCommand(this.timerAlarmSec);
this.ovenAlarmService.updateCharacteristic(Characteristic.Active, 1);
this.ovenAlarmService.updateCharacteristic(Characteristic.RemainingDuration, this.timerAlarmSec);
this.ovenAlarmService.updateCharacteristic(Characteristic.InUse, 1);
}
callback(null);
});
this.ovenAlarmService.setCharacteristic(Characteristic.InUse, this.ovenTimerTime() > 0 ? Characteristic.InUse.IN_USE : Characteristic.InUse.NOT_IN_USE);
this.ovenAlarmService.getCharacteristic(Characteristic.RemainingDuration)
.setProps({
maxValue: (6000 - 1), // 100 minutes
})
.on('get', (callback) => {
const currentValue = this.ovenTimerTime();
callback(null, currentValue);
});
this.ovenAlarmService.getCharacteristic(this.platform.Characteristic.SetDuration)
.setProps({
maxValue: (6000 - 1),
minStep: 60,
})
.on('get', (callback) => {
const currentValue = this.timerAlarmSec;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value >= (6000)) {
value = 6000 - 1;
}
this.timerAlarmSec = value;
callback(null);
});
///////////Switches
this.microwaveSwitch = accessory.getService('Microwave Mode') ||
accessory.addService(this.platform.Service.Switch, 'Microwave Mode', 'CataNicoGaTa-80M');
this.microwaveSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.microwaveSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Mode');
this.microwaveSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value) {
this.ovenCommandList.ovenMode = 'MICROWAVE';
}
this.updateOvenModeSwitch();
callback(null);
});
this.combiBakeSwitch = accessory.getService('Combination Bake Mode') ||
accessory.addService(this.platform.Service.Switch, 'Combination Bake Mode', 'CataNicoGaTa-80B');
this.combiBakeSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.combiBakeSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Combination Bake Mode');
this.combiBakeSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value) {
this.ovenCommandList.ovenMode = 'COMBI_BAKE';
}
this.updateOvenModeSwitch();
callback(null);
});
this.dehydrateSwitch = accessory.getService('Dehydrate Mode') ||
accessory.addService(this.platform.Service.Switch, 'Dehydrate Mode', 'CataNicoGaTa-80d');
this.dehydrateSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.dehydrateSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Dehydrate Mode');
this.dehydrateSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value) {
this.ovenCommandList.ovenMode = 'DEHYDRATE';
}
this.updateOvenModeSwitch();
callback(null);
});
this.ovenSwitch = accessory.getService('Oven Mode') ||
accessory.addService(this.platform.Service.Switch, 'Oven Mode', 'CataNicoGaTa-80OVen');
this.ovenSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.ovenSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Oven Mode');
this.ovenSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value) {
this.ovenCommandList.ovenMode = 'OVEN';
}
this.updateOvenModeSwitch();
callback(null);
});
this.convectionBakeSwitch = accessory.getService('Convection Bake Mode') ||
accessory.addService(this.platform.Service.Switch, 'Convection Bake Mode', 'CataNicoGaTa-Control1');
this.convectionBakeSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.convectionBakeSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Convection Bake Mode');
this.convectionBakeSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.ovenCommandList.ovenMode == 'CONV_BAKE';
}
this.updateOvenModeSwitch();
callback(null);
});
this.convectionRoastSwitch = accessory.getService('Combination Roast Mode') ||
accessory.addService(this.platform.Service.Switch, 'Combination Roast Mode', 'CataNicoGaTa-Control2');
this.convectionRoastSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.convectionRoastSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Combination Roast Mode');
this.convectionRoastSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.ovenCommandList.ovenMode == 'COMBI_ROAST';
}
this.updateOvenModeSwitch();
callback(null);
});
this.frozenMealSwitch = accessory.getService('Time Defrost Mode') ||
accessory.addService(this.platform.Service.Switch, 'Time Defrost Mode', 'CataNicoGaTa-Control3');
this.frozenMealSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.frozenMealSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Time Defrost Mode');
this.frozenMealSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.ovenCommandList.ovenMode == 'TIME_DEFROST';
}
this.updateOvenModeSwitch();
callback(null);
});
this.defrostSwitch = accessory.getService('Defrost Mode') ||
accessory.addService(this.platform.Service.Switch, 'Defrost Mode', 'CataNicoGaTa-Control3D');
this.defrostSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.defrostSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Defrost Mode');
this.defrostSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.ovenCommandList.ovenMode == 'INVERTER_DEFROST';
}
this.updateOvenModeSwitch();
callback(null);
});
this.airFrySwitch = accessory.getService('Air Fry Mode') ||
accessory.addService(this.platform.Service.Switch, 'Air Fry Mode', 'CataNicoGaTa-Control4');
this.airFrySwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.airFrySwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Air Fry Mode');
this.airFrySwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.ovenCommandList.ovenMode == 'AIRFRY';
}
this.updateOvenModeSwitch();
callback(null);
});
this.proofSwitch = accessory.getService('Proof Mode') ||
accessory.addService(this.platform.Service.Switch, 'Proof Mode', 'CataNicoGaTa-Control5');
this.proofSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.proofSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Proof Mode');
this.proofSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.ovenCommandList.ovenMode == 'PROOF';
}
this.updateOvenModeSwitch();
callback(null);
});
this.warmModeSwitch = accessory.getService('Warm Mode (High)') ||
accessory.addService(this.platform.Service.Switch, 'Warm Mode (High)', 'CataNicoGaTa-Control5W');
this.warmModeSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.warmModeSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Warm Mode (High)');
this.warmModeSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.ovenCommandList.ovenMode == 'WARM';
// this.timeModeCommand();
}
this.updateOvenModeSwitch();
callback(null);
});
this.cancelSwitch = accessory.getService('Stop Microwave') ||
accessory.addService(this.platform.Service.Switch, 'Stop Microwave', 'CataNicoGaTa-Control6');
this.cancelSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.cancelSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Stop Microwave');
this.cancelSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.stopOven();
}
setTimeout(() => {
this.cancelSwitch.updateCharacteristic(this.platform.Characteristic.On, false);
}, 1000);
this.updateOvenModeSwitch();
callback(null);
});
this.startOvenSwitch = accessory.getService('Start Microwave') ||
accessory.addService(this.platform.Service.Switch, 'Start Microwave', 'CataNicoGaTa-Control8');
this.startOvenSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.startOvenSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Start Microwave');
this.startOvenSwitch.getCharacteristic(this.platform.Characteristic.On)
.on('get', (callback) => {
const currentValue = false;
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value === true) {
this.sendOvenCommand();
setTimeout(() => {
this.startOvenSwitch.updateCharacteristic(this.platform.Characteristic.On, false);
}, 1000);
}
callback(null);
});
/////////Temperature Control
this.ovenTempControl = this.accessory.getService('Microwave Oven Temperature Control') ||
this.accessory.addService(this.platform.Service.Thermostat, 'Microwave Oven Temperature Control', 'NicoCataGaTa-OvenTC')
.setCharacteristic(this.platform.Characteristic.Name, 'Microwave Oven Temperature Control')
.setCharacteristic(this.platform.Characteristic.CurrentHeatingCoolingState, this.currentHeatingState())
.setCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits, 1);
this.ovenTempControl.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
this.ovenTempControl.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Oven Temperature Control');
this.ovenTempControl.getCharacteristic(this.platform.Characteristic.TargetHeatingCoolingState)
.setProps({ validValues: [this.platform.Characteristic.TargetHeatingCoolingState.OFF, this.platform.Characteristic.TargetHeatingCoolingState.HEAT] })
.on('get', (callback) => {
const currentValue = this.targetHeatingState();
callback(null, currentValue);
})
.on('set', (value, callback) => {
if (value == 0) {
this.stopOven();
}
else {
this.pauseUpdate = true;
}
callback(null);
});
this.ovenTempControl.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
.setProps({
minValue: 10,
maxValue: 233,
minStep: 0.5,
})
.on('get', (callback) => {
const currentValue = this.ovenCurrentTemperature();
callback(null, currentValue);
});
this.ovenTempControl.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
.on('get', (callback) => {
const currentValue = this.localHumidity;
callback(null, currentValue);
});
this.ovenTempControl.getCharacteristic(this.platform.Characteristic.TargetTemperature)
.setProps({
minValue: 38,
maxValue: 233,
minStep: 0.5,
})
.on('get', (callback) => {
const currentValue = this.ovenTargetTemperature();
callback(null, currentValue);
})
.on('set', (value, callback) => {
var _b;
if ((_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.LWOTargetTemperatureUnit.includes('FAH')) {
this.ovenCommandList.ovenSetTemperature = Math.round(this.tempCtoF(value) / 5) * 5;
}
else {
this.ovenCommandList.ovenSetTemperature = Math.round(value / 5) * 5;
}
callback(null);
});
}
//////////////////
async timeModeCommand() {
var _b;
const ctrlKey = 'SetPreference';
const device = this.accessory.context.device;
(_b = this.platform.ThinQ) === null || _b === void 0 ? void 0 : _b.deviceControl(device, {
dataKey: null,
dataValue: null,
dataSetList: {
ovenState: {
'cmdOptionContentsType': 'REMOTE_SETTING',
'cmdOptionDataLength': 'REMOTE_SETTING',
'mwoSettingClockSetTimeHour': 128,
'mwoSettingClockSetTimeMin': 128,
'mwoSettingClockSetHourMode': '24H_MODE',
'mwoSettingSound': 'NOT_SET',
'mwoSettingClockDisplay': 'NOT_SET',
'mwoSettingDisplayScrollSpeed': 'SLOW',
'mwoSettingDefrostWeightMode': 'NOT_SET',
'mwoSettingDemoMode': 'NOT_SET',
},
},
dataGetList: null,
}, 'Set', ctrlKey);
}
async sendLightVentCommand() {
var _b;
this.platform.log.debug('Fan Speed: ' + this.ventSpeed + ' Light: ' + this.lampLevel);
let _a;
const ctrlKey = 'setVentLampLevel';
const device = this.accessory.context.device;
(_b = this.platform.ThinQ) === null || _b === void 0 ? void 0 : _b.deviceControl(device, {
dataKey: null,
dataValue: null,
dataSetList: {
ovenState: {
'cmdOptionContentsType': 'REMOTE_VENT_LAMP',
'cmdOptionDataLength': 'REMOTE_VENT_LAMP',
'mwoVentOnOff': this.ventSpeed > 0 ? 'ENABLE' : 'DISABLE',
'mwoVentSpeedLevel': this.ventSpeed,
'mwoLampOnOff': this.lampLevel > 0 ? 'ENABLE' : 'DISABLE',
'mwoLampLevel': this.lampLevel,
},
},
dataGetList: null,
}, 'Set', ctrlKey);
}
async sendTimerCommand(time) {
var _b;
if (!this.waitingForCommand) {
this.platform.log.debug('Alarm Set to: ' + this.secondsToTime(time));
const ctrlKey = 'SetTimer';
const device = this.accessory.context.device;
(_b = this.platform.ThinQ) === null || _b === void 0 ? void 0 : _b.deviceControl(device, {
dataKey: null,
dataValue: null,
dataSetList: {
ovenState: {
'cmdOptionContentsType': 'TIMER',
'cmdOptionDataLength': 'TIMER',
'lowerTimerHour': 128,
'lowerTimerMinute': 128,
'lowerTimerSecond': 128,
'upperTimerHour': 0,
'upperTimerMinute': Math.floor(time / 60),
'upperTimerSecond': Math.floor(time % 60),
},
},
dataGetList: null,
}, 'Set', ctrlKey);
this.waitingForCommand = true;
setTimeout(() => {
this.pauseUpdate = false;
this.firstPause = true;
}, 10000);
}
setTimeout(() => {
this.waitingForCommand = false;
}, 1000);
}
sendOvenCommand() {
var _b, _c, _d, _e;
if (!this.monitorOnly) {
if (!this.waitingForCommand) {
this.pauseUpdate = true;
this.ovenCommandList.tempUnits = (_b = this.Status.data) === null || _b === void 0 ? void 0 : _b.LWOTargetTemperatureUnit;
this.ovenCommandList.microwavePower = this.mwPower.toString();
if (this.ovenCommandList.ovenMode === 'NONE') {
this.ovenCommandList.ovenMode = 'WARM';
}
if (this.ovenCommandList.ovenSetDuration == 0) {
this.ovenCommandList.ovenSetDuration = 300;
}
if (this.ovenCommandList.ovenMode.includes('COMBI_BAKE') || this.ovenCommandList.ovenMode.includes('CONV_BAKE') || this.ovenCommandList.ovenMode.includes('COMBI_ROAST') || this.ovenCommandList.ovenMode.includes('OVEN')) {
if (this.ovenCommandList.tempUnits.includes('FAH')) {
if (this.ovenCommandList.ovenSetTemperature < 250) {
this.ovenCommandList.ovenSetTemperature = 250;
}
if (this.ovenCommandList.ovenSetTemperature > 450) {
this.ovenCommandList.ovenSetTemperature = 450;
}
}
else {
if (this.ovenCommandList.ovenSetTemperature < 125) {
this.ovenCommandList.ovenSetTemperature = 125;
}
if (this.ovenCommandList.ovenSetTemperature > 230) {
this.ovenCommandList.ovenSetTemperature = 230;
}
}
if (this.ovenCommandList.ovenMode.includes('COMBI_BAKE')) {
this.ovenCommandList.subCookNumber = 82;
this.ovenCommandList.microwavePower = '10';
this.ovenCommandList.targetWeight = 0;
this.ovenCommandList.weightUnits = 'KG';
}
if (this.ovenCommandList.ovenMode.includes('COMBI_ROAST')) {
this.ovenCommandList.subCookNumber = 82;
this.ovenCommandList.microwavePower = '30';
this.ovenCommandList.targetWeight = 0;
this.ovenCommandList.weightUnits = 'LBS';
}
if (this.ovenCommandList.ovenMode.includes('CONV_BAKE') || this.ovenCommandList.ovenMode.includes('OVEN')) {
this.ovenCommandList.subCookNumber = 0;
this.ovenCommandList.microwavePower = '100';
this.ovenCommandList.targetWeight = 0;
this.ovenCommandList.weightUnits = 'LBS';
}
}
else if (this.ovenCommandList.ovenMode.includes('DEHYDRATE')) {
if (this.ovenCommandList.tempUnits.includes('FAH')) {
if (this.ovenCommandList.ovenSetTemperature < 100) {
this.ovenCommandList.ovenSetTemperature = 100;
}
if (this.ovenCommandList.ovenSetTemperature > 200) {
this.ovenCommandList.ovenSetTemperature = 200;
}
}
else {
if (this.ovenCommandList.ovenSetTemperature < 38) {
th