#!/usr/bin/env python # -*- coding: UTF-8 -*- import config import os import protocol import report 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__), 'logfile', config.loggers) c = tcp_socket.tcp_client_stp(config.server_ip, config.server_port) prot = protocol.my_client_protocol(c, secret=config.secret) target_dict = { 'bakehouse': [prot.DID_BAKE_HOUSE, ], 'bakery': [prot.DID_BAKERY, ], 'mill': [prot.DID_MILL, ], 'ploenlein': [prot.DID_PLOENLEIN, ], 'reesehouse': [prot.DID_REESE_HOUSE, ], 'all': [prot.DID_BAKE_HOUSE, prot.DID_BAKERY, prot.DID_MILL, prot.DID_PLOENLEIN, prot.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(prot.SID_EXECUTE_REQUEST, prot.DID_MODE, 'automatic') elif cmd in ["man", "manual"]: prot.send(prot.SID_EXECUTE_REQUEST, prot.DID_MODE, 'manual') elif cmd == "mode": prot.send(prot.SID_READ_REQUEST, prot.DID_MODE, None) elif cmd == "state": prot.send(prot.SID_READ_REQUEST, prot.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(prot.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(prot.SID_EXECUTE_REQUEST, t, state) c.close()