From 84cb7e6446b34cffda124d49c951c6b920577ede Mon Sep 17 00:00:00 2001 From: Vincent Maas Date: Sun, 24 Jul 2022 15:14:44 +0200 Subject: [PATCH] add auto volume and total power on hours action --- ColorControl/ColorControl.csproj | 4 +-- ColorControl/MainForm.cs | 2 +- ColorControl/Services/LG/LgDevice.cs | 40 +++++++++++++++++++++++++--- ColorControl/lgtv/LgTvApi.cs | 31 ++++++++++++--------- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index 880b7b6..55e5363 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -18,8 +18,8 @@ Maassoft Maassoft 0 - 7.1.0.0 - 7.1.0.0 + 7.2.0.0 + 7.2.0.0 false true false diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index 27caeba..3191c22 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -3136,7 +3136,7 @@ Do you want to continue?" return; } - var actions = device.GetInvokableActions(); + var actions = device.GetInvokableActions(_lgService.Config.ShowAdvancedActions); var gameBarActions = device.GetInvokableActionsForGameBar(); var activatedGameBarActions = device.GetActionsForGameBar(); diff --git a/ColorControl/Services/LG/LgDevice.cs b/ColorControl/Services/LG/LgDevice.cs index b87ac67..54d1ee2 100644 --- a/ColorControl/Services/LG/LgDevice.cs +++ b/ColorControl/Services/LG/LgDevice.cs @@ -23,6 +23,7 @@ namespace ColorControl.Services.LG public int CurrentValue { get; set; } public int NumberOfValues { get; set; } public LgPreset Preset { get; set; } + public bool Advanced { get; set; } } public class LgDevicePictureSettings @@ -204,7 +205,11 @@ namespace ColorControl.Services.LG AddGenericPictureAction("soundMode", typeof(SoundMode), category: "sound", title: "Sound Mode"); AddGenericPictureAction("soundOutput", typeof(SoundOutput), category: "sound", title: "Sound Output"); - //await ExecuteRequest("luna://com.webos.settingsservice/setSystemSettings", new { category = "network", settings = new { wolwowlOnOff = "true" } }); + AddGenericPictureAction("autoVolume", typeof(OffToOn), category: "sound", title: "Auto Volume"); + + //AddGenericPictureAction("enableToastPopup", typeof(OffToOn), category: "option", title: "enableToastPopup"); + AddSetConfigAction("tv.conti.supportUsedTime", typeof(BoolFalseToTrue), title: "Total Power On Time"); + AddGenericPictureAction("wolwowlOnOff", typeof(FalseToTrue), category: "network", title: "Wake-On-LAN"); } @@ -260,6 +265,21 @@ namespace ColorControl.Services.LG _invokableActions.Add(action); } + private void AddSetConfigAction(string name, Type type, string title) + { + var action = new InvokableAction + { + Name = name, + Function = new Func, bool>(GenericSetConfigAction), + EnumType = type, + Title = title == null ? Utils.FirstCharUpperCase(name) : title, + Category = "Config", + Advanced = true + }; + + _invokableActions.Add(action); + } + public void AddGameBarAction(string name) { if (!ActionsOnGameBar.Contains(name)) @@ -310,6 +330,8 @@ namespace ColorControl.Services.LG await _lgTvApi.SubscribePictureSettings(PictureSettingsChanged); await _lgTvApi.SubscribeForegroundApp(ForegroundAppChanged); + //await _lgTvApi.SetConfig("tv.conti.supportUsedTime", true); + //await _lgTvApi.Reboot(); //var result = await GetPictureSettings(); @@ -773,9 +795,9 @@ namespace ColorControl.Services.LG return result; } - public List GetInvokableActions() + public List GetInvokableActions(bool includedAdvanced = false) { - return _invokableActions; + return includedAdvanced ? _invokableActions : _invokableActions.Where(a => !a.Advanced).ToList(); } public List GetInvokableActionsForGameBar() @@ -920,6 +942,18 @@ namespace ColorControl.Services.LG return true; } + private bool GenericSetConfigAction(Dictionary parameters) + { + var key = parameters["name"].ToString(); + var values = parameters["value"] as object[]; + var value = values[0]; + + var task = _lgTvApi.SetConfig(key, value); + Utils.WaitForTask(task); + + return true; + } + private void UpdateCurrentValueOfAction(string settingName, string value) { if (settingName != "backlight" && settingName != "contrast" && settingName != "brightness" && settingName != "color") diff --git a/ColorControl/lgtv/LgTvApi.cs b/ColorControl/lgtv/LgTvApi.cs index 9eaab5c..b94794a 100644 --- a/ColorControl/lgtv/LgTvApi.cs +++ b/ColorControl/lgtv/LgTvApi.cs @@ -124,6 +124,14 @@ namespace LgTv true_ } + public enum BoolFalseToTrue + { + [Description("Disabled")] + bool_false, + [Description("Enabled")] + bool_true + } + public enum GammaExp { low, @@ -417,6 +425,11 @@ namespace LgTv { await _connection.SendCommandAsync(new RequestMessage("", "ssap://system/turnOff")); } + public async Task Reboot() + { + await ExecuteRequest("luna://com.webos.service.tv.power/reboot", new { reason = "" }); + } + public async Task Play() { await _connection.SendCommandAsync(new RequestMessage("play", "ssap://media.controls/play")); @@ -662,6 +675,11 @@ namespace LgTv string jsonValue; var valueType = value.GetType(); var intType = typeof(int); + if (value.ToString().StartsWith("bool_")) + { + value = bool.Parse(value.ToString().Substring(5)); + } + if (valueType.IsArray && intType.IsAssignableFrom(valueType.GetElementType())) { var values = ((Array)value).Cast(); @@ -746,19 +764,6 @@ namespace LgTv await ExecuteRequest(lunauri, @params); } - public async Task Reboot() - { - //await ExecuteRequest("luna://com.webos.service.oledepl/setGlobalStressReduction", new { enable = true }); - - //var requestMessage = new RequestMessage("ssap://com.webos.service.devicereset/requestReboot", new { reason = "broadcastSystemChanged" }); - //var response = await _connection.SendCommandAsync(requestMessage); - - //await ExecuteRequest("luna://com.webos.settingsservice/setSystemSettings", new { category = "network", settings = new { wolwowlOnOff = "true" } }); - - //await ExecuteRequest("luna://com.webos.settingsservice/setSystemSettings", new { category = "general", settings = new { powerOffBySCA3SystemChanged = "true" } }); - //await ExecuteRequest("luna://com.webos.service.devicereset/requestReboot", new { reason = "broadcastSystemChanged" }); - } - private async Task ExecuteRequest(string lunauri, object @params) { var buttons = new[]