karen.DeviceContainer

Karen's Client Device Manager.

The sole purpose of the device container is to facilitate communication between one or more input/output devices and the brain. The device container allows for multiple client devices to be attached to a single communication vehicle. This minimizes the overhead on the device to send its collected content to the brain.

__init__(self, tcp_port=8081, hostname='localhost', ssl_cert_file=None, ssl_key_file=None, brain_url='http://localhost:8080') special

Device Container Initialization

Parameters:
  • tcp_port (int) – The TCP port on which the brain's TCP server will listen for incoming connections

  • hostname (str) – The network hostname or IP address for the TCP server daemon

  • ssl_cert_file (str) – The path and file name of the SSL certificate (.crt) for secure communications

  • ssl_key_file (str) – The path and file name of the SSL private key (.key or .pem) for secure communications

  • brain_url (str) – The URL of the brain device.

Both the ssl_cert_file and ssl_key_file must be present in order for SSL to be leveraged.

addDevice(self, deviceType, obj, friendlyName=None, autoStart=True, autoRegister=True)

Adds a new input/output device and optionally starts it and registers it with the brain.

Parameters:
  • deviceType (str) – The type of the device being added (e.g. "karen.listener.Listener").

  • obj (object) – The instantiated class object of the input/output device.

  • friendlyName (str) – The friendly name of the device (e.g. "living room").

  • autoStart (bool) – Indicates if this call should call the start() method on input/output device.

  • autoRegister (bool) – Indicates if the client should automatically register with the brain

Returns:
  • (bool) – True on success else will raise an exception.

callbackHandler(self, inType, data)

The target of all input/output devices. Sends collected data to the brain. Posts request to "/data".

Parameters:
  • inType (str) – The type of data collected (e.g. "AUDIO_INPUT").

  • data (object) – The object to be converted to JSON and sent to the brain in the body of the message.

Returns:
  • (bool) – True on success or False on failure.

setHandler(self, handlerType, handlerCallback)

Sets the handler to be used for incoming control requests

Parameters:
  • handlerType (str) – The type of incoming control request to handle (e.g. "KILL").

  • handlerCallback (function) – The function to call when the control request matches the handler type

Returns:
  • (bool) – True on success else will raise an exception.

start(self, useThreads=True, autoRegister=True, autoStartDevices=False)

Starts the client TCP daemon, optionally using threads.

Parameters:
  • useThreads (bool) – Indicates if the brain should be started on a new thread.

  • autoRegister (bool) – Indicates if the client should automatically register with the brain

  • autoStartDevices (bool) – Indicates if this call should also start any stopped or not started input/output devices.

Returns:
  • (bool) – True on success else will raise an exception.

stop(self)

Stops the client TCP server daemon.

Returns:
  • (bool) – True on success else will raise an exception.

stopDevices(self, deviceType=None, removeDevices=False)

Stops all connected input/output devices.

Parameters:
  • deviceType (str) – The type of device to stop (e.g. "karen.listener.Listener"). (optional)

  • removeDevices (bool) – Indicates if the devices should be removed once stopped. (optional)

Returns:
  • (bool) – True on success else will raise an exception.

wait(self, seconds=0)

Waits for any active servers to complete before closing

Parameters:
  • seconds (int) – Number of seconds to wait before calling the "stop()" function

Returns:
  • (bool) – True on success else will raise an exception.