wether station gui client
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

smarthome.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # generated by wxGlade 0.9.4 on Fri Sep 4 13:21:47 2020
  5. #
  6. import wx
  7. import config
  8. import logging
  9. import os
  10. import time
  11. import garage_protocol
  12. import wetation_protocol
  13. import report
  14. import tcp_socket
  15. import task
  16. from config import FULL_SCRREN
  17. # begin wxGlade: dependencies
  18. # end wxGlade
  19. # begin wxGlade: extracode
  20. # end wxGlade
  21. class Wetation(wx.Frame):
  22. def __init__(self, *args, **kwds):
  23. # begin wxGlade: Wetation.__init__
  24. kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
  25. wx.Frame.__init__(self, *args, **kwds)
  26. self.SetSize((800, 600))
  27. self.garage_oc = wx.Button(self, wx.ID_ANY, "Garage")
  28. self.gate_position = wx.Slider(self, wx.ID_ANY, 50, 0, 100)
  29. self.__set_properties()
  30. self.__do_layout()
  31. self.Bind(wx.EVT_BUTTON, self.garage_oc_evt, self.garage_oc)
  32. # end wxGlade
  33. self.ShowFullScreen(FULL_SCRREN)
  34. def __set_properties(self):
  35. # begin wxGlade: Wetation.__set_properties
  36. self.SetTitle("frame")
  37. self.SetBackgroundColour(wx.Colour(250, 249, 255))
  38. self.SetForegroundColour(wx.Colour(35, 35, 142))
  39. self.gate_position.Enable(False)
  40. # end wxGlade
  41. def __do_layout(self):
  42. # begin wxGlade: Wetation.__do_layout
  43. sizer_main = wx.BoxSizer(wx.VERTICAL)
  44. sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
  45. sizer_env_data_in = wx.BoxSizer(wx.HORIZONTAL)
  46. sizer_9 = wx.BoxSizer(wx.VERTICAL)
  47. sizer_5 = wx.BoxSizer(wx.VERTICAL)
  48. sizer_env_data_out = wx.BoxSizer(wx.HORIZONTAL)
  49. sizer_7 = wx.BoxSizer(wx.VERTICAL)
  50. sizer_4 = wx.BoxSizer(wx.VERTICAL)
  51. sizer_date_time = wx.BoxSizer(wx.HORIZONTAL)
  52. spacer_1 = wx.StaticText(self, wx.ID_ANY, "")
  53. spacer_1.SetBackgroundColour(wx.Colour(35, 35, 142))
  54. spacer_1.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  55. sizer_main.Add(spacer_1, 0, wx.EXPAND, 0)
  56. date = wx.StaticText(self, wx.ID_ANY, "xx.xx.xxxx", style=wx.ALIGN_LEFT)
  57. date.SetBackgroundColour(wx.Colour(35, 35, 142))
  58. date.SetForegroundColour(wx.Colour(255, 255, 255))
  59. date.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  60. sizer_date_time.Add(date, 1, wx.EXPAND | wx.LEFT, 0)
  61. time = wx.StaticText(self, wx.ID_ANY, "xx:xx", style=wx.ALIGN_RIGHT)
  62. time.SetBackgroundColour(wx.Colour(35, 35, 142))
  63. time.SetForegroundColour(wx.Colour(255, 255, 255))
  64. time.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  65. sizer_date_time.Add(time, 1, wx.EXPAND | wx.RIGHT, 0)
  66. sizer_main.Add(sizer_date_time, 0, wx.EXPAND, 0)
  67. spacer_2 = wx.StaticText(self, wx.ID_ANY, "")
  68. spacer_2.SetBackgroundColour(wx.Colour(35, 35, 142))
  69. spacer_2.SetFont(wx.Font(5, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  70. sizer_main.Add(spacer_2, 0, wx.EXPAND, 0)
  71. spacer_3 = wx.StaticText(self, wx.ID_ANY, u"Außentemperatur")
  72. spacer_3.SetBackgroundColour(wx.Colour(0, 0, 0))
  73. spacer_3.SetForegroundColour(wx.Colour(250, 249, 255))
  74. spacer_3.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  75. sizer_main.Add(spacer_3, 0, wx.EXPAND, 0)
  76. out_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
  77. out_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  78. sizer_4.Add(out_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
  79. out_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
  80. out_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  81. sizer_4.Add(out_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
  82. sizer_env_data_out.Add(sizer_4, 1, wx.EXPAND, 0)
  83. out_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
  84. out_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  85. sizer_7.Add(out_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
  86. out_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
  87. out_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  88. sizer_7.Add(out_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
  89. sizer_env_data_out.Add(sizer_7, 1, wx.EXPAND, 0)
  90. sizer_env_data_out.Add((50, 20), 0, 0, 0)
  91. out_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
  92. out_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  93. sizer_env_data_out.Add(out_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0)
  94. sizer_main.Add(sizer_env_data_out, 0, wx.EXPAND, 0)
  95. spacer_4 = wx.StaticText(self, wx.ID_ANY, "Innentemperatur")
  96. spacer_4.SetBackgroundColour(wx.Colour(0, 0, 0))
  97. spacer_4.SetForegroundColour(wx.Colour(250, 249, 255))
  98. spacer_4.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  99. sizer_main.Add(spacer_4, 0, wx.EXPAND, 0)
  100. in_humidity = wx.StaticText(self, wx.ID_ANY, "- %", style=wx.ALIGN_RIGHT)
  101. in_humidity.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  102. sizer_5.Add(in_humidity, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
  103. in_pressure = wx.StaticText(self, wx.ID_ANY, "- mbar", style=wx.ALIGN_RIGHT)
  104. in_pressure.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  105. sizer_5.Add(in_pressure, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
  106. sizer_env_data_in.Add(sizer_5, 1, wx.EXPAND, 0)
  107. in_temperature_min = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
  108. in_temperature_min.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  109. sizer_9.Add(in_temperature_min, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
  110. in_temperature_max = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
  111. in_temperature_max.SetFont(wx.Font(24, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  112. sizer_9.Add(in_temperature_max, 1, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, 0)
  113. sizer_env_data_in.Add(sizer_9, 1, wx.EXPAND, 0)
  114. sizer_env_data_in.Add((50, 20), 0, 0, 0)
  115. in_temperature = wx.StaticText(self, wx.ID_ANY, u"-.- °C", style=wx.ALIGN_RIGHT)
  116. in_temperature.SetFont(wx.Font(48, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  117. sizer_env_data_in.Add(in_temperature, 2, wx.ALIGN_RIGHT | wx.RIGHT, 0)
  118. sizer_main.Add(sizer_env_data_in, 0, wx.EXPAND, 0)
  119. sizer_main.Add((10, 10), 1, 0, 0)
  120. spacer_5 = wx.StaticText(self, wx.ID_ANY, "Garage")
  121. spacer_5.SetBackgroundColour(wx.Colour(0, 0, 0))
  122. spacer_5.SetForegroundColour(wx.Colour(250, 249, 255))
  123. spacer_5.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
  124. sizer_main.Add(spacer_5, 0, wx.EXPAND, 0)
  125. sizer_8.Add(self.garage_oc, 0, 0, 0)
  126. gate__open = wx.StaticText(self, wx.ID_ANY, "Close")
  127. sizer_8.Add(gate__open, 0, wx.ALIGN_CENTER, 0)
  128. sizer_8.Add(self.gate_position, 1, wx.EXPAND, 0)
  129. gate_open = wx.StaticText(self, wx.ID_ANY, "Open")
  130. sizer_8.Add(gate_open, 0, wx.ALIGN_CENTER, 0)
  131. sizer_main.Add(sizer_8, 0, wx.EXPAND, 0)
  132. self.SetSizer(sizer_main)
  133. self.Layout()
  134. # end wxGlade
  135. self.date = date
  136. self.time = time
  137. #
  138. self.out_humidity = out_humidity
  139. self.out_pressure = out_pressure
  140. self.out_temperature = out_temperature
  141. self.out_temperature_min = out_temperature_min
  142. self.out_temperature_max = out_temperature_max
  143. #
  144. self.in_humidity = in_humidity
  145. self.in_pressure = in_pressure
  146. self.in_temperature = in_temperature
  147. def garage_oc_evt(self, event): # wxGlade: Wetation.<event_handler>
  148. self.prot_garage.send(prot_garage.SID_EXECUTE_REQUEST, prot_garage.OPEN_CLOSE_GATE, None)
  149. event.Skip()
  150. # end of class Wetation
  151. class MyApp(wx.App):
  152. def OnInit(self):
  153. self.frame = Wetation(None, wx.ID_ANY, "")
  154. self.SetTopWindow(self.frame)
  155. self.frame.Show()
  156. return True
  157. # end of class MyApp
  158. def initiate_update(rt, frame, prot_out, prot_in, prot_garage):
  159. prot_out.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
  160. prot_in.send(wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST, wetation_protocol.my_base_protocol_tcp.CURRENT_ENVDATA, None)
  161. prot_garage.send(garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST, garage_protocol.my_base_protocol_tcp.GATE_POSITION, None)
  162. wx.CallAfter(frame.time.SetLabel, time.strftime("%H:%M"))
  163. wx.CallAfter(frame.date.SetLabel, time.strftime("%d.%m.%Y"))
  164. wx.CallAfter(frame.Layout)
  165. if __name__ == "__main__":
  166. report.appLoggingConfigure(os.path.dirname(__file__), config.LOGTARGET, config.loggers)
  167. #
  168. app = MyApp(0)
  169. #
  170. # Start TCP-Clients
  171. c_tcp = tcp_socket.tcp_client_stp(config.server_out_ip, config.server_out_port, rx_log_lvl=logging.DEBUG)
  172. 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)
  173. if config.server_out_secret is not None:
  174. prot_out.authentificate()
  175. c_tcp = tcp_socket.tcp_client_stp(config.server_in_ip, config.server_in_port, rx_log_lvl=logging.DEBUG)
  176. 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)
  177. if config.server_in_secret is not None:
  178. prot_in.authentificate()
  179. c_tcp = tcp_socket.tcp_client_stp(config.server_garage_ip, config.server_garage_port, rx_log_lvl=logging.DEBUG)
  180. prot_garage = garage_protocol.my_smarthome_gui_client_protocol_tcp(c_tcp, app.frame.gate_position, app.frame.Layout, config.server_garage_secret)
  181. if config.server_garage_secret is not None:
  182. prot_garage.authentificate()
  183. app.frame.prot_garage = prot_garage
  184. pt = task.periodic(10, initiate_update, app.frame, prot_out, prot_in, prot_garage)
  185. pt.run()
  186. app.MainLoop()
  187. pt.stop()
  188. try:
  189. pt.join()
  190. finally:
  191. pt.stop()