ul-data-logger-api-sdk 1.3.6__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/PKG-INFO +1 -1
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/data_logger_api_sdk.py +23 -21
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/data_logger_sdk_config.py +2 -2
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/types/api_device_data_history.py +10 -9
- ul-data-logger-api-sdk-2.0.0/pyproject.toml +130 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/setup.py +35 -33
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/ul_data_logger_api_sdk.egg-info/PKG-INFO +1 -1
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/ul_data_logger_api_sdk.egg-info/SOURCES.txt +1 -0
- ul-data-logger-api-sdk-2.0.0/ul_data_logger_api_sdk.egg-info/requires.txt +2 -0
- ul-data-logger-api-sdk-1.3.6/ul_data_logger_api_sdk.egg-info/requires.txt +0 -1
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/README.md +0 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/__init__.py +0 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/py.typed +0 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/types/__init__.py +0 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/types/api_packet_types.py +0 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/types/api_protocol_types.py +0 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/setup.cfg +0 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/ul_data_logger_api_sdk.egg-info/dependency_links.txt +0 -0
- {ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/ul_data_logger_api_sdk.egg-info/top_level.txt +0 -0
|
@@ -2,16 +2,16 @@ import json
|
|
|
2
2
|
import time
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
from functools import lru_cache
|
|
5
|
-
from typing import List, Type
|
|
5
|
+
from typing import List, Type
|
|
6
6
|
|
|
7
7
|
from ul_api_utils.internal_api.internal_api import InternalApi
|
|
8
8
|
from ul_api_utils.internal_api.internal_api_response import TPyloadType
|
|
9
9
|
from ul_api_utils.utils.api_method import ApiMethod
|
|
10
10
|
|
|
11
|
-
from data_logger_api_sdk.
|
|
11
|
+
from data_logger_api_sdk.data_logger_sdk_config import DataLoggerApiSdkConfig
|
|
12
|
+
from data_logger_api_sdk.types.api_device_data_history import ApiDeviceDataHistoryBody, ApiDeviceDataHistoryResponse
|
|
12
13
|
from data_logger_api_sdk.types.api_packet_types import ApiPacketTypesListResponse
|
|
13
14
|
from data_logger_api_sdk.types.api_protocol_types import ApiProtocolTypesListResponse
|
|
14
|
-
from data_logger_api_sdk.data_logger_sdk_config import DataLoggerApiSdkConfig
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class DataLoggerApiSdk:
|
|
@@ -20,45 +20,47 @@ class DataLoggerApiSdk:
|
|
|
20
20
|
self._config = config
|
|
21
21
|
self._api = InternalApi(entry_point=self._config.api_url, default_auth_token=self._config.api_token)
|
|
22
22
|
|
|
23
|
-
@lru_cache(maxsize=None) #
|
|
23
|
+
@lru_cache(maxsize=None) # there should not be leaks memory leaks. flake8 just scared inmemory cache ;)
|
|
24
24
|
def request_payload(
|
|
25
25
|
self,
|
|
26
26
|
_: int,
|
|
27
27
|
method: ApiMethod,
|
|
28
28
|
endpoint: str,
|
|
29
29
|
typed_as: Type[TPyloadType],
|
|
30
|
-
body:
|
|
30
|
+
body: str | None,
|
|
31
31
|
) -> TPyloadType:
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.
|
|
32
|
+
return (
|
|
33
|
+
self._api.request(
|
|
34
|
+
method=method,
|
|
35
|
+
path=endpoint,
|
|
36
|
+
json=json.loads(body) if body is not None else None,
|
|
37
|
+
)
|
|
38
|
+
.typed(typed_as)
|
|
39
|
+
.check()
|
|
39
40
|
.payload
|
|
41
|
+
)
|
|
40
42
|
|
|
41
43
|
def _get_cache_post_payload(
|
|
42
44
|
self,
|
|
43
45
|
method: ApiMethod,
|
|
44
46
|
path: str,
|
|
45
47
|
typed: Type[TPyloadType],
|
|
46
|
-
body:
|
|
48
|
+
body: str | None = None,
|
|
47
49
|
) -> TPyloadType:
|
|
48
50
|
ttl_status = round(time.time() / self._config.cache_ttl_s)
|
|
49
|
-
return self.request_payload(ttl_status, method, path, typed, body)
|
|
51
|
+
return self.request_payload(ttl_status, method, path, typed, body) # type: ignore # Type[TPyloadType] is hashable
|
|
50
52
|
|
|
51
53
|
def get_protocol_types_list(self, mac: int) -> List[str]:
|
|
52
54
|
return self._get_cache_post_payload(
|
|
53
55
|
ApiMethod.GET,
|
|
54
|
-
f
|
|
56
|
+
f"/devices/mac/{mac}/logs/protocol-types",
|
|
55
57
|
ApiProtocolTypesListResponse,
|
|
56
58
|
).protocol_types
|
|
57
59
|
|
|
58
60
|
def get_packet_types_list(self, mac: int) -> List[str]:
|
|
59
61
|
return self._get_cache_post_payload(
|
|
60
62
|
ApiMethod.GET,
|
|
61
|
-
f
|
|
63
|
+
f"/devices/mac/{mac}/logs/packet-types",
|
|
62
64
|
ApiPacketTypesListResponse,
|
|
63
65
|
).packet_types
|
|
64
66
|
|
|
@@ -67,8 +69,8 @@ class DataLoggerApiSdk:
|
|
|
67
69
|
period_from: datetime,
|
|
68
70
|
period_to: datetime,
|
|
69
71
|
mac: int,
|
|
70
|
-
protocol_type:
|
|
71
|
-
packet_type:
|
|
72
|
+
protocol_type: str | None = None,
|
|
73
|
+
packet_type: str | None = None,
|
|
72
74
|
) -> List[ApiDeviceDataHistoryResponse]:
|
|
73
75
|
api_device_history_body = ApiDeviceDataHistoryBody(
|
|
74
76
|
period_from=period_from,
|
|
@@ -76,10 +78,10 @@ class DataLoggerApiSdk:
|
|
|
76
78
|
mac=mac,
|
|
77
79
|
protocol_type=protocol_type,
|
|
78
80
|
packet_type=packet_type,
|
|
79
|
-
).
|
|
81
|
+
).model_dump_json()
|
|
80
82
|
return self._get_cache_post_payload(
|
|
81
83
|
ApiMethod.POST,
|
|
82
|
-
|
|
83
|
-
List[ApiDeviceDataHistoryResponse],
|
|
84
|
+
"/device-data-history",
|
|
85
|
+
List[ApiDeviceDataHistoryResponse], # type: ignore
|
|
84
86
|
api_device_history_body,
|
|
85
87
|
)
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
-
from typing import Optional
|
|
3
2
|
from uuid import UUID
|
|
4
3
|
|
|
5
|
-
from ul_api_utils.api_resource.api_response import JsonApiResponsePayload
|
|
6
4
|
from data_aggregator_sdk.integration_message import IntegrationV0MessageMeta
|
|
7
|
-
from pydantic import BaseModel,
|
|
5
|
+
from pydantic import BaseModel, field_validator
|
|
6
|
+
from ul_api_utils.api_resource.api_response import JsonApiResponsePayload
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
class ApiDeviceDataHistoryBody(BaseModel):
|
|
11
10
|
period_from: datetime
|
|
12
11
|
period_to: datetime
|
|
13
12
|
mac: int
|
|
14
|
-
protocol_type:
|
|
15
|
-
packet_type:
|
|
13
|
+
protocol_type: str | None = None
|
|
14
|
+
packet_type: str | None = None
|
|
16
15
|
|
|
17
|
-
@
|
|
16
|
+
@field_validator("period_from", mode="before")
|
|
17
|
+
@classmethod
|
|
18
18
|
def validate_period_from(cls, value: str | datetime) -> datetime:
|
|
19
19
|
if isinstance(value, str):
|
|
20
20
|
return datetime.combine(datetime.fromisoformat(value), datetime.min.time())
|
|
21
21
|
return value
|
|
22
22
|
|
|
23
|
-
@
|
|
23
|
+
@field_validator("period_to", mode="before")
|
|
24
|
+
@classmethod
|
|
24
25
|
def validate_period_to(cls, value: str | datetime) -> datetime:
|
|
25
26
|
if isinstance(value, str):
|
|
26
27
|
return datetime.combine(datetime.fromisoformat(value), datetime.max.time())
|
|
@@ -29,9 +30,9 @@ class ApiDeviceDataHistoryBody(BaseModel):
|
|
|
29
30
|
|
|
30
31
|
class ApiDeviceDataHistoryResponse(JsonApiResponsePayload):
|
|
31
32
|
mac: int
|
|
32
|
-
|
|
33
|
+
bs_serial_number: int | None = None
|
|
33
34
|
date_created: datetime
|
|
34
|
-
id:
|
|
35
|
+
id: UUID | None = None
|
|
35
36
|
raw_dt: datetime
|
|
36
37
|
raw_payload: str
|
|
37
38
|
raw_message: str
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
[tool.pytest.ini_options]
|
|
2
|
+
addopts = """
|
|
3
|
+
--cov src \
|
|
4
|
+
--no-cov-on-fail \
|
|
5
|
+
--cov-report term-missing \
|
|
6
|
+
--cov-report html:./.tmp/coverage \
|
|
7
|
+
--maxfail=1 \
|
|
8
|
+
--tb=short \
|
|
9
|
+
-vvv \
|
|
10
|
+
-ra \
|
|
11
|
+
-q \
|
|
12
|
+
--showlocals \
|
|
13
|
+
-p pytest_cov"""
|
|
14
|
+
log_cli = true
|
|
15
|
+
cache_dir = "./.tmp/pytest-cache"
|
|
16
|
+
testpaths = [
|
|
17
|
+
"__tests__",
|
|
18
|
+
]
|
|
19
|
+
norecursedirs = [
|
|
20
|
+
".*",
|
|
21
|
+
".git",
|
|
22
|
+
".tmp",
|
|
23
|
+
"srv",
|
|
24
|
+
"node_modules",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.mypy]
|
|
28
|
+
plugins = [
|
|
29
|
+
"sqlmypy",
|
|
30
|
+
"sqlalchemy.ext.mypy.plugin",
|
|
31
|
+
"pydantic.mypy"
|
|
32
|
+
]
|
|
33
|
+
#packages = [
|
|
34
|
+
# "src",
|
|
35
|
+
# "__tests__",
|
|
36
|
+
#]
|
|
37
|
+
exclude = ["migrations"]
|
|
38
|
+
cache_dir = "./.tmp/mypy-cache"
|
|
39
|
+
python_version = "3.10"
|
|
40
|
+
warn_return_any = false
|
|
41
|
+
warn_unused_configs = true
|
|
42
|
+
ignore_missing_imports = false
|
|
43
|
+
follow_imports = "normal"
|
|
44
|
+
namespace_packages = true
|
|
45
|
+
explicit_package_bases = true
|
|
46
|
+
follow_imports_for_stubs = true
|
|
47
|
+
implicit_reexport = true
|
|
48
|
+
allow_untyped_globals = false
|
|
49
|
+
disallow_any_generics = true
|
|
50
|
+
disallow_untyped_defs = true
|
|
51
|
+
disallow_incomplete_defs = true
|
|
52
|
+
check_untyped_defs = true
|
|
53
|
+
disallow_untyped_decorators = false
|
|
54
|
+
no_implicit_optional = true
|
|
55
|
+
strict_optional = true
|
|
56
|
+
warn_unused_ignores = true
|
|
57
|
+
warn_no_return = true
|
|
58
|
+
show_none_errors = true
|
|
59
|
+
ignore_errors = false
|
|
60
|
+
allow_redefinition = false
|
|
61
|
+
strict_equality = true
|
|
62
|
+
show_error_context = false
|
|
63
|
+
show_column_numbers = false
|
|
64
|
+
warn_redundant_casts = true
|
|
65
|
+
warn_unreachable = true
|
|
66
|
+
|
|
67
|
+
[tool.pydantic-mypy]
|
|
68
|
+
init_forbid_extra = true
|
|
69
|
+
init_typed = true
|
|
70
|
+
warn_required_dynamic_aliases = true
|
|
71
|
+
warn_untyped_fields = true
|
|
72
|
+
|
|
73
|
+
[[tool.mypy.overrides]]
|
|
74
|
+
module = [
|
|
75
|
+
"sqlalchemy_serializer",
|
|
76
|
+
"api_utils"
|
|
77
|
+
]
|
|
78
|
+
ignore_missing_imports = true
|
|
79
|
+
|
|
80
|
+
[tool.ruff]
|
|
81
|
+
exclude = ["migrations"]
|
|
82
|
+
line-length = 150
|
|
83
|
+
target-version = "py310"
|
|
84
|
+
cache-dir = "./.tmp/ruff-cache"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
[tool.ruff.lint]
|
|
88
|
+
select = ["ALL"]
|
|
89
|
+
ignore = ["D", "RUF001", "PGH003"]
|
|
90
|
+
extend-ignore = [
|
|
91
|
+
"S311", # Generated data isn't always used for cryptographic purposes
|
|
92
|
+
"N805", # First argument of a method should be named `self` - but pydantic docs use cls
|
|
93
|
+
"TRY003", # Avoid specifying long messages outside the exception class - but pydantic allow to use simple raise error
|
|
94
|
+
"EM101", # Exception must not use a string literal, assign to variable first - duplicate msg? ok
|
|
95
|
+
"S101", # Use of `assert` detected - only way to deal with paranoic mypy
|
|
96
|
+
"PLR0913", # Too many arguments in function definition (6 > 5) - maybe good. wiil be refactored later
|
|
97
|
+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` - sqlalchemy allow to mutations
|
|
98
|
+
"G004", # Logging statement uses f-string - it's OK
|
|
99
|
+
"UP035", # `typing.List` is deprecated, use `list` instead - yes, but `list` broke api-utils @rest_api
|
|
100
|
+
"UP006", # Use `list` instead of `List` for type annotation - yes, but `list` broke api-utils @rest_api
|
|
101
|
+
"ANN401", # Checks that function arguments are annotated with a more specific type than Any
|
|
102
|
+
"ANN101", # This rule is commonly disabled because type checkers can infer this type without annotation. It will be removed in a future release
|
|
103
|
+
"C901", # Checks for functions with a high McCabe complexity
|
|
104
|
+
"ERA001", # Checks for commented-out Python code
|
|
105
|
+
"ANN102", # Checks that class method cls arguments have type annotations
|
|
106
|
+
"PGH004", # Check for noqa annotations that suppress all diagnostics, as opposed to targeting specific diagnostics
|
|
107
|
+
"A002", # Checks for any function arguments that use the same name as a builtin
|
|
108
|
+
"A001", # Checks for variable (and function) assignments that use the same name as a builtin
|
|
109
|
+
"B019", # Checks for uses of the functools.lru_cache and functools.cache decorators on methods
|
|
110
|
+
"PLW0603", # Checks for the use of global statements to update identifiers
|
|
111
|
+
"UP033", # Checks for uses of functools.lru_cache that set maxsize=None
|
|
112
|
+
"FIX002", # Checks for "TODO" comments
|
|
113
|
+
"TD002", # Checks that a TODO comment includes an author
|
|
114
|
+
"TD003", # Checks that a TODO comment is associated with a link to a relevant issue or ticket
|
|
115
|
+
"FBT001", # Checks for the use of boolean positional arguments in function definitions, as determined by the presence of a bool type hint
|
|
116
|
+
"PERF203", # Checks for uses of except handling via try-except within for and while loops
|
|
117
|
+
"A005", # Checks if module shadows a Python standard-library module
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
[tool.ruff.lint.mccabe]
|
|
121
|
+
max-complexity = 4
|
|
122
|
+
|
|
123
|
+
[tool.black]
|
|
124
|
+
target-version = ["py310"]
|
|
125
|
+
exclude = "migrations"
|
|
126
|
+
#include = [
|
|
127
|
+
# "^/src",
|
|
128
|
+
# "^/notification_sdk",
|
|
129
|
+
#]
|
|
130
|
+
check = false
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
from
|
|
3
|
-
from setuptools import setup, find_packages
|
|
2
|
+
from pathlib import Path
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
from setuptools import find_packages, setup
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
HERE = Path(__file__).resolve().parent
|
|
7
|
+
|
|
8
|
+
with Path.open(Path(HERE) / "README.md", encoding="utf-8") as f:
|
|
8
9
|
long_description = f.read()
|
|
9
10
|
|
|
10
11
|
if sys.argv:
|
|
11
|
-
if
|
|
12
|
+
if "broker_sdk" in set(sys.argv):
|
|
12
13
|
sys.argv.remove("broker_sdk")
|
|
13
14
|
setup(
|
|
14
|
-
name=
|
|
15
|
-
version=
|
|
16
|
-
description=
|
|
17
|
-
author=
|
|
15
|
+
name="ul-data-logger-sdk",
|
|
16
|
+
version="3.0.0",
|
|
17
|
+
description="Data logger sdk",
|
|
18
|
+
author="Unic-lab",
|
|
18
19
|
long_description=long_description,
|
|
19
20
|
long_description_content_type="text/markdown",
|
|
20
|
-
packages=find_packages(include=[
|
|
21
|
+
packages=find_packages(include=["data_logger_sdk*"]),
|
|
21
22
|
include_package_data=True,
|
|
22
23
|
package_data={
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
"": ["*.yml", "py.typed"],
|
|
25
|
+
"data_logger_sdk": ["py.typed"],
|
|
25
26
|
},
|
|
26
27
|
license="MIT",
|
|
27
28
|
classifiers=[
|
|
@@ -34,30 +35,30 @@ if sys.argv:
|
|
|
34
35
|
"Programming Language :: Python :: 3.9",
|
|
35
36
|
"Operating System :: OS Independent",
|
|
36
37
|
],
|
|
37
|
-
platforms=
|
|
38
|
+
platforms="any",
|
|
38
39
|
install_requires=[
|
|
39
|
-
"unipipeline>=
|
|
40
|
-
# "ul-data-aggregator-sdk
|
|
41
|
-
# "ul-py-tool==1.
|
|
42
|
-
# "ul-
|
|
43
|
-
# "ul-
|
|
44
|
-
# "ul-data-gateway-sdk==0.
|
|
40
|
+
"ul-unipipeline>=2.0.0",
|
|
41
|
+
# "ul-data-aggregator-sdk>=8.13.2",
|
|
42
|
+
# "ul-py-tool==2.1.2,
|
|
43
|
+
# "ul-api-utils==8.1.6",
|
|
44
|
+
# "ul-db-utils==4.0.2",
|
|
45
|
+
# "ul-data-gateway-sdk==1.0.3",
|
|
45
46
|
],
|
|
46
47
|
)
|
|
47
|
-
elif
|
|
48
|
+
elif "api_sdk" in set(sys.argv):
|
|
48
49
|
sys.argv.remove("api_sdk")
|
|
49
50
|
setup(
|
|
50
|
-
name=
|
|
51
|
-
version=
|
|
52
|
-
description=
|
|
53
|
-
author=
|
|
51
|
+
name="ul-data-logger-api-sdk",
|
|
52
|
+
version="2.0.0",
|
|
53
|
+
description="Data logger API sdk",
|
|
54
|
+
author="Unic-lab",
|
|
54
55
|
long_description=long_description,
|
|
55
56
|
long_description_content_type="text/markdown",
|
|
56
|
-
packages=find_packages(include=[
|
|
57
|
+
packages=find_packages(include=["data_logger_api_sdk*"]),
|
|
57
58
|
include_package_data=True,
|
|
58
59
|
package_data={
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
"": ["*.yml", "py.typed"],
|
|
61
|
+
"data_logger_api_sdk": ["py.typed"],
|
|
61
62
|
},
|
|
62
63
|
license="MIT",
|
|
63
64
|
classifiers=[
|
|
@@ -70,13 +71,14 @@ if sys.argv:
|
|
|
70
71
|
"Programming Language :: Python :: 3.9",
|
|
71
72
|
"Operating System :: OS Independent",
|
|
72
73
|
],
|
|
73
|
-
platforms=
|
|
74
|
+
platforms="any",
|
|
74
75
|
install_requires=[
|
|
75
|
-
"unipipeline>=
|
|
76
|
+
"ul-unipipeline>=2.0.0",
|
|
77
|
+
"tqdm==4.66.1",
|
|
76
78
|
# "ul-data-aggregator-sdk>=8.13.2",
|
|
77
|
-
# "ul-
|
|
78
|
-
# "ul-
|
|
79
|
-
# "ul-
|
|
80
|
-
# "ul-data-gateway-sdk==0.
|
|
79
|
+
# "ul-py-tool==2.1.2,
|
|
80
|
+
# "ul-api-utils==8.1.6",
|
|
81
|
+
# "ul-db-utils==4.0.2",
|
|
82
|
+
# "ul-data-gateway-sdk==1.0.3",
|
|
81
83
|
],
|
|
82
84
|
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
unipipeline>=1.4.5
|
|
File without changes
|
{ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{ul-data-logger-api-sdk-1.3.6 → ul-data-logger-api-sdk-2.0.0}/data_logger_api_sdk/types/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|