12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #!/usr/bin/env python
- # -*- coding: UTF-8 -*-
-
- import config
- import os
- import protocol
- import report
- import socket_protocol
- import sys
- import tcp_socket
-
-
- def help_msg():
- print(""""Possible commands are:
- * q[uit]
- * auto[matic]
- * man[ual]
- * mode
- * state
- * get [all,bakehose,bakery,mill,reesehouse,ploenlein]
- * set [all,bakehose,bakery,mill,reesehouse,ploenlein] [on,off]""")
-
-
-
- if __name__ == '__main__':
- report.appLoggingConfigure(os.path.dirname(__file__), config.LOGTARGET, ((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT)
- c = tcp_socket.tcp_client_stp(config.server_ip, config.server_port)
- prot = protocol.my_client_protocol(c, secret=config.secret, channel_name='leyk')
- target_dict = {
- 'bakehouse': [protocol.DID_BAKE_HOUSE, ],
- 'bakery': [protocol.DID_BAKERY, ],
- 'mill': [protocol.DID_MILL, ],
- 'ploenlein': [protocol.DID_PLOENLEIN, ],
- 'reesehouse': [protocol.DID_REESE_HOUSE, ],
- 'all': [protocol.DID_BAKE_HOUSE, protocol.DID_BAKERY, protocol.DID_MILL, protocol.DID_PLOENLEIN, protocol.DID_REESE_HOUSE]
- }
- if prot.authentificate():
- help_msg()
- cmd = None
- while cmd not in ["q", "quit"]:
- cmd = sys.stdin.readline()
- cmd = cmd.lower().strip('\n')
- if cmd == 'help':
- help_msg()
- elif cmd in ["auto", "automatic"]:
- prot.send(socket_protocol.SID_EXECUTE_REQUEST, protocol.DID_MODE, 'automatic')
- elif cmd in ["man", "manual"]:
- prot.send(socket_protocol.SID_EXECUTE_REQUEST, protocol.DID_MODE, 'manual')
- elif cmd == "mode":
- prot.send(socket_protocol.SID_READ_REQUEST, protocol.DID_MODE, None)
- elif cmd == "state":
- prot.send(socket_protocol.SID_READ_REQUEST, protocol.DID_STATE, None)
- elif cmd.startswith('get '):
- target = target_dict.get(cmd.split(' ')[1])
- if target is not None:
- for t in target:
- prot.send(socket_protocol.SID_READ_REQUEST, t, None)
- elif cmd.startswith('set '):
- target = target_dict.get(cmd.split(' ')[1])
- try:
- state = {'on': True, 'off': False}.get(cmd.split(' ')[2])
- except IndexError:
- state = None
- if target is not None and state is not None:
- for t in target:
- prot.send(socket_protocol.SID_EXECUTE_REQUEST, t, state)
- c.close()
|