Browse Source

Module Update

mod_update
Dirk Alders 4 years ago
parent
commit
fdef5e6a9e
6 changed files with 34 additions and 39 deletions
  1. 4
    10
      config_example/config.py
  2. 1
    1
      garage_protocol
  3. 26
    25
      smarthome.py
  4. 1
    1
      socket_protocol
  5. 1
    1
      stringtools
  6. 1
    1
      wetation_protocol

+ 4
- 10
config_example/config.py View File

9
 # TCP-Server
9
 # TCP-Server
10
 #
10
 #
11
 server_out_secret = None  # or set a secret to require client authentification: b'give_a_secret_string_here'
11
 server_out_secret = None  # or set a secret to require client authentification: b'give_a_secret_string_here'
12
-server_out_ip = '192.168.0.121'
12
+server_out_ip = 'localhost'
13
 server_out_port = 37000
13
 server_out_port = 37000
14
 server_in_secret = None  # or set a secret to require client authentification: b'give_a_secret_string_here'
14
 server_in_secret = None  # or set a secret to require client authentification: b'give_a_secret_string_here'
15
-server_in_ip = '192.168.0.120'
16
-server_in_port = 37000
15
+server_in_ip = 'localhost'
16
+server_in_port = 47000
17
 
17
 
18
 server_garage_secret = None  # or set a secret to require client authentification: b'give_a_secret_string_here'
18
 server_garage_secret = None  # or set a secret to require client authentification: b'give_a_secret_string_here'
19
-server_garage_ip = '192.168.0.13'
19
+server_garage_ip = 'localhost'
20
 server_garage_port = 10000
20
 server_garage_port = 10000
21
 # Logging
21
 # Logging
22
 #
22
 #
23
 LOGTARGET = 'stdout'   # possible choices are: 'logfile' or 'stdout'
23
 LOGTARGET = 'stdout'   # possible choices are: 'logfile' or 'stdout'
24
-SHORT_FMT = "%(asctime)s: %(levelname)-7s - %(message)s"
25
-""" A short formatter including the most important information"""
26
-LONG_FMT = """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27
-File "%(pathname)s", line %(lineno)d, in %(funcName)s
28
-%(asctime)s: %(levelname)-7s - %(message)s"""
29
-""" A long formatter which results in links to the source code inside Eclipse"""
30
 
24
 
31
 # Logging
25
 # Logging
32
 #
26
 #

+ 1
- 1
garage_protocol

1
-Subproject commit c5f4e0323aa0a07d996372f94c9652be6fad3919
1
+Subproject commit 882ea5a033338b0da86d312266ee93179133ff41

+ 26
- 25
smarthome.py View File

12
 import numbers
12
 import numbers
13
 import os
13
 import os
14
 import report
14
 import report
15
+import socket_protocol
15
 import task
16
 import task
16
 import tcp_socket
17
 import tcp_socket
17
 import time
18
 import time
63
     REQUEST_MSGS_SLOW = {
64
     REQUEST_MSGS_SLOW = {
64
         PROT_ID_IN: [
65
         PROT_ID_IN: [
65
             {
66
             {
66
-                'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
67
-                'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT,
67
+                'service_id': socket_protocol.SID_READ_REQUEST,
68
+                'data_id': wetation_protocol.ENVDATA_STATISTIC_DHT,
68
             },
69
             },
69
             {
70
             {
70
-                'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
71
-                'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP,
71
+                'service_id': socket_protocol.SID_READ_REQUEST,
72
+                'data_id': wetation_protocol.ENVDATA_STATISTIC_BMP,
72
             },
73
             },
73
         ],
74
         ],
74
         PROT_ID_OUT: [
75
         PROT_ID_OUT: [
75
             {
76
             {
76
-                'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
77
-                'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT,
77
+                'service_id': socket_protocol.SID_READ_REQUEST,
78
+                'data_id': wetation_protocol.ENVDATA_STATISTIC_DHT,
78
             },
79
             },
79
             {
80
             {
80
-                'service_id': wetation_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
81
-                'data_id': wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP,
81
+                'service_id': socket_protocol.SID_READ_REQUEST,
82
+                'data_id': wetation_protocol.ENVDATA_STATISTIC_BMP,
82
             },
83
             },
83
         ],
84
         ],
84
     }
85
     }
86
     REQUEST_MSGS_FAST = {
87
     REQUEST_MSGS_FAST = {
87
         PROT_ID_GARAGE: [
88
         PROT_ID_GARAGE: [
88
             {
89
             {
89
-                'service_id': garage_protocol.my_base_protocol_tcp.SID_READ_REQUEST,
90
-                'data_id': garage_protocol.my_base_protocol_tcp.GATE_POSITION,
90
+                'service_id': socket_protocol.SID_READ_REQUEST,
91
+                'data_id': garage_protocol.GATE_POSITION,
91
             },
92
             },
92
         ],
93
         ],
93
     }
94
     }
162
         cn = self.PROT_NAMES[prot_id]
163
         cn = self.PROT_NAMES[prot_id]
163
         logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
164
         logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
164
         if prot_id == self.PROT_ID_GARAGE:
165
         if prot_id == self.PROT_ID_GARAGE:
165
-            if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
166
+            if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
166
                 rv = isinstance(data, numbers.Number)
167
                 rv = isinstance(data, numbers.Number)
167
-            elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
168
+            elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
168
                 if data is True:
169
                 if data is True:
169
                     rv = True
170
                     rv = True
170
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
171
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
171
-            if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
172
+            if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
172
                 rv = True
173
                 rv = True
173
                 for main_key in [bmp_180.KEY_PRESSURE, bmp_180.KEY_TEMPERATURE, bmp_180.KEY_TIME]:
174
                 for main_key in [bmp_180.KEY_PRESSURE, bmp_180.KEY_TEMPERATURE, bmp_180.KEY_TIME]:
174
                     if main_key not in data:
175
                     if main_key not in data:
179
                             if not isinstance(data[main_key].get(sub_key), numbers.Number):
180
                             if not isinstance(data[main_key].get(sub_key), numbers.Number):
180
                                 rv = False
181
                                 rv = False
181
                                 break
182
                                 break
182
-            elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
183
+            elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
183
                 rv = True
184
                 rv = True
184
                 for main_key in [dht_22.KEY_HUMIDITY, dht_22.KEY_TEMPERATURE, dht_22.KEY_TIME]:
185
                 for main_key in [dht_22.KEY_HUMIDITY, dht_22.KEY_TEMPERATURE, dht_22.KEY_TIME]:
185
                     if main_key not in data:
186
                     if main_key not in data:
200
         data = msg.get_data()
201
         data = msg.get_data()
201
         if self.__validate_response_data__(prot_id, service_id, data_id, data):
202
         if self.__validate_response_data__(prot_id, service_id, data_id, data):
202
             wx.CallAfter(self.__data__, prot_id, service_id, data_id, data)
203
             wx.CallAfter(self.__data__, prot_id, service_id, data_id, data)
203
-            return wetation_protocol.my_base_protocol_tcp.STATUS_OKAY, None
204
+            return socket_protocol.STATUS_OKAY, None
204
         else:
205
         else:
205
             wx.CallAfter(self.__no_data__, prot_id, service_id, data_id)
206
             wx.CallAfter(self.__no_data__, prot_id, service_id, data_id)
206
-            return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
207
+            return socket_protocol.STATUS_SERVICE_OR_DATA_UNKNOWN, None
207
 
208
 
208
     def __no_data__(self, prot_id, service_id, data_id):
209
     def __no_data__(self, prot_id, service_id, data_id):
209
         cn = self.PROT_NAMES[prot_id]
210
         cn = self.PROT_NAMES[prot_id]
210
         logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
211
         logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
211
         if prot_id == self.PROT_ID_GARAGE:
212
         if prot_id == self.PROT_ID_GARAGE:
212
-            if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
213
+            if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
213
                 logger.warning('Resetting GUI elements for %s', cn)
214
                 logger.warning('Resetting GUI elements for %s', cn)
214
                 self.heading_garage.Show(False)
215
                 self.heading_garage.Show(False)
215
                 self.gate_oc.Show(False)
216
                 self.gate_oc.Show(False)
218
                 self.gate_close.Show(False)
219
                 self.gate_close.Show(False)
219
                 self.Layout()
220
                 self.Layout()
220
                 return
221
                 return
221
-            elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
222
+            elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
222
                 return
223
                 return
223
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
224
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
224
-            if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
225
+            if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
225
                 logger.warning('Resetting GUI elements for %s', cn)
226
                 logger.warning('Resetting GUI elements for %s', cn)
226
                 txt_pressure = '- hPa'
227
                 txt_pressure = '- hPa'
227
                 if prot_id == self.PROT_ID_IN:
228
                 if prot_id == self.PROT_ID_IN:
230
                     self.out_pressure.SetLabel(txt_pressure)
231
                     self.out_pressure.SetLabel(txt_pressure)
231
                 self.Layout()
232
                 self.Layout()
232
                 return
233
                 return
233
-            elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
234
+            elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
234
                 logger.warning('Resetting GUI elements for %s', cn)
235
                 logger.warning('Resetting GUI elements for %s', cn)
235
                 txt_temperature = '-.- °C'
236
                 txt_temperature = '-.- °C'
236
                 txt_humidity = '-.- %'
237
                 txt_humidity = '-.- %'
248
         cn = self.PROT_NAMES[prot_id]
249
         cn = self.PROT_NAMES[prot_id]
249
         logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
250
         logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
250
         if prot_id == self.PROT_ID_GARAGE:
251
         if prot_id == self.PROT_ID_GARAGE:
251
-            if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
252
+            if service_id == socket_protocol.SID_READ_RESPONSE and data_id == garage_protocol.GATE_POSITION:
252
                 logger.debug('Setting %s position to %3d', cn, int(data * 100))
253
                 logger.debug('Setting %s position to %3d', cn, int(data * 100))
253
                 self.heading_garage.Show(True)
254
                 self.heading_garage.Show(True)
254
                 self.gate_oc.Show(True)
255
                 self.gate_oc.Show(True)
258
                 self.gate_position.SetValue(int(data * 100))
259
                 self.gate_position.SetValue(int(data * 100))
259
                 self.Layout()
260
                 self.Layout()
260
                 return
261
                 return
261
-            elif service_id == garage_protocol.my_base_protocol_tcp.SID_EXECUTE_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE:
262
+            elif service_id == socket_protocol.SID_EXECUTE_RESPONSE and data_id == garage_protocol.OPEN_CLOSE_GATE:
262
                 return
263
                 return
263
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
264
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
264
-            if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
265
+            if service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_BMP:
265
                 data = helpers.continues_statistic_multivalue(**data)
266
                 data = helpers.continues_statistic_multivalue(**data)
266
                 logger.debug('Setting %s pressure to %4d hPa', cn, data[bmp_180.KEY_PRESSURE].mean)
267
                 logger.debug('Setting %s pressure to %4d hPa', cn, data[bmp_180.KEY_PRESSURE].mean)
267
                 #
268
                 #
271
                 else:
272
                 else:
272
                     wx.CallAfter(self.update_current_bmp_env_data, data, self.out_pressure)
273
                     wx.CallAfter(self.update_current_bmp_env_data, data, self.out_pressure)
273
                 return
274
                 return
274
-            elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
275
+            elif service_id == socket_protocol.SID_READ_RESPONSE and data_id == wetation_protocol.ENVDATA_STATISTIC_DHT:
275
                 data = helpers.continues_statistic_multivalue(**data)
276
                 data = helpers.continues_statistic_multivalue(**data)
276
                 #
277
                 #
277
                 # Current environmental data
278
                 # Current environmental data
321
         ).ShowModal()
322
         ).ShowModal()
322
         if r == wx.ID_YES:
323
         if r == wx.ID_YES:
323
             logger.debug("Gate open/close request")
324
             logger.debug("Gate open/close request")
324
-            self.__prot__[self.PROT_ID_GARAGE].send(garage_protocol.my_base_protocol_tcp.SID_EXECUTE_REQUEST, garage_protocol.my_base_protocol_tcp.OPEN_CLOSE_GATE, None)
325
+            self.__prot__[self.PROT_ID_GARAGE].send(socket_protocol.SID_EXECUTE_REQUEST, garage_protocol.OPEN_CLOSE_GATE, None)
325
         event.Skip()
326
         event.Skip()
326
 
327
 
327
     def reset_in_temp_minmax_evt(self, event):
328
     def reset_in_temp_minmax_evt(self, event):

+ 1
- 1
socket_protocol

1
-Subproject commit 7c02c8dd3cc5b24a1ba8ce71c0b7396f3759671e
1
+Subproject commit 35d9f688a4f080a8cae70a18e27036b55399edde

+ 1
- 1
stringtools

1
-Subproject commit 76d8ae9b1bfd894bc5f4b830394ce0552120a508
1
+Subproject commit 5ac92e2b864cd27bd4026352ba9149f4d23ca019

+ 1
- 1
wetation_protocol

1
-Subproject commit cdc9912f3d26edea9e0a36b0fccfc7d3bfd6b868
1
+Subproject commit 07357d33ad5dbed4807fef6ef088abd5b005e363

Loading…
Cancel
Save