UNPKG

@shadman-a/homebridge-my-ac

Version:

A Homebridge plugin for controlling/monitoring LG ThinQ devices via LG ThinQ platform.

969 lines (968 loc) 97.3 kB
/** * Special thank to carlosgamezvillegas (https://github.com/carlosgamezvillegas) for the initial work on the Microwave device. */ import { BaseDevice } from '../baseDevice.js'; import { normalizeBoolean, normalizeNumber } from '../helper.js'; export default class Microwave extends BaseDevice { platform; accessory; inputNameStatus = 'Microwave Status'; inputNameMode = 'Microwave Mode'; inputNameTempString = 'Microwave Temperature'; courseStartString = 'Microwave Start Time Not Set'; courseTimeString = 'Microwave Cook Time Not Set'; courseTimerString = 'Microwave Cook Timer Not Set'; courseTimeEndString = 'Microwave End Time Not Set'; inputNameOptions = 'Microwave Options'; firstStart = true; firstDuration = 0; firstTimer = 0; courseStartMS = 0; inputID = 1; temperatureFCommand = 0; thermostatSel = 0; timerAlarmSec = 0; pauseUpdate = false; firstPause = true; ventSpeed = 0; lampLevel = 0; mwPower = 50; localTemperature = 22; localHumidity = 50; defaultTemp = 0; waitingForCommand = false; ovenCommandList = { ovenMode: 'WARM', ovenSetTemperature: 0, tempUnits: this.Status.data?.LWOTargetTemperatureUnit, ovenSetDuration: 0, subCookNumber: 0, weightUnits: 'KG', microwavePower: '100', targetWeight: 0 }; showTime = true; showTimer = true; monitorOnly = false; timeOut = 0; /** Service */ serviceHood; serviceLight; microwavePower; ovenService; ovenState; lightVent; ovenMode; ovenTemp; ovenOptions; ovenStart; ovenTimer; ovenTime; ovenEndTime; ovenTimerService; ovenAlarmService; microwaveSwitch; combiBakeSwitch; dehydrateSwitch; ovenSwitch; convectionBakeSwitch; convectionRoastSwitch; frozenMealSwitch; defrostSwitch; airFrySwitch; proofSwitch; warmModeSwitch; cancelSwitch; startOvenSwitch; ovenTempControl; offSwitch; constructor(platform, accessory, logger) { super(platform, accessory, logger); this.platform = platform; this.accessory = accessory; const { 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) => { let currentValue = 0; if (this.Status.data?.mwoVentSpeedLevel > 0) { currentValue = 1; } callback(null, currentValue); }) .on('set', (value, callback) => { this.ventSpeed = value; if (this.ventSpeed !== this.Status.data?.mwoVentSpeedLevel) { this.sendLightVentCommand(); } callback(null); }); this.serviceHood.getCharacteristic(Characteristic.RotationSpeed) .on('get', (callback) => { this.ventSpeed = this.Status.data?.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) => { const enabled = normalizeBoolean(value); if (!enabled) { this.lampLevel = 0; this.sendLightVentCommand(); } else { this.lampLevel = 2; this.sendLightVentCommand(); } callback(null); }) .on('get', (callback) => { let currentValue = false; if (this.Status.data?.mwoLampLevel > 0) { currentValue = true; } callback(null, currentValue); }); this.serviceLight.getCharacteristic(Characteristic.Brightness) .on('get', (callback) => { this.lampLevel = this.Status.data?.mwoLampLevel; callback(null, this.lampLevel); }) .on('set', (value, callback) => { this.lampLevel = value; if (this.lampLevel !== this.Status.data?.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) => { if (value) { if (this.Status.data?.mwoVentSpeedLevel !== 0 || this.Status.data?.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) => { const enabled = normalizeBoolean(value); if (!enabled) { this.mwPower = 0; } else { this.mwPower = 100; } callback(null); }) .on('get', (callback) => { let currentValue = false; if (parseInt(this.Status.data?.LWOMGTPowerLevel) * 10 > 0) { currentValue = true; } callback(null, currentValue); }); this.microwavePower.getCharacteristic(this.platform.Characteristic.Brightness) .on('get', (callback) => { const currentValue = parseInt(this.Status.data?.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) => { const enabled = normalizeBoolean(value); if (!enabled) { if (this.Status.data?.LWOState.includes('INITIAL')) { this.stopOven(); this.timeOut = 1500; setTimeout(() => { this.timeOut = 0; }, this.timeOut); } setTimeout(() => { if (this.Status.data?.mwoVentSpeedLevel !== 0 || this.Status.data?.mwoLampLevel !== 0) { this.lampLevel = 0; this.ventSpeed = 0; this.sendLightVentCommand(); } }, this.timeOut); } else { if (this.Status.data?.mwoVentSpeedLevel === 0 || this.Status.data?.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) => { const vNum = normalizeNumber(inputIdentifier); if (vNum === null) { this.platform.log.error('ActiveIdentifier is not a number'); callback(); return; } if (vNum > 9 || vNum < 1) { this.inputID = 1; } else { this.inputID = vNum; } 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) => { const enabled = normalizeBoolean(value); if (!enabled) { 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) => { const vNum = normalizeNumber(value); if (vNum === null) { this.platform.log.error('SetDuration is not a number'); callback(); return; } this.pauseUpdate = true; this.platform.log.debug('Cooking Duration set to to: ' + this.secondsToTime(vNum)); this.ovenCommandList.ovenSetDuration = vNum; 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) => { const enabled = normalizeBoolean(value); if (!enabled) { 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), // 100 minutes minStep: 60, }) .on('get', (callback) => { const currentValue = this.timerAlarmSec; callback(null, currentValue); }) .on('set', (value, callback) => { let vNum = normalizeNumber(value); if (vNum === null) { this.platform.log.error('SetDuration is not a number'); callback(); return; } if (vNum >= 6000) { vNum = 6000 - 1; } this.timerAlarmSec = vNum; 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) => { const enabled = normalizeBoolean(value); if (enabled) { 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) => { const enabled = normalizeBoolean(value); if (enabled) { 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) => { const enabled = normalizeBoolean(value); if (enabled) { 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) => { const enabled = normalizeBoolean(value); if (enabled) { 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) => { const enabled = normalizeBoolean(value); if (enabled) { 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) => { const enabled = normalizeBoolean(value); if (enabled) { 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) => { const enabled = normalizeBoolean(value); if (enabled) { this.ovenCommandList.ovenMode = 'WARM'; } 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) => { const enabled = normalizeBoolean(value); if (enabled) { 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) => { const enabled = normalizeBoolean(value); if (enabled) { 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) => { const enabled = normalizeBoolean(value); if (!enabled) { 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) => { const vNum = normalizeNumber(value); if (vNum === null) { this.platform.log.error('TargetTemperature is not a number'); callback(); return; } if (this.Status.data?.LWOTargetTemperatureUnit.includes('FAH')) { this.ovenCommandList.ovenSetTemperature = Math.round(this.tempCtoF(vNum) / 5) * 5; } else { this.ovenCommandList.ovenSetTemperature = Math.round(vNum / 5) * 5; } callback(null); }); } ////////////////// async timeModeCommand() { const ctrlKey = 'SetPreference'; const device = this.accessory.context.device; this.platform.ThinQ?.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() { this.platform.log.debug('Fan Speed: ' + this.ventSpeed + ' Light: ' + this.lampLevel); const ctrlKey = 'setVentLampLevel'; const device = this.accessory.context.device; this.platform.ThinQ?.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) { if (!this.waitingForCommand) { this.platform.log.debug('Alarm Set to: ' + this.secondsToTime(time)); const ctrlKey = 'SetTimer'; const device = this.accessory.context.device; this.platform.ThinQ?.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() { if (!this.monitorOnly) { if (!this.waitingForCommand) { this.pauseUpdate = true; this.ovenCommandList.tempUnits = this.Status.data?.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; } const isBakeOrOven = this.ovenCommandList.ovenMode.includes('COMBI_BAKE') || this.ovenCommandList.ovenMode.includes('CONV_BAKE') || this.ovenCommandList.ovenMode.includes('COMBI_ROAST') || this.ovenCommandList.ovenMode.includes('OVEN'); if (isBakeOrOven) { 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'; }