def validate_device_update(context):
    """Validate that the non-Pantacor device attributes are updated correctly."""
    device_repo = DeviceRepository(context.db)
    device = device_repo.get_device_by_id(context.device_id)
    assert_that(device.core_version, equal_to("test_core_version"))
    assert_that(device.platform, equal_to("test_platform"))
    assert_that(device.enclosure_version, equal_to("test_enclosure_version"))
Example #2
0
    def _add_device(self, device: NewDeviceRequest):
        """Creates a device and associate it to a pairing session"""
        device_dict = device.to_native()
        geography_id = self._ensure_geography_exists(self.db, device_dict)
        device_dict.update(geography_id=geography_id)
        device_repository = DeviceRepository(self.db)
        device_id = device_repository.add(self.account.id, device_dict)

        return device_id
Example #3
0
    def _run(self):
        device_repo = DeviceRepository(self.db)
        devices_updated = 0
        for device in device_repo.get_all_device_ids():
            last_contact_ts = self._get_ts_from_cache(device.id)
            if last_contact_ts is not None:
                devices_updated += 1
                device_repo.update_last_contact_ts(device.id, last_contact_ts)

        self.log.info(str(devices_updated) + ' devices were active today')
Example #4
0
 def _update_device(self, device_id, updates):
     device_updates = updates.to_native()
     geography_id = self._ensure_geography_exists(self.db, device_updates)
     device_updates.update(geography_id=geography_id)
     device_repository = DeviceRepository(self.db)
     device_repository.update_device_from_account(
         self.account.id,
         device_id,
         device_updates
     )
Example #5
0
    def _get_device(self, device_id: str) -> dict:
        """Get the device information for a specific device.

        :param device_id: Identifier of the device to retrieve
        :return: device information to return to the UI
        """
        device_repository = DeviceRepository(self.db)
        device = device_repository.get_device_by_id(device_id)
        response_data = self._format_device_for_response(device)

        return response_data
def validate_response(context):
    device_id = context.response.data.decode()
    account = context.accounts["foo"]
    db = connect_to_db(context.client_config["DB_CONNECTION_CONFIG"])
    device_repository = DeviceRepository(db)
    device = device_repository.get_device_by_id(device_id)

    assert_that(device, not_none())
    assert_that(device.name, equal_to("Selene Test Device"))
    assert_that(device.placement, equal_to("Mycroft Offices"))
    assert_that(device.account_id, equal_to(account.id))
Example #7
0
    def _get_devices(self):
        device_repository = DeviceRepository(self.db)
        devices = device_repository.get_devices_by_account_id(
            self.account.id
        )
        response_data = []
        for device in devices:
            response_device = self._format_device_for_response(device)
            response_data.append(response_device)

        return response_data
Example #8
0
    def _delete_device(self, device_id: str):
        """Delete the specified device from the database.

        There are other tables related to the device table in the database.  This
        method assumes that the child tables contain "delete cascade" clauses.

        :param device_id: database identifier of a device
        """
        device_repository = DeviceRepository(self.db)
        device_repository.remove(device_id)
        delete_device_login(device_id, self.cache)
def validate_pantacor_update(context):
    """Validate that the Pantacor config of the device is stored in the database."""
    device_repo = DeviceRepository(context.db)
    device = device_repo.get_device_by_id(context.device_id)
    assert_that(device.pantacor_config, not_none())
    assert_that(device.pantacor_config.pantacor_id,
                equal_to("test_pantacor_id"))
    assert_that(device.pantacor_config.release_channel,
                equal_to("test_channel_name"))
    assert_that(device.pantacor_config.auto_update, equal_to(True))
    assert_that(device.pantacor_config.ip_address, equal_to("192.168.1.2"))
    assert_that(device.pantacor_config.ssh_public_key, none())
Example #10
0
    def _add_device(self, device: NewDeviceRequest) -> str:
        """Creates a device and associate it to a pairing session.

        :param device: Schematic containing the request data
        :return: the database identifier of the new device
        """
        device_dict = device.to_native()
        geography_id = self._ensure_geography_exists(device_dict)
        device_dict.update(geography_id=geography_id)
        device_repository = DeviceRepository(self.db)
        device_id = device_repository.add(self.account.id, device_dict)

        return device_id
Example #11
0
    def _get_devices(self) -> List[dict]:
        """Get a list of the devices belonging to the account in the request JWT

        :return: list of devices to be returned to the UI.
        """
        device_repository = DeviceRepository(self.db)
        devices = device_repository.get_devices_by_account_id(self.account.id)
        response_data = []
        for device in devices:
            response_device = self._format_device_for_response(device)
            response_data.append(response_device)

        return response_data
Example #12
0
    def _update_device(self, device_id: str, updates: UpdateDeviceRequest):
        """Update the device attributes on the database based on the request.

        :param device_id: database identifier of a device
        :param updates: The new values of the device attributes
        :return:
        """
        device_updates = updates.to_native()
        geography_id = self._ensure_geography_exists(device_updates)
        device_updates.update(geography_id=geography_id)
        device_repository = DeviceRepository(self.db)
        device_repository.update_device_from_account(self.account.id,
                                                     device_id, device_updates)
Example #13
0
def validate_response(context):
    """Ensure that the database was updated as expected."""
    account = context.accounts["foo"]
    db = connect_to_db(context.client_config["DB_CONNECTION_CONFIG"])
    device_repository = DeviceRepository(db)
    devices = device_repository.get_devices_by_account_id(account.id)
    device = None
    for device in devices:
        if device.name == "Selene Test Device":
            break
    assert_that(device, not_none())
    assert_that(device.name, equal_to("Selene Test Device"))
    assert_that(device.placement, equal_to("Mycroft Offices"))
    assert_that(device.account_id, equal_to(account.id))
    context.device_id = device.id
Example #14
0
def add_device(db, account_id, geography_id):
    device = dict(name='Selene Test Device',
                  pairing_code='ABC123',
                  placement='kitchen',
                  geography_id=geography_id,
                  country='United States',
                  region='Missouri',
                  city='Kansas City',
                  timezone='America/Chicago',
                  wake_word='Selene Test Wake Word',
                  voice='Selene Test Voice')
    device_repository = DeviceRepository(db)
    device_id = device_repository.add(account_id, device)

    return device_id
Example #15
0
 def _activate(self, device_id: str, activation_request: ActivationRequest):
     """Updates the core version, platform and enclosure_version columns"""
     updates = dict(platform=str(activation_request.platform),
                    enclosure_version=str(
                        activation_request.enclosureVersion),
                    core_version=str(activation_request.coreVersion))
     DeviceRepository(self.db).update_device_from_core(device_id, updates)
Example #16
0
 def expire_device_location_etag_by_account_id(self, account_id: str):
     """Expire the locations' etag fpr açç device for a given acccount
     :param account_id: account uuid"""
     db = connect_to_db(self.db_connection_config)
     devices = DeviceRepository(db).get_devices_by_account_id(account_id)
     for device in devices:
         self.expire_device_location_etag_by_device_id(device.id)
Example #17
0
 def expire_device_setting_etag_by_account_id(self, account_id: str):
     """Expire the settings' etags for all devices from a given account. Used when the settings are updated
     at account level"""
     db = connect_to_db(self.db_connection_config)
     devices = DeviceRepository(db).get_devices_by_account_id(account_id)
     for device in devices:
         self.expire_device_setting_etag_by_device_id(device.id)
Example #18
0
def add_device(db, account_id, geography_id):
    device = dict(
        name="Selene Test Device",
        pairing_code="ABC123",
        placement="kitchen",
        geography_id=geography_id,
        country="United States",
        region="Missouri",
        city="Kansas City",
        timezone="America/Chicago",
        wake_word="hey selene",
        voice="Selene Test Voice",
    )
    device_repository = DeviceRepository(db)
    device_id = device_repository.add(account_id, device)

    return device_id
Example #19
0
    def patch(self, device_id):
        self._authenticate(device_id)
        payload = json.loads(self.request.data)
        update_device = UpdateDevice(payload)
        update_device.validate()
        updates = dict(platform=payload.get('platform') or 'unknown',
                       enclosure_version=payload.get('enclosureVersion')
                       or 'unknown',
                       core_version=payload.get('coreVersion') or 'unknown')
        DeviceRepository(self.db).update_device_from_core(device_id, updates)

        return '', HTTPStatus.OK
Example #20
0
    def get(self, device_id):
        self._authenticate(device_id)
        self._validate_etag(device_etag_key(device_id))
        device = DeviceRepository(self.db).get_device_by_id(device_id)

        if device is not None:
            response_data = dict(uuid=device.id,
                                 name=device.name,
                                 description=device.placement,
                                 coreVersion=device.core_version,
                                 enclosureVersion=device.enclosure_version,
                                 platform=device.platform,
                                 user=dict(uuid=device.account_id))
            response = response_data, HTTPStatus.OK

            self._add_etag(device_etag_key(device_id))
        else:
            response = '', HTTPStatus.NO_CONTENT

        return response
Example #21
0
    def _get_device(self, device_id):
        device_repository = DeviceRepository(self.db)
        device = device_repository.get_device_by_id(device_id)
        response_data = self._format_device_for_response(device)

        return response_data
    def device_repository(self):
        """Lazily load an instance of the device repository"""
        if self._device_repository is None:
            self._device_repository = DeviceRepository(self.db)

        return self._device_repository
Example #23
0
 def _delete_device(self, device_id):
     device_repository = DeviceRepository(self.db)
     device_repository.remove(device_id)
     delete_device_login(device_id, self.cache)
Example #24
0
def add_text_to_speech(db):
    voice = _build_voice()
    device_repository = DeviceRepository(db)
    voice.id = device_repository.add_text_to_speech(voice)

    return voice
Example #25
0
 def expire_skill_etag_by_account_id(self, account_id):
     db = connect_to_db(self.db_connection_config)
     devices = DeviceRepository(db).get_devices_by_account_id(account_id)
     for device in devices:
         self.expire_skill_etag_by_device_id(device.id)
Example #26
0
def remove_text_to_speech(db, voice):
    device_repository = DeviceRepository(db)
    device_repository.remove_text_to_speech(voice.id)
Example #27
0
    def device_repository(self):
        """Lazily instantiate the device repository."""
        if self._device_repository is None:
            self._device_repository = DeviceRepository(self.db)

        return self._device_repository
Example #28
0
def add_wake_word(db):
    wake_word = _build_wake_word()
    device_repository = DeviceRepository(db)
    wake_word.id = device_repository.add_wake_word(wake_word)

    return wake_word
Example #29
0
def remove_wake_word(db, wake_word):
    device_repository = DeviceRepository(db)
    device_repository.remove_wake_word(wake_word.id)