Ejemplo n.º 1
0
    def setup(self):
        must_upload = self.config.get('must_upload')
        if must_upload is not None and str2bool(must_upload):
            ConfigurationManager.set('enclosure', 'must_upload', False)
            time.sleep(5)
            self.client.emit(
                Message("speak",
                        metadata={
                            'utterance':
                            "I am currently uploading to the arduino."
                        }))
            self.client.emit(
                Message("speak",
                        metadata={
                            'utterance': "I will be finished in just a moment."
                        }))
            self.upload_hex()
            self.client.emit(
                Message("speak",
                        metadata={'utterance':
                                  "Arduino programing complete."}))

        must_start_test = self.config.get('must_start_test')
        if must_start_test is not None and str2bool(must_start_test):
            ConfigurationManager.set('enclosure', 'must_start_test', False)
            time.sleep(0.5)  # Ensure arduino has booted
            self.client.emit(
                Message("speak",
                        metadata={'utterance':
                                  "Begining hardware self test."}))
            self.writer.write("test.begin")
Ejemplo n.º 2
0
    def setup(self):
        must_upload = self.config.get('must_upload')
        if must_upload is not None and str2bool(must_upload):
            ConfigurationManager.set('enclosure', 'must_upload', False)
            self.upload_hex()

        must_start_test = self.config.get('must_start_test')
        if must_start_test is not None and str2bool(must_start_test):
            ConfigurationManager.set('enclosure', 'must_start_test', False)
            time.sleep(0.5)  # Ensure arduino has booted
            self.writer.write("test.begin")
Ejemplo n.º 3
0
    def update(self):
        config = self.config_manager.get_config()
        remote_config_url = config.get("remote_configuration").get("url")
        enabled = str2bool(
            config.get("remote_configuration").get("enabled", "False"))
        if enabled and self.identity.token:
            auth_header = "Bearer %s:%s" % (self.identity.device_id,
                                            self.identity.token)
            try:
                response = requests.get(remote_config_url,
                                        headers={"Authorization": auth_header})
                user = response.json()
                for attribute in user["attributes"]:
                    attribute_name = attribute.get("attribute_name")
                    core_config_name = self.remote_config_mapping.get(
                        attribute_name)
                    if core_config_name:
                        config["core"][core_config_name] = str(
                            attribute.get("attribute_value"))
                        logger.info(
                            "Accepting remote configuration: core[%s] == %s" %
                            (core_config_name, attribute["attribute_value"]))
            except Exception as e:
                logger.error("Failed to fetch remote configuration: %s" %
                             repr(e))

        else:
            logger.debug(
                "Device not paired, cannot retrieve remote configuration.")
Ejemplo n.º 4
0
    def setup(self):
        must_upload = self.config.get('must_upload')
        if must_upload is not None and str2bool(must_upload):
            ConfigurationManager.set('enclosure', 'must_upload', False)
            time.sleep(5)
            self.client.emit(Message("speak", metadata={
                'utterance': "I am currently uploading to the arduino."}))
            self.client.emit(Message("speak", metadata={
                'utterance': "I will be finished in just a moment."}))
            self.upload_hex()

        must_start_test = self.config.get('must_start_test')
        if must_start_test is not None and str2bool(must_start_test):
            ConfigurationManager.set('enclosure', 'must_start_test', False)
            time.sleep(0.5)  # Ensure arduino has booted
            self.writer.write("test.begin")
Ejemplo n.º 5
0
    def update(self):
        config = self.config_manager.get_config()
        remote_config_url = config.get("remote_configuration").get("url")
        enabled = str2bool(
            config.get("remote_configuration").get("enabled", "False"))
        if enabled and self.identity.token:
            auth_header = "Bearer %s:%s" % (
                self.identity.device_id, self.identity.token)
            try:
                response = requests.get(
                    remote_config_url, headers={"Authorization": auth_header})
                user = response.json()
                for attribute in user["attributes"]:
                    attribute_name = attribute.get("attribute_name")
                    core_config_name = self.remote_config_mapping.get(
                        attribute_name)
                    if core_config_name:
                        config["core"][core_config_name] = str(
                            attribute.get("attribute_value"))
                        logger.info(
                            "Accepting remote configuration: core[%s] == %s" %
                            (core_config_name, attribute["attribute_value"]))
            except Exception as e:
                logger.error(
                    "Failed to fetch remote configuration: %s" % repr(e))

        else:
            logger.debug(
                "Device not paired, cannot retrieve remote configuration.")
Ejemplo n.º 6
0
 def __init__(self, config=_config, pairing_code=None):
     self.config = config
     self.ws_client = WebsocketClient(host=config.get("host"),
                                      port=config.get("port"),
                                      path=config.get("route"),
                                      ssl=str2bool(config.get("ssl")))
     self.identity_manager = IdentityManager()
     self.identity = self.identity_manager.identity
     self.pairing_code = pairing_code if pairing_code else generate_pairing_code()
Ejemplo n.º 7
0
 def __init__(self, host=client_config.get("host"),
              port=client_config.get("port"),
              path=client_config.get("route"),
              ssl=str2bool(client_config.get("ssl"))):
     self.emitter = EventEmitter()
     self.scheme = "wss" if ssl else "ws"
     self.host = host
     self.port = port
     self.path = path
     self.exp_backoff_counter = 1
     self.client = self._create_new_connection()
     self.pool = ThreadPool(10)
Ejemplo n.º 8
0
 def __init__(self, host=client_config.get("host"),
              port=client_config.get("port"),
              path=client_config.get("route"),
              ssl=str2bool(client_config.get("ssl"))):
     self.emitter = EventEmitter()
     self.scheme = "wss" if ssl else "ws"
     self.host = host
     self.port = port
     self.path = path
     self.exp_backoff_counter = 1
     self.client = self._create_new_connection()
     self.pool = ThreadPool(10)
Ejemplo n.º 9
0
    def load(config=None):
        RemoteConfiguration.validate_config(config)

        identity = IdentityManager().get()
        config_remote = config.get("remote_configuration", {})
        enabled = str2bool(config_remote.get("enabled", "False"))

        if enabled and identity.token:
            url = config_remote.get("url")
            auth_header = "Bearer %s:%s" % (identity.device_id, identity.token)
            try:
                response = requests.get(url,
                                        headers={"Authorization": auth_header})
                user = response.json()
                RemoteConfiguration.__load_attributes(config, user)
            except Exception as e:
                logger.error(
                    "Failed to fetch remote configuration: %s" % repr(e))
        else:
            logger.debug(
                "Device not paired, cannot retrieve remote configuration.")
        return config
Ejemplo n.º 10
0
    def load(config=None):
        RemoteConfiguration.validate_config(config)

        identity = IdentityManager().get()
        config_remote = config.get("remote_configuration", {})
        enabled = str2bool(config_remote.get("enabled", "False"))

        if enabled and identity.token:
            url = config_remote.get("url")
            auth_header = "Bearer %s:%s" % (identity.device_id, identity.token)
            try:
                response = requests.get(url,
                                        headers={"Authorization": auth_header})
                user = response.json()
                RemoteConfiguration.__load_attributes(config, user)
            except Exception as e:
                logger.error("Failed to fetch remote configuration: %s" %
                             repr(e))
        else:
            logger.debug(
                "Device not paired, cannot retrieve remote configuration.")
        return config
Ejemplo n.º 11
0
 def first_setup(self):
     if str2bool(self.config.get('setup')):
         self.start()
Ejemplo n.º 12
0
 def __init__(self,
              url=config.get("url"),
              enabled=str2bool(config.get("enabled"))):
     self.url = url
     self.enabled = enabled
Ejemplo n.º 13
0
 def __init__(self,
              url=config.get("url"),
              enabled=str2bool(config.get("enabled"))):
     self.url = url
     self.enabled = enabled