From a59a458e58a3c8f90cb99c4767cfcd71acd8ed16 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Sat, 31 Mar 2018 20:42:28 +0000 Subject: [PATCH] [DW] Flex4Grid deleted [NF] BosMon Mqtt Plugin created --- House-Dashboard/Graphics/Heater.cs | 58 ++++++++++++++++++++++++++++++ House-Dashboard/MainWindow.xaml | 11 ++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/House-Dashboard/Graphics/Heater.cs b/House-Dashboard/Graphics/Heater.cs index 4c25be9..f45ee1e 100644 --- a/House-Dashboard/Graphics/Heater.cs +++ b/House-Dashboard/Graphics/Heater.cs @@ -12,9 +12,16 @@ using LitJson; namespace BlubbFish.House.Dashboard.Graphics { class Heater : AGraphics { private TextBlock targetTemp; + private Dictionary targetTemps = new Dictionary(); private TextBlock mode; private TextBlock now; private String topic; + private Dictionary modes = new Dictionary(); + private Int32 activemode = -1; + private Dictionary replace = new Dictionary { + { "Heat", "Heizen" }, + { "Energy Save Heat", "Nacht" } + }; public Heater(Dictionary settings, ADataBackend data) : base(settings, data) { this.targetTemp = new TextBlock { @@ -30,6 +37,9 @@ namespace BlubbFish.House.Dashboard.Graphics { this.topic = this.settings["topic"]; this.data.MessageIncomming += this.Data_MessageIncomming; this.data.Send(this.topic + "/0/49/1/get", ""); + this.data.Send(this.topic + "/0/64/get", ""); + this.data.Send(this.topic + "/0/67/1/get", ""); + this.data.Send(this.topic + "/0/67/11/get", ""); } } @@ -46,10 +56,58 @@ namespace BlubbFish.House.Dashboard.Graphics { } } } + if (e.Topic == this.topic + "/0/64") { + if (j.Keys.Contains("ValidModes") && j["ValidModes"].IsObject && this.modes.Count == 0) { + foreach (String item in j["ValidModes"].Keys) { + if (Int32.TryParse(item, out Int32 jvmode)) { + this.modes.Add(jvmode, j["ValidModes"][item].ToString()); + } + } + } + if (j.Keys.Contains("Level")) { + if (Int32.TryParse(j["Level"].ToString(), out Int32 jmode) && this.modes.ContainsKey(jmode)) { + this.activemode = jmode; + String text = this.modes[jmode]; + if (this.replace.ContainsKey(text)) { + text = this.replace[text]; + } + this.now.Dispatcher.BeginInvoke((Action)(() => { + this.mode.Text = text; + })); + this.WriteTargetTemp(); + } + } + } + if (e.Topic == this.topic + "/0/67/1" || e.Topic == this.topic + "/0/67/11") { + if (j.Keys.Contains("Level")) { + if (Double.TryParse(j["Level"].ToString(), out Double temp)) { + Int32 id = 0; + if (e.Topic.EndsWith("/1")) { + id = 1; + } else if (e.Topic.EndsWith("/11")) { + id = 11; + } + if (this.targetTemps.ContainsKey(id)) { + this.targetTemps[id] = temp; + } else { + this.targetTemps.Add(id, temp); + } + this.WriteTargetTemp(); + } + } + } } catch (Exception) { } } } + private void WriteTargetTemp() { + if (this.targetTemps.ContainsKey(this.activemode)) { + this.now.Dispatcher.BeginInvoke((Action)(() => { + this.targetTemp.Text = this.targetTemps[this.activemode] + " °C"; + })); + } + } + public override Grid Draw() { Grid outergrid = this.CreateOuterGrid(); outergrid.Children.Add(this.CreateInnerGrid()); diff --git a/House-Dashboard/MainWindow.xaml b/House-Dashboard/MainWindow.xaml index 467191d..1416997 100644 --- a/House-Dashboard/MainWindow.xaml +++ b/House-Dashboard/MainWindow.xaml @@ -5,13 +5,13 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:House_Dashboard" mc:Ignorable="d" - Title="Dashboard" WindowState="Maximized" Topmost="True" WindowStyle="None" Height="600" Width="800"> + Title="Dashboard" WindowState="Maximized" Topmost="True" WindowStyle="None" Height="600" Width="800" Name="myWindow"> - + @@ -76,5 +76,12 @@