def is_paired(ignore_errors=True): """ Determine if this device is actively paired with a web backend Determines if the installation of Mycroft has been paired by the user with the backend system, and if that pairing is still active. Returns: bool: True if paired with backend """ global _paired_cache if _paired_cache: # NOTE: This assumes once paired, the unit remains paired. So # un-pairing must restart the system (or clear this value). # The Mark 1 does perform a restart on RESET. return True try: api = DeviceApi() device = api.get() _paired_cache = api.identity.uuid is not None and \ api.identity.uuid != "" return _paired_cache except HTTPError as e: if e.response.status_code == 401: return False except Exception as e: LOG.warning('Could not get device infO: ' + repr(e)) if ignore_errors: return False if connected(): raise BackendDown raise InternetDown
def check_remote_pairing(ignore_errors): """Check that a basic backend endpoint accepts our pairing. Arguments: ignore_errors (bool): True if errors should be ignored when Returns: True if pairing checks out, otherwise False. """ try: DeviceApi().get() return True except HTTPError as e: if e.response.status_code == 401: return False error = e except Exception as e: error = e LOG.warning('Could not get device info: {}'.format(repr(error))) if ignore_errors: return False if isinstance(error, HTTPError): if connected(): raise BackendDown from error else: raise InternetDown from error else: raise error
def is_paired(ignore_errors=True): """ Determine if this device is actively paired with a web backend Determines if the installation of Mycroft has been paired by the user with the backend system, and if that pairing is still active. Returns: bool: True if paired with backend """ global _paired_cache if _paired_cache: # NOTE: This assumes once paired, the unit remains paired. So # un-pairing must restart the system (or clear this value). # The Mark 1 does perform a restart on RESET. return True try: api = DeviceApi() device = api.get() _paired_cache = api.identity.uuid is not None and \ api.identity.uuid != "" return _paired_cache except HTTPError as e: if e.response.status_code == 401: return False except Exception as e: LOG.warning('Could not get device infO: ' + repr(e)) if ignore_errors: return False if connected(): raise BackendDown raise InternetDown
def upload_skills_data(self, data): """ Upload skills.json file. This file contains a manifest of installed and failed installations for use with the Marketplace. Arguments: data: dictionary with skills data from msm """ if not isinstance(data, dict): raise ValueError('data must be of type dict') _data = deepcopy(data) # Make sure the input data isn't modified # Strip the skills.json down to the bare essentials to_send = {} if 'blacklist' in _data: to_send['blacklist'] = _data['blacklist'] else: LOG.warning('skills manifest lacks blacklist entry') to_send['blacklist'] = [] # Make sure skills doesn't contain duplicates (keep only last) if 'skills' in _data: skills = {s['name']: s for s in _data['skills']} to_send['skills'] = [skills[key] for key in skills] else: LOG.warning('skills manifest lacks skills entry') to_send['skills'] = [] for s in to_send['skills']: # Remove optional fields backend objects to if 'update' in s: s.pop('update') # Finalize skill_gid with uuid if needed s['skill_gid'] = s.get('skill_gid', '').replace( '@|', '@{}|'.format(self.identity.uuid)) self.request({ "method": "PUT", "path": "/" + UUID + "/skillJson", "json": to_send })