wether station protocol
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

__init__.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. import config
  4. import logging
  5. import socket_protocol
  6. import rpi_envsens as envsens
  7. logger = logging.getLogger('APP')
  8. class my_base_protocol_tcp(socket_protocol.pure_json_protocol):
  9. # EXECUTE_REQUESTs
  10. CURRENT_ENVDATA = 0
  11. class my_server_protocol_tcp(my_base_protocol_tcp):
  12. def __init__(self, comm_instance, envsens, secret=None):
  13. socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
  14. self.envsens = envsens
  15. self.register_callback(self.SID_READ_REQUEST, self.CURRENT_ENVDATA, self.rd_temperature)
  16. def rd_temperature(self, msg):
  17. return self.STATUS_OKAY, self.envsens.get_env_data()
  18. class my_smarthome_gui_client_protocol_tcp(my_base_protocol_tcp):
  19. START_ROUTINE_DATA_IDS = []
  20. def __init__(self, comm_instance, cb_temperature, cb_humidity, cb_pressure, cb_layout, secret=None):
  21. self.cb_temperature = cb_temperature
  22. self.cb_humidity = cb_humidity
  23. self.cb_pressure = cb_pressure
  24. self.cb_layout = cb_layout
  25. socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
  26. self.register_callback(self.SID_READ_RESPONSE, self.CURRENT_ENVDATA, self.read_current_envdata)
  27. def __authentificate_process_feedback__(self, msg):
  28. if msg.get_data() is True:
  29. print("The client is authentificated.")
  30. else:
  31. print("AUTHENTIFICATION ERROR")
  32. return my_base_protocol_tcp.__authentificate_process_feedback__(self, msg)
  33. def read_current_envdata(self, msg):
  34. import wx
  35. if msg.get_status() == self.STATUS_OKAY:
  36. env_data = msg.get_data()
  37. wx.CallAfter(self.cb_temperature.SetLabel, "%.1f °C" % env_data[envsens.KEY_TEMPERATURE])
  38. wx.CallAfter(self.cb_humidity.SetLabel, "%.1f %%" % env_data[envsens.KEY_HUMIDITY])
  39. wx.CallAfter(self.cb_pressure.SetLabel, "%.0f mbar" % env_data[envsens.KEY_PRESSURE])
  40. wx.CallAfter(self.cb_layout)
  41. return self.STATUS_OKAY, None
  42. else:
  43. print('No environmental data received!')
  44. return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None