if api_auth is None: print("osio_client_auth: APIAuth not available.", file=sys.stderr) exit(1) if cmd.verbose: print("osio_client_auth: %s" % api_auth, file=sys.stderr) # User manager... user_manager = UserManager(HTTPClient(), api_auth.api_key) # Device manager... device_manager = DeviceManager(HTTPClient(), api_auth.api_key) # check for existing registration... device = device_manager.find_for_name(api_auth.org_id, Host.name()) # check for existing ClientAuth... client_auth = ClientAuth.load(Host) # ---------------------------------------------------------------------------------------------------------------- # remove non-matching record... if device and client_auth: if device.client_id != client_auth.client_id: ClientAuth.delete(Host) client_auth = None # ----------------------------------------------------------------------------------------------------------------
if cmd.verbose: print("aws_mqtt_control: %s" % auth, file=sys.stderr) # responder... handler = AWSMQTTControlHandler() subscriber = MQTTSubscriber(topic, handler.handle) # client... client = MQTTClient(subscriber) if cmd.verbose: print("aws_mqtt_control: %s" % client, file=sys.stderr) sys.stderr.flush() # tag... host_tag = Host.name() # ------------------------------------------------------------------------------------------------------------ # run... client.connect(auth) while True: # cmd... if cmd.interactive: line = StdIO.prompt(device_tag + ' > ') cmd_tokens = line.split() if len(line) > 0 else None else: cmd_tokens = cmd.cmd_tokens
else: for i in range(len(bridges)): print("%d: %s" % ((i + 1), bridges[i])) index = StdIO.prompt("Bridge (1 - %d) ?: " % len(bridges)) bridge = bridges[int(index) - 1] if cmd.verbose: print("join: %s" % bridge, file=sys.stderr) # manager... bridge_manager = BridgeManager(bridge.ip_address, None) # device... client = ClientDescription(ClientDescription.APP, Host.name()) device = DeviceDescription(client) if cmd.verbose: print("join: %s" % device, file=sys.stderr) sys.stderr.flush() # ---------------------------------------------------------------------------------------------------------------- # run... # join... response = None try: response = bridge_manager.register(device)
print("osio_mqtt_control: Topic not available: %s" % cmd.device_topic, file=sys.stderr) exit(1) # responder... handler = OSIOMQTTControlHandler() subscriber = MQTTSubscriber(cmd.device_topic, handler.handle) # client... client = MQTTClient(subscriber) if cmd.verbose: print("osio_mqtt_control: %s" % client, file=sys.stderr) sys.stderr.flush() # tag... tag = Host.name() # ------------------------------------------------------------------------------------------------------------ # run... client.connect(ClientAuth.MQTT_HOST, client_auth.client_id, client_auth.user_id, client_auth.client_password) while True: # cmd... if cmd.interactive: line = StdIO.prompt(cmd.device_tag + ' > ') cmd_tokens = line.split() if len(line) > 0 else None else: cmd_tokens = cmd.cmd_tokens
from scs_core.osio.client.client_auth import ClientAuth from scs_core.osio.config.project_source import ProjectSource from scs_core.osio.manager.device_manager import DeviceManager from scs_core.osio.manager.user_manager import UserManager from scs_core.sys.system_id import SystemID from scs_host.sys.host import Host from scs_philips_hue.cmd.cmd_osio_client_auth import CmdOSIOClientAuth # -------------------------------------------------------------------------------------------------------------------- if __name__ == '__main__': system_id = SystemID('scs', 'phi', 'Hue Interface', 'RPi', Host.name()) description = 'South Coast Science - Philips Hue Bridge' tags = ['scs', 'philips-hue'] # ---------------------------------------------------------------------------------------------------------------- # cmd... cmd = CmdOSIOClientAuth() if cmd.verbose: print("osio_client_auth: %s" % cmd, file=sys.stderr) # ---------------------------------------------------------------------------------------------------------------- # resources...