From 8dd3ee46b92af51c18b9726ff1f5ee4bb3b1318d Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Mon, 7 Sep 2020 12:34:08 +0200 Subject: [PATCH] GUI and protocol separeted from libraries and implemented in the application --- garage_protocol | 2 +- gui.py | 158 +++++++++++++++++++++++ smarthome.wxg => gui.wxg | 62 +++++++-- smarthome.py | 267 +++++++++++++-------------------------- wetation_protocol | 2 +- 5 files changed, 301 insertions(+), 190 deletions(-) create mode 100755 gui.py rename smarthome.wxg => gui.wxg (88%) diff --git a/garage_protocol b/garage_protocol index 88c3b56..ae391a4 160000 --- a/garage_protocol +++ b/garage_protocol @@ -1 +1 @@ -Subproject commit 88c3b5676f0f670e1b68bb327d844e9d67dddda6 +Subproject commit ae391a4698abc0834519cfade3c96b06a59a22d9 diff --git a/gui.py b/gui.py new file mode 100755 index 0000000..97d2d0b --- /dev/null +++ b/gui.py @@ -0,0 +1,158 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +# +# generated by wxGlade 0.9.3 on Mon Sep 7 11:55:26 2020 +# + +import wx + +# begin wxGlade: dependencies +# end wxGlade + +# begin wxGlade: extracode +# end wxGlade + + +class Wetation(wx.Frame): + def __init__(self, *args, **kwds): + # begin wxGlade: Wetation.__init__ + kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE + wx.Frame.__init__(self, *args, **kwds) + self.SetSize((800, 628)) + self.date = wx.StaticText(self, wx.ID_ANY, "xx.xx.xxxx", style=wx.ALIGN_LEFT) + self.time = wx.StaticText(self, wx.ID_ANY, "xx:xx", style=wx.ALIGN_RIGHT) + self.heading_out_envdata = wx.StaticText(self, wx.ID_ANY, u"Außentemperatur") + self.out_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT) + self.out_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT) + self.out_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) + self.out_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) + self.out_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) + self.heading_in_envdata = wx.StaticText(self, wx.ID_ANY, "Innentemperatur") + self.in_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT) + self.in_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT) + self.in_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) + self.in_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) + self.in_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) + self.heading_garage = wx.StaticText(self, wx.ID_ANY, "Garage") + self.gate_oc = wx.Button(self, wx.ID_ANY, "Garage") + self.gate_close = wx.StaticText(self, wx.ID_ANY, "Close") + self.gate_position = wx.Slider(self, wx.ID_ANY, 50, 0, 100) + self.gate_open = wx.StaticText(self, wx.ID_ANY, "Open") + + self.__set_properties() + self.__do_layout() + + self.Bind(wx.EVT_BUTTON, self.gate_oc_evt, self.gate_oc) + # end wxGlade + + def __set_properties(self): + # begin wxGlade: Wetation.__set_properties + self.SetTitle("frame") + self.SetBackgroundColour(wx.Colour(250, 249, 255)) + self.SetForegroundColour(wx.Colour(35, 35, 142)) + self.date.SetBackgroundColour(wx.Colour(35, 35, 142)) + self.date.SetForegroundColour(wx.Colour(255, 255, 255)) + self.date.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.time.SetBackgroundColour(wx.Colour(35, 35, 142)) + self.time.SetForegroundColour(wx.Colour(255, 255, 255)) + self.time.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.heading_out_envdata.SetBackgroundColour(wx.Colour(35, 35, 142)) + self.heading_out_envdata.SetForegroundColour(wx.Colour(250, 249, 255)) + self.heading_out_envdata.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.out_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.out_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.out_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.out_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.out_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.heading_in_envdata.SetBackgroundColour(wx.Colour(35, 35, 142)) + self.heading_in_envdata.SetForegroundColour(wx.Colour(250, 249, 255)) + self.heading_in_envdata.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.in_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.in_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.in_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.in_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.in_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.heading_garage.SetBackgroundColour(wx.Colour(35, 35, 142)) + self.heading_garage.SetForegroundColour(wx.Colour(250, 249, 255)) + self.heading_garage.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + self.heading_garage.Hide() + self.gate_oc.Hide() + self.gate_close.Hide() + self.gate_position.Enable(False) + self.gate_position.Hide() + self.gate_open.Hide() + # end wxGlade + + def __do_layout(self): + # begin wxGlade: Wetation.__do_layout + sizer_main = wx.BoxSizer(wx.VERTICAL) + sizer_8 = wx.BoxSizer(wx.HORIZONTAL) + sizer_env_data_in = wx.BoxSizer(wx.HORIZONTAL) + sizer_9 = wx.BoxSizer(wx.VERTICAL) + sizer_5 = wx.BoxSizer(wx.VERTICAL) + sizer_env_data_out = wx.BoxSizer(wx.HORIZONTAL) + sizer_7 = wx.BoxSizer(wx.VERTICAL) + sizer_4 = wx.BoxSizer(wx.VERTICAL) + sizer_date_time = wx.BoxSizer(wx.HORIZONTAL) + spacer_1 = wx.StaticText(self, wx.ID_ANY, "") + spacer_1.SetBackgroundColour(wx.Colour(35, 35, 142)) + spacer_1.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + sizer_main.Add(spacer_1, 0, wx.EXPAND, 0) + sizer_date_time.Add(self.date, 1, wx.EXPAND | wx.LEFT, 0) + sizer_date_time.Add(self.time, 1, wx.EXPAND | wx.RIGHT, 0) + sizer_main.Add(sizer_date_time, 0, wx.EXPAND, 0) + spacer_2 = wx.StaticText(self, wx.ID_ANY, "") + spacer_2.SetBackgroundColour(wx.Colour(35, 35, 142)) + spacer_2.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) + sizer_main.Add(spacer_2, 0, wx.EXPAND, 0) + sizer_main.Add((20, 20), 0, 0, 0) + sizer_main.Add(self.heading_out_envdata, 0, wx.EXPAND, 0) + sizer_4.Add(self.out_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) + sizer_4.Add(self.out_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) + sizer_env_data_out.Add(sizer_4, 1, wx.EXPAND, 0) + sizer_7.Add(self.out_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) + sizer_7.Add(self.out_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) + sizer_env_data_out.Add(sizer_7, 1, wx.EXPAND, 0) + sizer_env_data_out.Add((50, 20), 0, 0, 0) + sizer_env_data_out.Add(self.out_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0) + sizer_main.Add(sizer_env_data_out, 0, wx.EXPAND, 0) + sizer_main.Add((20, 20), 0, 0, 0) + sizer_main.Add(self.heading_in_envdata, 0, wx.EXPAND, 0) + sizer_5.Add(self.in_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) + sizer_5.Add(self.in_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) + sizer_env_data_in.Add(sizer_5, 1, wx.EXPAND, 0) + sizer_9.Add(self.in_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) + sizer_9.Add(self.in_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) + sizer_env_data_in.Add(sizer_9, 1, wx.EXPAND, 0) + sizer_env_data_in.Add((50, 20), 0, 0, 0) + sizer_env_data_in.Add(self.in_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0) + sizer_main.Add(sizer_env_data_in, 0, wx.EXPAND, 0) + sizer_main.Add((10, 10), 1, 0, 0) + sizer_main.Add(self.heading_garage, 0, wx.EXPAND, 0) + sizer_8.Add(self.gate_oc, 0, 0, 0) + sizer_8.Add(self.gate_close, 0, wx.ALIGN_CENTER, 0) + sizer_8.Add(self.gate_position, 1, wx.EXPAND, 0) + sizer_8.Add(self.gate_open, 0, wx.ALIGN_CENTER, 0) + sizer_main.Add(sizer_8, 0, wx.EXPAND, 0) + self.SetSizer(sizer_main) + self.Layout() + # end wxGlade + + def gate_oc_evt(self, event): # wxGlade: Wetation. + print("Event handler 'gate_oc_evt' not implemented!") + event.Skip() + +# end of class Wetation + +class MyApp(wx.App): + def OnInit(self): + self.wetation = Wetation(None, wx.ID_ANY, "") + self.SetTopWindow(self.wetation) + self.wetation.Show() + return True + +# end of class MyApp + +if __name__ == "__main__": + app = MyApp(0) + app.MainLoop() diff --git a/smarthome.wxg b/gui.wxg similarity index 88% rename from smarthome.wxg rename to gui.wxg index db496ad..b187523 100644 --- a/smarthome.wxg +++ b/gui.wxg @@ -1,9 +1,9 @@ - + - + - 800, 600 + 800, 628 #faf9ff #23238e frame @@ -49,6 +49,7 @@ + 1 @@ -68,6 +69,7 @@ + 1 @@ -88,12 +90,20 @@ + + + 0 + + 20 + 20 + + 0 wxEXPAND - - #000000 + + #23238e #faf9ff 12 @@ -104,6 +114,7 @@ + 1 @@ -133,6 +144,7 @@ + 1 @@ -150,6 +162,7 @@ + 1 @@ -175,6 +188,7 @@ + 1 @@ -192,6 +206,7 @@ + 1 @@ -219,16 +234,25 @@ + 1 + + + 0 + + 20 + 20 + + 0 wxEXPAND - - #000000 + + #23238e #faf9ff 12 @@ -239,6 +263,7 @@ + 1 @@ -268,6 +293,7 @@ + 1 @@ -285,6 +311,7 @@ + 1 @@ -310,6 +337,7 @@ + 1 @@ -327,6 +355,7 @@ + 1 @@ -354,6 +383,7 @@ + 1 @@ -370,8 +400,8 @@ 0 wxEXPAND - - #000000 + + #23238e #faf9ff 12 @@ -381,7 +411,9 @@ 0 + 1 + 1 @@ -393,10 +425,11 @@ 0 - + - garage_oc_evt + gate_oc_evt + 1 @@ -404,8 +437,10 @@ 0 wxALIGN_CENTER - + + 1 + 1 @@ -414,6 +449,7 @@ wxEXPAND 1 + 1 0, 100 50 @@ -424,7 +460,9 @@ 0 wxALIGN_CENTER + 1 + 1 diff --git a/smarthome.py b/smarthome.py index 3499c64..3d2ab90 100644 --- a/smarthome.py +++ b/smarthome.py @@ -1,184 +1,119 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- # -# generated by wxGlade 0.9.4 on Fri Sep 4 13:21:47 2020 -# - -import wx import config +import rpi_envsens as envsens +import garage_protocol +import gui import logging import os - -import time -import garage_protocol -import wetation_protocol import report -import tcp_socket import task -from config import FULL_SCRREN +import tcp_socket +import time +import wetation_protocol +import wx -# begin wxGlade: dependencies -# end wxGlade - -# begin wxGlade: extracode -# end wxGlade +logger = logging.getLogger('APP') -class Wetation(wx.Frame): +class WetationFrameProt(gui.Wetation): def __init__(self, *args, **kwds): - # begin wxGlade: Wetation.__init__ - kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE - wx.Frame.__init__(self, *args, **kwds) - self.SetSize((800, 600)) - self.garage_oc = wx.Button(self, wx.ID_ANY, "Garage") - self.gate_position = wx.Slider(self, wx.ID_ANY, 50, 0, 100) + gui.Wetation.__init__(self, *args, **kwds) + self.__task_data_request__ = task.periodic(10, self.__initiate_data_request__) + self.__init__communication__() - self.__set_properties() - self.__do_layout() - - self.Bind(wx.EVT_BUTTON, self.garage_oc_evt, self.garage_oc) - # end wxGlade - self.ShowFullScreen(FULL_SCRREN) - - def __set_properties(self): - # begin wxGlade: Wetation.__set_properties - self.SetTitle("frame") - self.SetBackgroundColour(wx.Colour(250, 249, 255)) - self.SetForegroundColour(wx.Colour(35, 35, 142)) - self.gate_position.Enable(False) - # end wxGlade - - def __do_layout(self): - # begin wxGlade: Wetation.__do_layout - sizer_main = wx.BoxSizer(wx.VERTICAL) - sizer_8 = wx.BoxSizer(wx.HORIZONTAL) - sizer_env_data_in = wx.BoxSizer(wx.HORIZONTAL) - sizer_9 = wx.BoxSizer(wx.VERTICAL) - sizer_5 = wx.BoxSizer(wx.VERTICAL) - sizer_env_data_out = wx.BoxSizer(wx.HORIZONTAL) - sizer_7 = wx.BoxSizer(wx.VERTICAL) - sizer_4 = wx.BoxSizer(wx.VERTICAL) - sizer_date_time = wx.BoxSizer(wx.HORIZONTAL) - spacer_1 = wx.StaticText(self, wx.ID_ANY, "") - spacer_1.SetBackgroundColour(wx.Colour(35, 35, 142)) - spacer_1.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_main.Add(spacer_1, 0, wx.EXPAND, 0) - date = wx.StaticText(self, wx.ID_ANY, "xx.xx.xxxx", style=wx.ALIGN_LEFT) - date.SetBackgroundColour(wx.Colour(35, 35, 142)) - date.SetForegroundColour(wx.Colour(255, 255, 255)) - date.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_date_time.Add(date, 1, wx.EXPAND | wx.LEFT, 0) - time = wx.StaticText(self, wx.ID_ANY, "xx:xx", style=wx.ALIGN_RIGHT) - time.SetBackgroundColour(wx.Colour(35, 35, 142)) - time.SetForegroundColour(wx.Colour(255, 255, 255)) - time.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_date_time.Add(time, 1, wx.EXPAND | wx.RIGHT, 0) - sizer_main.Add(sizer_date_time, 0, wx.EXPAND, 0) - spacer_2 = wx.StaticText(self, wx.ID_ANY, "") - spacer_2.SetBackgroundColour(wx.Colour(35, 35, 142)) - spacer_2.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_main.Add(spacer_2, 0, wx.EXPAND, 0) - spacer_3 = wx.StaticText(self, wx.ID_ANY, u"Außentemperatur") - spacer_3.SetBackgroundColour(wx.Colour(0, 0, 0)) - spacer_3.SetForegroundColour(wx.Colour(250, 249, 255)) - spacer_3.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_main.Add(spacer_3, 0, wx.EXPAND, 0) - out_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT) - out_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_4.Add(out_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) - out_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT) - out_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_4.Add(out_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) - sizer_env_data_out.Add(sizer_4, 1, wx.EXPAND, 0) - out_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) - out_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_7.Add(out_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) - out_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) - out_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_7.Add(out_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) - sizer_env_data_out.Add(sizer_7, 1, wx.EXPAND, 0) - sizer_env_data_out.Add((50, 20), 0, 0, 0) - out_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) - out_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_env_data_out.Add(out_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0) - sizer_main.Add(sizer_env_data_out, 0, wx.EXPAND, 0) - spacer_4 = wx.StaticText(self, wx.ID_ANY, "Innentemperatur") - spacer_4.SetBackgroundColour(wx.Colour(0, 0, 0)) - spacer_4.SetForegroundColour(wx.Colour(250, 249, 255)) - spacer_4.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_main.Add(spacer_4, 0, wx.EXPAND, 0) - in_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT) - in_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_5.Add(in_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) - in_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT) - in_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_5.Add(in_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) - sizer_env_data_in.Add(sizer_5, 1, wx.EXPAND, 0) - in_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) - in_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_9.Add(in_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) - in_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) - in_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_9.Add(in_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0) - sizer_env_data_in.Add(sizer_9, 1, wx.EXPAND, 0) - sizer_env_data_in.Add((50, 20), 0, 0, 0) - in_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT) - in_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_env_data_in.Add(in_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0) - sizer_main.Add(sizer_env_data_in, 0, wx.EXPAND, 0) - sizer_main.Add((10, 10), 1, 0, 0) - spacer_5 = wx.StaticText(self, wx.ID_ANY, "Garage") - spacer_5.SetBackgroundColour(wx.Colour(0, 0, 0)) - spacer_5.SetForegroundColour(wx.Colour(250, 249, 255)) - spacer_5.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "")) - sizer_main.Add(spacer_5, 0, wx.EXPAND, 0) - sizer_8.Add(self.garage_oc, 0, 0, 0) - gate__open = wx.StaticText(self, wx.ID_ANY, "Close") - sizer_8.Add(gate__open, 0, wx.ALIGN_CENTER, 0) - sizer_8.Add(self.gate_position, 1, wx.EXPAND, 0) - gate_open = wx.StaticText(self, wx.ID_ANY, "Open") - sizer_8.Add(gate_open, 0, wx.ALIGN_CENTER, 0) - sizer_main.Add(sizer_8, 0, wx.EXPAND, 0) - self.SetSizer(sizer_main) - self.Layout() - # end wxGlade - self.date = date - self.time = time + def __init__communication__(self): # - self.out_humidity = out_humidity - self.out_pressure = out_pressure + # Start TCP-Clients + c_tcp = tcp_socket.tcp_client_stp(config.server_out_ip, config.server_out_port, rx_log_lvl=logging.DEBUG) + self.prot_out = wetation_protocol.my_base_protocol_tcp(c_tcp, config.server_out_secret) + self.prot_out.register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, self.update_current_env_data_out) + if config.server_out_secret is not None: + self.prot_out.authentificate() - self.out_temperature = out_temperature - self.out_temperature_min = out_temperature_min - self.out_temperature_max = out_temperature_max - # - self.in_humidity = in_humidity - self.in_pressure = in_pressure + c_tcp = tcp_socket.tcp_client_stp(config.server_in_ip, config.server_in_port, rx_log_lvl=logging.DEBUG) + self.prot_in = wetation_protocol.my_base_protocol_tcp(c_tcp, config.server_in_secret) + self.prot_in.register_callback(wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, self.update_current_env_data_in) + if config.server_in_secret is not None: + self.prot_in.authentificate() - self.in_temperature = in_temperature + c_tcp = tcp_socket.tcp_client_stp(config.server_garage_ip, config.server_garage_port, rx_log_lvl=logging.DEBUG) + self.prot_garage = garage_protocol.my_base_protocol_tcp(c_tcp, config.server_garage_secret) + self.prot_garage.register_callback(garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE, garage_protocol.my_base_protocol_tcp.GATE_POSITION, self.update_gate_position) + if config.server_garage_secret is not None: + self.prot_garage.authentificate() + + def __update_current_envdata__(self, msg, temperature, humidity, pressure): + if msg.get_status() == wetation_protocol.my_base_protocol_tcp.STATUS_OKAY: + env_data = msg.get_data() + wx.CallAfter(temperature.SetLabel, "%.1f °C" % env_data[envsens.KEY_TEMPERATURE]) + wx.CallAfter(humidity.SetLabel, "%.1f %%" % env_data[envsens.KEY_HUMIDITY]) + wx.CallAfter(pressure.SetLabel, "%.0f mbar" % env_data[envsens.KEY_PRESSURE]) + wx.CallAfter(self.Layout) + return wetation_protocol.my_base_protocol_tcp.STATUS_OKAY, None + else: + logger.error('No environmental data received! MSG_STATUS was %s', wetation_protocol.my_base_protocol_tcp.STATUS_NAMES.get(msg.get_status(), repr(msg.get_status()))) + return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None + + def update_current_env_data_out(self, msg): + return self.__update_current_envdata__(msg, self.out_temperature, self.out_humidity, self.out_pressure) + + def update_current_env_data_in(self, msg): + return self.__update_current_envdata__(msg, self.in_temperature, self.in_humidity, self.in_pressure) + + def update_gate_position(self, msg): + if msg.get_status() == garage_protocol.my_base_protocol_tcp.STATUS_OKAY: + # + # show gate section in GUI + # + self.heading_garage.show(True) + self.gate_oc.show(True) + self.gate_open.show(True) + self.gate_position.show(True) + self.gate_close.show(True) + # + # update gate position + # + wx.CallAfter(self.gate_position.SetValue, msg.get_data() * 100) + wx.CallAfter(self.Layout) + return garage_protocol.my_base_protocol_tcp.STATUS_OKAY, None + else: + logger.error('No gate position received! MSG_STATUS was %s', garage_protocol.my_base_protocol_tcp.STATUS_NAMES.get(msg.get_status(), repr(msg.get_status()))) + return garage_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None def garage_oc_evt(self, event): # wxGlade: Wetation. - self.prot_garage.send(prot_garage.SID_EXECUTE_REQUEST, prot_garage.OPEN_CLOSE_GATE, None) + self.prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_EXECUTE_REQUEST, garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE, None) event.Skip() -# end of class Wetation + + def __initiate_data_request__(self, rt): + self.prot_out.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None) + self.prot_in.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None) + self.prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST, garage_protocol.my_base_protocol_tcp.GATE_POSITION, None) + # TODO: Move the following three lines to the wx idle task + wx.CallAfter(self.time.SetLabel, time.strftime("%H:%M")) + wx.CallAfter(self.date.SetLabel, time.strftime("%d.%m.%Y")) + wx.CallAfter(self.Layout) + + def run(self): + self.__task_data_request__.run() + + def close(self): + self.__task_data_request__.stop() + self.__task_data_request__.join() + + def __del__(self): + self.close() + class MyApp(wx.App): def OnInit(self): - self.frame = Wetation(None, wx.ID_ANY, "") + self.frame = WetationFrameProt(None, wx.ID_ANY, "") self.SetTopWindow(self.frame) self.frame.Show() return True -# end of class MyApp - -def initiate_update(rt, frame, prot_out, prot_in, prot_garage): - prot_out.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None) - prot_in.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None) - prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST, garage_protocol.my_base_protocol_tcp.GATE_POSITION, None) - wx.CallAfter(frame.time.SetLabel, time.strftime("%H:%M")) - wx.CallAfter(frame.date.SetLabel, time.strftime("%d.%m.%Y")) - wx.CallAfter(frame.Layout) @@ -186,26 +121,6 @@ if __name__ == "__main__": report.appLoggingConfigure(os.path.dirname(__file__), config.LOGTARGET, config.loggers) # app = MyApp(0) - # - # Start TCP-Clients - c_tcp = tcp_socket.tcp_client_stp(config.server_out_ip, config.server_out_port, rx_log_lvl=logging.DEBUG) - prot_out = wetation_protocol.my_smarthome_gui_client_protocol_tcp(c_tcp, app.frame.out_temperature, app.frame.out_humidity, app.frame.out_pressure, app.frame.Layout, config.server_out_secret) - if config.server_out_secret is not None: - prot_out.authentificate() - c_tcp = tcp_socket.tcp_client_stp(config.server_in_ip, config.server_in_port, rx_log_lvl=logging.DEBUG) - prot_in = wetation_protocol.my_smarthome_gui_client_protocol_tcp(c_tcp, app.frame.in_temperature, app.frame.in_humidity, app.frame.in_pressure, app.frame.Layout, config.server_in_secret) - if config.server_in_secret is not None: - prot_in.authentificate() - c_tcp = tcp_socket.tcp_client_stp(config.server_garage_ip, config.server_garage_port, rx_log_lvl=logging.DEBUG) - prot_garage = garage_protocol.my_smarthome_gui_client_protocol_tcp(c_tcp, app.frame.gate_position, app.frame.Layout, config.server_garage_secret) - if config.server_garage_secret is not None: - prot_garage.authentificate() - app.frame.prot_garage = prot_garage - pt = task.periodic(10, initiate_update, app.frame, prot_out, prot_in, prot_garage) - pt.run() + app.frame.run() app.MainLoop() - pt.stop() - try: - pt.join() - finally: - pt.stop() + app.frame.close() diff --git a/wetation_protocol b/wetation_protocol index 4a2f461..53e4523 160000 --- a/wetation_protocol +++ b/wetation_protocol @@ -1 +1 @@ -Subproject commit 4a2f461be4ac53984aded6e4b7d128f3fb5b0c39 +Subproject commit 53e4523c140b5f51dedb3b128048eb59c1a5da4c