diff --git a/backend/shared/device/__init__.py b/backend/shared/device/__init__.py index 5d0704a3..33d10c67 100644 --- a/backend/shared/device/__init__.py +++ b/backend/shared/device/__init__.py @@ -1,2 +1,2 @@ from .device import get_device_by_id -from .device import get_devices_by_account_id \ No newline at end of file +from .device import get_devices_by_account_id diff --git a/backend/shared/device/device.py b/backend/shared/device/device.py index 90798c40..4c13d776 100644 --- a/backend/shared/device/device.py +++ b/backend/shared/device/device.py @@ -27,7 +27,7 @@ def get_device_by_id(db, device_id: str) -> Device: :param db: psycopg2 connection to mycroft database :param device_id: uuid - :return: + :return: Device entity """ query = DatabaseQuery( file_path=path.join(SQL_DIR, 'get_device_by_id.sql'), @@ -43,7 +43,7 @@ def get_devices_by_account_id(db, account_id: str) -> list[Device]: :param db: psycopg2 connection to mycroft database :param account_id: uuid - :return: + :return: List of User's devices """ query = DatabaseQuery( file_path=path.join(SQL_DIR, 'get_devices_by_account_id.sql'), @@ -51,4 +51,4 @@ def get_devices_by_account_id(db, account_id: str) -> list[Device]: singleton=False ) sql_results = fetch(db, query) - return list(map(lambda result: Device(**result), sql_results)) + return [Device(**result) for result in sql_results] diff --git a/backend/shared/device/sql/get_device_by_id.sql b/backend/shared/device/sql/get_device_by_id.sql index c9be71f1..8136dc75 100644 --- a/backend/shared/device/sql/get_device_by_id.sql +++ b/backend/shared/device/sql/get_device_by_id.sql @@ -1 +1 @@ -SELECT * FROM device.device WHERE id = %(device_id)s \ No newline at end of file +SELECT * FROM device.device WHERE id = %(device_id)s diff --git a/backend/shared/device/sql/get_devices_by_account_id.sql b/backend/shared/device/sql/get_devices_by_account_id.sql index 4b80c59c..fe5e0e2c 100644 --- a/backend/shared/device/sql/get_devices_by_account_id.sql +++ b/backend/shared/device/sql/get_devices_by_account_id.sql @@ -1 +1 @@ -SELECT * FROM device.device WHERE account_id = %(account_id)s \ No newline at end of file +SELECT * FROM device.device WHERE account_id = %(account_id)s diff --git a/backend/shared/skill/__init__.py b/backend/shared/skill/__init__.py index c6949997..53b8bde6 100644 --- a/backend/shared/skill/__init__.py +++ b/backend/shared/skill/__init__.py @@ -1,3 +1 @@ -from .skill import get_setting_sections_by_device_id_and_setting_version -from .skill import get_setting_by_section_id from .skill import get_setting_by_device_id_and_setting_version_hash diff --git a/backend/shared/skill/skill.py b/backend/shared/skill/skill.py index 49a3e84e..e8a9b686 100644 --- a/backend/shared/skill/skill.py +++ b/backend/shared/skill/skill.py @@ -34,22 +34,13 @@ class SettingSection(object): settings: list = None -@dataclass -class SkillSetting(object): - """Representation of the link between a device and a skill setting """ - id: str - device_skill_id: str - setting_id: str - value: str = None - - def get_setting_sections_by_device_id_and_setting_version(db, device_id, setting_version_hash): """ Fetch all sections of a skill for a given device and setting version :param db: psycopg2 connection to the mycroft database :param device_id: uuid :param setting_version_hash: version_hash for a given skill setting - :return: + :return: list of sections for a given skill """ query = DatabaseQuery( file_path=path.join(SQL_DIR, 'get_setting_sections_by_device_id_and_setting_version.sql'), @@ -57,15 +48,15 @@ def get_setting_sections_by_device_id_and_setting_version(db, device_id, setting singleton=False ) sql_results = fetch(db, query) - return list(map(lambda result: SettingSection(**result), sql_results)) + return [SettingSection(**result) for result in sql_results] def get_setting_by_section_id(db, setting_section_ids): - """ Fetch all settings for a given list of section ids + """ Fetch all settings whose id is in a given list of section ids :param db: psycopg2 connection to the mycroft database :param setting_section_ids: list of section ids - :return: + :return: list of settings """ query = DatabaseQuery( file_path=path.join(SQL_DIR, 'get_setting_by_section_ids.sql'), @@ -73,7 +64,7 @@ def get_setting_by_section_id(db, setting_section_ids): singleton=False ) sql_results = fetch(db, query) - return list(map(lambda result: Setting(**result), sql_results)) + return [Setting(**result) for result in sql_results] def get_skill_settings_by_device_id_and_version_hash(db, device_id, setting_version_hash): @@ -82,7 +73,7 @@ def get_skill_settings_by_device_id_and_version_hash(db, device_id, setting_vers :param db: psycopg2 connection to the mycroft database :param device_id: uuid :param setting_version_hash: - :return: + :return: list of tuples (setting_id, setting_value) """ query = DatabaseQuery( file_path=path.join(SQL_DIR, 'get_skill_setting_by_device_id_and_version_hash.sql'), @@ -90,7 +81,7 @@ def get_skill_settings_by_device_id_and_version_hash(db, device_id, setting_vers singleton=False ) sql_results = fetch(db, query) - return list(map(lambda result: SkillSetting(**result), sql_results)) + return [(result['setting_id'], result['value']) for result in sql_results] def get_setting_by_device_id_and_setting_version_hash(db, device_id, setting_version_hash): @@ -98,7 +89,7 @@ def get_setting_by_device_id_and_setting_version_hash(db, device_id, setting_ver :param db: psycopg2 connection to the mycroft database :param device_id: uuid :param setting_version_hash: - :return: + :return: list of sections, each section filled with its settings """ sections = get_setting_sections_by_device_id_and_setting_version(db, device_id, setting_version_hash) setting_sections_ids = tuple(map(lambda s: s.id, sections)) @@ -106,13 +97,13 @@ def get_setting_by_device_id_and_setting_version_hash(db, device_id, setting_ver skill_settings = get_skill_settings_by_device_id_and_version_hash(db, device_id, setting_version_hash) # Fills each setting with the correspondent value from the skill setting - for skill_setting in skill_settings: - s = next(filter(lambda setting: setting.id == skill_setting.setting_id, settings), None) + for setting_id, setting_value in skill_settings: + s = next(filter(lambda setting: setting.id == setting_id, settings), None) if s: - s.value = skill_setting.value + s.value = setting_value # Fills each setting with its list of settings for section in sections: - section.settings = list(filter(lambda setting: setting.setting_section_id == section.id, settings)) + section.settings = [setting for setting in settings if setting.setting_section_id == section.id] return sections