From 45a6458506012fb7af71d51b9c4521faeecebf01 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Tue, 11 Sep 2018 07:57:28 +0000 Subject: [PATCH] Add some tiny features to House-Dashboard Add ESP Graphics to Dashboard --- House-Dashboard/Functions/Tabs.cs | 3 +- House-Dashboard/Graphics/Esp.cs | 83 ++++++++++++++++------ House-Dashboard/Graphics/Heater.cs | 2 +- House-Dashboard/Graphics/HueLight.cs | 82 ++++++++++----------- House-Dashboard/House-Dashboard.csproj | 5 ++ House-Dashboard/MainWindow.xaml.cs | 13 ++-- House-Dashboard/Properties/AssemblyInfo.cs | 8 +-- House-Dashboard/credits.txt | 6 ++ 8 files changed, 127 insertions(+), 75 deletions(-) create mode 100644 House-Dashboard/credits.txt diff --git a/House-Dashboard/Functions/Tabs.cs b/House-Dashboard/Functions/Tabs.cs index 63c1542..521d737 100644 --- a/House-Dashboard/Functions/Tabs.cs +++ b/House-Dashboard/Functions/Tabs.cs @@ -71,7 +71,8 @@ namespace BlubbFish.House.Dashboard.Functions { bitmap.UriSource = new Uri(this.ini.GetValue("general", "icon"), UriKind.RelativeOrAbsolute); bitmap.EndInit(); Image image = new Image { - Source = bitmap + Source = bitmap, + Height = 30 }; header.Children.Add(image); } diff --git a/House-Dashboard/Graphics/Esp.cs b/House-Dashboard/Graphics/Esp.cs index 510ced4..af9706f 100644 --- a/House-Dashboard/Graphics/Esp.cs +++ b/House-Dashboard/Graphics/Esp.cs @@ -7,12 +7,67 @@ using System.Windows; using System.Windows.Controls; using BlubbFish.Utils.IoT.Connector; using System.Windows.Media; +using BlubbFish.Utils.IoT.Events; +using LitJson; namespace BlubbFish.House.Dashboard.Graphics { class Esp : AGraphics { + private readonly TextBlock lumi; + private readonly TextBlock pressure; + private readonly TextBlock humidity; + private readonly TextBlock temp; + private readonly String topic; + public Esp(Dictionary settings, ABackend data, UIElement window) : base(settings, data, window) { + this.lumi = new TextBlock() { + Text = "" + }; + this.pressure = new TextBlock() { + Text = "" + }; + this.humidity = new TextBlock() { + Text = "" + }; + this.temp = new TextBlock() { + Text = "" + }; + if (this.settings.ContainsKey("topic")) { + this.topic = this.settings["topic"]; + this.data.MessageIncomming += this.Data_MessageIncomming; + if (this.data is ADataBackend) { + ((ADataBackend)this.data).Send(this.topic + "/get", ""); + } + } + } + + private void Data_MessageIncomming(Object sender, BackendEvent e) { + if (e.From.ToString() == this.topic) { + try { + JsonData j = JsonMapper.ToObject(e.Message); + if (j.ContainsKey("Temperature") && j["Temperature"].IsDouble) { + this.temp.Dispatcher.BeginInvoke((Action)(() => { + this.temp.Text = ((Double)j["Temperature"]).ToString() + " °C"; + })); + } + if (j.ContainsKey("Humidity") && j["Humidity"].IsDouble) { + this.humidity.Dispatcher.BeginInvoke((Action)(() => { + this.humidity.Text = ((Double)j["Humidity"]).ToString("F2") + " %"; + })); + } + if (j.ContainsKey("Pressure") && j["Pressure"].IsDouble) { + this.pressure.Dispatcher.BeginInvoke((Action)(() => { + this.pressure.Text = ((Double)j["Pressure"]).ToString("F2") + " hPa"; + })); + } + if (j.ContainsKey("Lux") && j["Lux"].IsDouble) { + this.lumi.Dispatcher.BeginInvoke((Action)(() => { + this.lumi.Text = ((Double)j["Lux"]).ToString("F4") + " Lux"; + })); + } + } catch { } + } } public override Grid Draw() { @@ -44,11 +99,8 @@ namespace BlubbFish.House.Dashboard.Graphics Source = Helper.BitmapToImageSource(Properties.Resources.esp_luminence), Height = 30 }); - TextBlock temp = new TextBlock() { - Text = "2000" - }; - temp.SetValue(Grid.ColumnProperty, 1); - grid.Children.Add(temp); + this.lumi.SetValue(Grid.ColumnProperty, 1); + grid.Children.Add(this.lumi); return grid; } @@ -71,11 +123,8 @@ namespace BlubbFish.House.Dashboard.Graphics Source = Helper.BitmapToImageSource(Properties.Resources.esp_pressure), Height = 30 }); - TextBlock temp = new TextBlock() { - Text = "1000" - }; - temp.SetValue(Grid.ColumnProperty, 1); - grid.Children.Add(temp); + this.pressure.SetValue(Grid.ColumnProperty, 1); + grid.Children.Add(this.pressure); return grid; } @@ -98,11 +147,8 @@ namespace BlubbFish.House.Dashboard.Graphics Source = Helper.BitmapToImageSource(Properties.Resources.esp_humidity), Height = 30 }); - TextBlock temp = new TextBlock() { - Text = "30%" - }; - temp.SetValue(Grid.ColumnProperty, 1); - grid.Children.Add(temp); + this.humidity.SetValue(Grid.ColumnProperty, 1); + grid.Children.Add(this.humidity); return grid; } @@ -124,11 +170,8 @@ namespace BlubbFish.House.Dashboard.Graphics Source = Helper.BitmapToImageSource(Properties.Resources.esp_thermometer), Height = 30 }); - TextBlock temp = new TextBlock() { - Text = "20°C" - }; - temp.SetValue(Grid.ColumnProperty, 1); - grid.Children.Add(temp); + this.temp.SetValue(Grid.ColumnProperty, 1); + grid.Children.Add(this.temp); return grid; } diff --git a/House-Dashboard/Graphics/Heater.cs b/House-Dashboard/Graphics/Heater.cs index a108256..55d1264 100644 --- a/House-Dashboard/Graphics/Heater.cs +++ b/House-Dashboard/Graphics/Heater.cs @@ -117,7 +117,7 @@ namespace BlubbFish.House.Dashboard.Graphics { } } } - } catch (Exception) { } + } catch { } } } diff --git a/House-Dashboard/Graphics/HueLight.cs b/House-Dashboard/Graphics/HueLight.cs index de66e84..7ecb91e 100644 --- a/House-Dashboard/Graphics/HueLight.cs +++ b/House-Dashboard/Graphics/HueLight.cs @@ -15,13 +15,13 @@ namespace BlubbFish.House.Dashboard.Graphics { class Huelight : AGraphics { - private TextBlock status; - private TextBlock opy; - private ImageBrush img; - private String topic; + private readonly TextBlock status; + private readonly TextBlock opy; + private readonly ImageBrush img; + private readonly String topic; private Popup popup; - private Slider popup_slider; - private CheckBox popup_checkbox; + private readonly Slider popup_slider; + private readonly CheckBox popup_checkbox; public Huelight(Dictionary settings, ABackend data, UIElement window) : base(settings, data, window) { this.status = new TextBlock() { @@ -49,42 +49,44 @@ namespace BlubbFish.House.Dashboard.Graphics private void Data_MessageIncomming(Object sender, BackendEvent e) { if (e.From.ToString() == this.topic) { - JsonData json = JsonMapper.ToObject(e.Message); - if(json.ContainsKey("Brightness") && json["Brightness"].IsInt) { - Int32 bright = (Int32)json["Brightness"]; - this.opy.Dispatcher.BeginInvoke((Action)(() => { - this.opy.Text = ((bright / 254) * 100).ToString() + " %"; - })); - this.img.Dispatcher.BeginInvoke((Action)(() => { - this.img.Opacity = (bright / 254); - })); - this.popup_slider.Dispatcher.BeginInvoke((Action)(() => { - this.popup_slider.Value = bright; - })); - } - Boolean on = false; - if(json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && !(Boolean)json["Reachable"]) { - on = false; - } else if(json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && (Boolean)json["Reachable"]) { - if(json.ContainsKey("State") && json["State"].IsBoolean) { - on = (Boolean)json["State"]; + try { + JsonData json = JsonMapper.ToObject(e.Message); + if (json.ContainsKey("Brightness") && json["Brightness"].IsInt) { + Int32 bright = (Int32)json["Brightness"]; + this.opy.Dispatcher.BeginInvoke((Action)(() => { + this.opy.Text = ((Int32)(((Single)bright / 254) * 100)).ToString() + " %"; + })); + this.img.Dispatcher.BeginInvoke((Action)(() => { + this.img.Opacity = ((Single)bright / 254); + })); + this.popup_slider.Dispatcher.BeginInvoke((Action)(() => { + this.popup_slider.Value = bright; + })); } - } - if (!on) { - this.img.Dispatcher.BeginInvoke((Action)(() => { - this.img.Opacity = 0; - })); - } - this.status.Dispatcher.BeginInvoke((Action)(() => { - if (on) { - this.status.Text = "An"; - } else { - this.status.Text = "Aus"; + Boolean on = false; + if (json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && !(Boolean)json["Reachable"]) { + on = false; + } else if (json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && (Boolean)json["Reachable"]) { + if (json.ContainsKey("State") && json["State"].IsBoolean) { + on = (Boolean)json["State"]; + } } - })); - this.popup_checkbox.Dispatcher.BeginInvoke((Action)(() => { - this.popup_checkbox.IsChecked = on; - })); + if (!on) { + this.img.Dispatcher.BeginInvoke((Action)(() => { + this.img.Opacity = 0; + })); + } + this.status.Dispatcher.BeginInvoke((Action)(() => { + if (on) { + this.status.Text = "An"; + } else { + this.status.Text = "Aus"; + } + })); + this.popup_checkbox.Dispatcher.BeginInvoke((Action)(() => { + this.popup_checkbox.IsChecked = on; + })); + } catch { } } } diff --git a/House-Dashboard/House-Dashboard.csproj b/House-Dashboard/House-Dashboard.csproj index f4c6552..28e7cc2 100644 --- a/House-Dashboard/House-Dashboard.csproj +++ b/House-Dashboard/House-Dashboard.csproj @@ -140,5 +140,10 @@ + + + PreserveNewest + + \ No newline at end of file diff --git a/House-Dashboard/MainWindow.xaml.cs b/House-Dashboard/MainWindow.xaml.cs index 7b6e360..6ad2f17 100644 --- a/House-Dashboard/MainWindow.xaml.cs +++ b/House-Dashboard/MainWindow.xaml.cs @@ -28,6 +28,7 @@ namespace House_Dashboard { private Workload workload; public MainWindow() { + InIReader.SetSearchPath(new List() { "/etc/homedash", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\homedash" }); CultureInfo info = new CultureInfo("de-DE"); info.NumberFormat.NumberDecimalSeparator = "."; CultureInfo.DefaultThreadCurrentCulture = info; @@ -42,10 +43,10 @@ namespace House_Dashboard { } private void InitTabs() { - if(File.Exists("tabs.ini")) { - foreach (String item in InIReader.GetInstance("tabs.ini").GetSections()) { - if(InIReader.GetInstance("tabs.ini").GetValue(item, "settings") != null && File.Exists(InIReader.GetInstance("tabs.ini").GetValue(item, "settings"))) { - this.tabs.Items.Add(new Tabs(InIReader.GetInstance(InIReader.GetInstance("tabs.ini").GetValue(item, "settings")), this.mqtt).GetTab(this.myWindow)); + if(InIReader.ConfigExist("tabs")) { + foreach (String item in InIReader.GetInstance("tabs").GetSections()) { + if(InIReader.GetInstance("tabs").GetValue(item, "settings") != null && InIReader.ConfigExist(InIReader.GetInstance("tabs").GetValue(item, "settings"))) { + this.tabs.Items.Add(new Tabs(InIReader.GetInstance(InIReader.GetInstance("tabs").GetValue(item, "settings")), this.mqtt).GetTab(this.myWindow)); } } } else { @@ -55,8 +56,8 @@ namespace House_Dashboard { } private void InitMqtt() { - if(File.Exists("mqtt.ini")) { - this.mqtt = ABackend.GetInstance(InIReader.GetInstance("mqtt.ini").GetSection("settings"), ABackend.BackendType.Data); + if(InIReader.ConfigExist("mqtt")) { + this.mqtt = ABackend.GetInstance(InIReader.GetInstance("mqtt").GetSection("settings"), ABackend.BackendType.Data); if(this.mqtt == null) { MessageBox.Show("Der Mqtt Treiber konnte nicht geladen werden.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error); this.ApplicationShutdown(null, null); diff --git a/House-Dashboard/Properties/AssemblyInfo.cs b/House-Dashboard/Properties/AssemblyInfo.cs index b467bb0..6c8a5f4 100644 --- a/House-Dashboard/Properties/AssemblyInfo.cs +++ b/House-Dashboard/Properties/AssemblyInfo.cs @@ -53,10 +53,4 @@ using System.Windows; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: NeutralResourcesLanguage("de-DE")] - -/// Icons made by https://www.flaticon.com/authors/nice-and-serious Nice and Serious from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 -/// Icons made by https://www.flaticon.com/authors/epiccoders EpicCoders from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 -/// Icons made by https://www.flaticon.com/authors/photo3idea-studio photo3idea_studio from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 -/// Icons made by https://www.flaticon.com/authors/good-ware Good Ware from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 -/// Icons made by https://www.flaticon.com/authors/lucy-g Lucy G from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 \ No newline at end of file +[assembly: NeutralResourcesLanguage("de-DE")] \ No newline at end of file diff --git a/House-Dashboard/credits.txt b/House-Dashboard/credits.txt new file mode 100644 index 0000000..87a7266 --- /dev/null +++ b/House-Dashboard/credits.txt @@ -0,0 +1,6 @@ +Icons made by https://www.flaticon.com/authors/freepik Freepik from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 +Icons made by https://www.flaticon.com/authors/nice-and-serious Nice and Serious from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 +Icons made by https://www.flaticon.com/authors/epiccoders EpicCoders from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 +Icons made by https://www.flaticon.com/authors/photo3idea-studio photo3idea_studio from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 +Icons made by https://www.flaticon.com/authors/good-ware Good Ware from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 +Icons made by https://www.flaticon.com/authors/lucy-g Lucy G from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0 \ No newline at end of file