12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #!/usr/bin/env python
- # -*- coding: UTF-8 -*-
-
- import config
- import logging
- import socket_protocol
-
- import rpi_envsens as envsens
-
- logger = logging.getLogger('APP')
-
-
-
-
- class my_base_protocol_tcp(socket_protocol.pure_json_protocol):
- # EXECUTE_REQUESTs
- CURRENT_ENVDATA = 0
-
-
- class my_server_protocol_tcp(my_base_protocol_tcp):
- def __init__(self, comm_instance, envsens, secret=None):
- socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
- self.envsens = envsens
- self.register_callback(self.SID_READ_REQUEST, self.CURRENT_ENVDATA, self.rd_temperature)
-
- def rd_temperature(self, msg):
- return self.STATUS_OKAY, self.envsens.get_env_data()
-
-
- class my_smarthome_gui_client_protocol_tcp(my_base_protocol_tcp):
- START_ROUTINE_DATA_IDS = []
-
- def __init__(self, comm_instance, cb_temperature, cb_humidity, cb_pressure, cb_layout, secret=None):
- self.cb_temperature = cb_temperature
- self.cb_humidity = cb_humidity
- self.cb_pressure = cb_pressure
- self.cb_layout = cb_layout
- socket_protocol.pure_json_protocol.__init__(self, comm_instance, secret)
- self.register_callback(self.SID_READ_RESPONSE, self.CURRENT_ENVDATA, self.read_current_envdata)
-
- def __authentificate_process_feedback__(self, msg):
- if msg.get_data() is True:
- print("The client is authentificated.")
- else:
- print("AUTHENTIFICATION ERROR")
- return my_base_protocol_tcp.__authentificate_process_feedback__(self, msg)
-
- def read_current_envdata(self, msg):
- import wx
-
- if msg.get_status() == self.STATUS_OKAY:
- env_data = msg.get_data()
- wx.CallAfter(self.cb_temperature.SetLabel, "%.1f °C" % env_data[envsens.KEY_TEMPERATURE])
- wx.CallAfter(self.cb_humidity.SetLabel, "%.1f %%" % env_data[envsens.KEY_HUMIDITY])
- wx.CallAfter(self.cb_pressure.SetLabel, "%.0f mbar" % env_data[envsens.KEY_PRESSURE])
- wx.CallAfter(self.cb_layout)
- return self.STATUS_OKAY, None
- else:
- print('No environmental data received!')
- return self.STATUS_SERVICE_OR_DATA_UNKNOWN, None
|