|
5 | 5 |
|
6 | 6 | from typing import Any, Generator, List |
7 | 7 |
|
8 | | -from c8y_api.model._base import CumulocityResource, get_all_by_path |
| 8 | +from c8y_api.model._base import CumulocityResource |
| 9 | +from c8y_api.model._parser import as_tuples as parse_as_tuples |
9 | 10 | from c8y_api.model._util import _QueryUtil |
10 | 11 | from c8y_api.model.managedobjects import ManagedObjectUtil, ManagedObject, Device, Availability, DeviceGroup |
11 | 12 |
|
@@ -61,7 +62,7 @@ def get_all( |
61 | 62 | reverse: bool = None, |
62 | 63 | limit: int = None, |
63 | 64 | page_size: int = 1000, |
64 | | - as_tuples: list[str] | dict[str, Any] = None, |
| 65 | + as_tuples: str | tuple | list[str|tuple] = None, |
65 | 66 | **kwargs) -> List[ManagedObject]: |
66 | 67 | """ Query the database for managed objects and return the results |
67 | 68 | as list. |
@@ -156,7 +157,7 @@ def select( |
156 | 157 | limit: int = None, |
157 | 158 | page_size: int = 1000, |
158 | 159 | page_number: int = None, |
159 | | - as_tuples: list[str] | dict[str, Any] = None, |
| 160 | + as_tuples: str | tuple | list[str|tuple] = None, |
160 | 161 | **kwargs) -> Generator[ManagedObject]: |
161 | 162 | """ Query the database for managed objects and iterate over the |
162 | 163 | results. |
@@ -208,10 +209,10 @@ def select( |
208 | 209 | parsed in one chunk). This is a performance related setting. |
209 | 210 | page_number (int): Pull a specific page; this effectively disables |
210 | 211 | automatic follow-up page retrieval. |
211 | | - as_tuples: (list[str] or dict[str, Any]): Don't parse ManagedObjects, |
212 | | - but extract the values at certain JSON paths as tuples; If the path |
213 | | - is not defined in a result, None is used; Specify a dictionary to |
214 | | - define proper default values for each path. |
| 212 | + as_tuples: (*str|tuple): Don't parse objects, but directly extract |
| 213 | + the values at certain JSON paths as tuples; If the path is not |
| 214 | + defined in a result, None is used; Specify a tuple to define |
| 215 | + a proper default value for each path. |
215 | 216 |
|
216 | 217 | Returns: |
217 | 218 | Generator for ManagedObject instances |
@@ -351,7 +352,8 @@ def _select(self, parse_fun, device_mode: bool, page_number, limit, as_tuples, * |
351 | 352 | base_query, |
352 | 353 | page_number, |
353 | 354 | limit, |
354 | | - parse_fun if not as_tuples else (lambda x: get_all_by_path(x, as_tuples))) |
| 355 | + parse_fun if not as_tuples else |
| 356 | + lambda x: parse_as_tuples(x, *([as_tuples] if isinstance(as_tuples, str) else as_tuples))) |
355 | 357 |
|
356 | 358 | def create(self, *objects: ManagedObject): |
357 | 359 | """Create managed objects within the database. |
@@ -501,7 +503,7 @@ def select( # noqa (order) |
501 | 503 | limit: int = None, |
502 | 504 | page_size: int = 100, |
503 | 505 | page_number: int = None, |
504 | | - as_tuples: list[str] | dict[str, Any] = None, |
| 506 | + as_tuples: str | tuple | list[str|tuple] = None, |
505 | 507 | **kwargs,) -> Generator[Device]: |
506 | 508 | # pylint: disable=arguments-differ, arguments-renamed |
507 | 509 | """ Query the database for devices and iterate over the results. |
@@ -556,10 +558,10 @@ def select( # noqa (order) |
556 | 558 | parsed in one chunk). This is a performance related setting. |
557 | 559 | page_number (int): Pull a specific page; this effectively disables |
558 | 560 | automatic follow-up page retrieval. |
559 | | - as_tuples: (list[str] or dict[str, Any]): Don't parse Device objects, |
560 | | - but extract the values at certain JSON paths as tuples; If the path |
561 | | - is not defined in a result, None is used; Specify a dictionary to |
562 | | - define proper default values for each path. |
| 561 | + as_tuples: (*str|tuple): Don't parse objects, but directly extract |
| 562 | + the values at certain JSON paths as tuples; If the path is not |
| 563 | + defined in a result, None is used; Specify a tuple to define |
| 564 | + a proper default value for each path. |
563 | 565 |
|
564 | 566 | Returns: |
565 | 567 | Generator for Device objects |
@@ -614,7 +616,7 @@ def get_all( # noqa (changed signature) |
614 | 616 | limit: int = None, |
615 | 617 | page_size: int = 100, |
616 | 618 | page_number: int = None, |
617 | | - as_tuples: list[str] | dict[str, Any] = None, |
| 619 | + as_tuples: str | tuple | list[str|tuple] = None, |
618 | 620 | **kwargs) -> List[Device]: |
619 | 621 | # pylint: disable=arguments-differ, arguments-renamed |
620 | 622 | """ Query the database for devices and return the results as list. |
@@ -754,7 +756,7 @@ def select( # noqa (changed signature) |
754 | 756 | limit: int = None, |
755 | 757 | page_size: int = 100, |
756 | 758 | page_number: int = None, |
757 | | - as_tuples: list[str] | dict[str, Any] = None, |
| 759 | + as_tuples: str | tuple | list[str|tuple] = None, |
758 | 760 | **kwargs) -> Generator[DeviceGroup]: |
759 | 761 | # pylint: disable=arguments-differ, arguments-renamed |
760 | 762 | """ Select device groups by various parameters. |
@@ -812,11 +814,10 @@ def select( # noqa (changed signature) |
812 | 814 | parsed in one chunk). This is a performance related setting. |
813 | 815 | page_number (int): Pull a specific page; this effectively disables |
814 | 816 | automatic follow-up page retrieval. |
815 | | - as_tuples: (list[str] or dict[str, Any]): Don't parse DeviceGroup |
816 | | - objects, but extract the values at certain JSON paths as |
817 | | - tuples; If the path is not defined in a result, None is used; |
818 | | - Specify a dictionary to define proper default values for each |
819 | | - path. |
| 817 | + as_tuples: (*str|tuple): Don't parse objects, but directly extract |
| 818 | + the values at certain JSON paths as tuples; If the path is not |
| 819 | + defined in a result, None is used; Specify a tuple to define |
| 820 | + a proper default value for each path. |
820 | 821 |
|
821 | 822 | Returns: |
822 | 823 | Generator of DeviceGroup instances |
@@ -923,7 +924,7 @@ def get_all( # noqa (changed signature) |
923 | 924 | limit: int = None, |
924 | 925 | page_size: int = 100, |
925 | 926 | page_number: int = None, |
926 | | - as_tuples: list[str] | dict[str, Any] = None, |
| 927 | + as_tuples: str | tuple | list[str|tuple] = None, |
927 | 928 | **kwargs ) -> List[DeviceGroup]: |
928 | 929 | # pylint: disable=arguments-differ, arguments-renamed |
929 | 930 | """ Select managed objects by various parameters. |
|
0 commit comments