frequenz-client-microgrid 0.8.0__tar.gz → 0.9.1__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.
- {frequenz_client_microgrid-0.8.0/src/frequenz_client_microgrid.egg-info → frequenz_client_microgrid-0.9.1}/PKG-INFO +23 -23
- frequenz_client_microgrid-0.9.1/RELEASE_NOTES.md +32 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/pyproject.toml +33 -25
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_client.py +3 -1
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_component.py +1 -2
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_component_data.py +1 -1
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_connection.py +1 -1
- frequenz_client_microgrid-0.9.1/src/frequenz/client/microgrid/_metadata.py +34 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_sensor_proto.py +1 -1
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/sensor.py +1 -1
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1/src/frequenz_client_microgrid.egg-info}/PKG-INFO +23 -23
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz_client_microgrid.egg-info/SOURCES.txt +0 -1
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz_client_microgrid.egg-info/requires.txt +22 -22
- frequenz_client_microgrid-0.8.0/RELEASE_NOTES.md +0 -18
- frequenz_client_microgrid-0.8.0/src/frequenz/client/microgrid/_metadata.py +0 -54
- frequenz_client_microgrid-0.8.0/src/frequenz/client/microgrid/id.py +0 -218
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/LICENSE +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/MANIFEST.in +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/README.md +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/setup.cfg +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/__init__.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_component_error.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_component_states.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_constants.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_exception.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_lifetime.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/_util.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/conftest.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/metrics.py +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz/client/microgrid/py.typed +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz_client_microgrid.egg-info/dependency_links.txt +0 -0
- {frequenz_client_microgrid-0.8.0 → frequenz_client_microgrid-0.9.1}/src/frequenz_client_microgrid.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: frequenz-client-microgrid
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: Microgrid API client for Python
|
|
5
5
|
Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
|
|
6
6
|
License: MIT
|
|
@@ -21,15 +21,15 @@ Classifier: Typing :: Typed
|
|
|
21
21
|
Requires-Python: <4,>=3.11
|
|
22
22
|
Description-Content-Type: text/markdown
|
|
23
23
|
License-File: LICENSE
|
|
24
|
-
Requires-Dist: frequenz-api-microgrid<0.16.0,>=0.15.
|
|
24
|
+
Requires-Dist: frequenz-api-microgrid<0.16.0,>=0.15.5
|
|
25
25
|
Requires-Dist: frequenz-channels<2.0.0,>=1.0.0-rc1
|
|
26
|
-
Requires-Dist: frequenz-client-base<0.
|
|
27
|
-
Requires-Dist:
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist: typing-extensions<5,>=4.
|
|
26
|
+
Requires-Dist: frequenz-client-base<0.12.0,>=0.8.0
|
|
27
|
+
Requires-Dist: frequenz-client-common<0.4.0,>=0.3.2
|
|
28
|
+
Requires-Dist: grpcio<2,>=1.63.0
|
|
29
|
+
Requires-Dist: protobuf<7,>=5.26.1
|
|
30
|
+
Requires-Dist: typing-extensions<5,>=4.13.0
|
|
31
31
|
Provides-Extra: dev-flake8
|
|
32
|
-
Requires-Dist: flake8==7.
|
|
32
|
+
Requires-Dist: flake8==7.3.0; extra == "dev-flake8"
|
|
33
33
|
Requires-Dist: flake8-docstrings==1.7.0; extra == "dev-flake8"
|
|
34
34
|
Requires-Dist: flake8-pyproject==1.2.3; extra == "dev-flake8"
|
|
35
35
|
Requires-Dist: pydoclint==0.6.6; extra == "dev-flake8"
|
|
@@ -39,33 +39,33 @@ Requires-Dist: black==25.1.0; extra == "dev-formatting"
|
|
|
39
39
|
Requires-Dist: isort==6.0.1; extra == "dev-formatting"
|
|
40
40
|
Provides-Extra: dev-mkdocs
|
|
41
41
|
Requires-Dist: black==25.1.0; extra == "dev-mkdocs"
|
|
42
|
-
Requires-Dist: Markdown==3.8; extra == "dev-mkdocs"
|
|
42
|
+
Requires-Dist: Markdown==3.8.2; extra == "dev-mkdocs"
|
|
43
43
|
Requires-Dist: mike==2.1.3; extra == "dev-mkdocs"
|
|
44
44
|
Requires-Dist: mkdocs-gen-files==0.5.0; extra == "dev-mkdocs"
|
|
45
45
|
Requires-Dist: mkdocs-literate-nav==0.6.2; extra == "dev-mkdocs"
|
|
46
46
|
Requires-Dist: mkdocs-macros-plugin==1.3.7; extra == "dev-mkdocs"
|
|
47
|
-
Requires-Dist: mkdocs-material==9.6.
|
|
48
|
-
Requires-Dist: mkdocstrings[python]==0.
|
|
49
|
-
Requires-Dist: mkdocstrings-python==1.16.
|
|
50
|
-
Requires-Dist: frequenz-repo-config[lib]==0.13.
|
|
47
|
+
Requires-Dist: mkdocs-material==9.6.16; extra == "dev-mkdocs"
|
|
48
|
+
Requires-Dist: mkdocstrings[python]==0.30.0; extra == "dev-mkdocs"
|
|
49
|
+
Requires-Dist: mkdocstrings-python==1.16.12; extra == "dev-mkdocs"
|
|
50
|
+
Requires-Dist: frequenz-repo-config[lib]==0.13.5; extra == "dev-mkdocs"
|
|
51
51
|
Provides-Extra: dev-mypy
|
|
52
|
-
Requires-Dist: mypy==1.
|
|
52
|
+
Requires-Dist: mypy==1.17.1; extra == "dev-mypy"
|
|
53
53
|
Requires-Dist: grpc-stubs==1.53.0.6; extra == "dev-mypy"
|
|
54
|
-
Requires-Dist: types-Markdown==3.8.0.
|
|
55
|
-
Requires-Dist: types-protobuf==
|
|
54
|
+
Requires-Dist: types-Markdown==3.8.0.20250708; extra == "dev-mypy"
|
|
55
|
+
Requires-Dist: types-protobuf==6.30.2.20250703; extra == "dev-mypy"
|
|
56
56
|
Requires-Dist: frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-mypy"
|
|
57
57
|
Provides-Extra: dev-noxfile
|
|
58
58
|
Requires-Dist: nox==2025.5.1; extra == "dev-noxfile"
|
|
59
|
-
Requires-Dist: frequenz-repo-config[lib]==0.13.
|
|
59
|
+
Requires-Dist: frequenz-repo-config[lib]==0.13.5; extra == "dev-noxfile"
|
|
60
60
|
Provides-Extra: dev-pylint
|
|
61
|
-
Requires-Dist: pylint==3.3.
|
|
61
|
+
Requires-Dist: pylint==3.3.7; extra == "dev-pylint"
|
|
62
62
|
Requires-Dist: frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-pylint"
|
|
63
63
|
Provides-Extra: dev-pytest
|
|
64
|
-
Requires-Dist: pytest==8.
|
|
65
|
-
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.13.
|
|
66
|
-
Requires-Dist: pytest-mock==3.14.
|
|
67
|
-
Requires-Dist: pytest-asyncio==
|
|
68
|
-
Requires-Dist: async-solipsism==0.
|
|
64
|
+
Requires-Dist: pytest==8.4.1; extra == "dev-pytest"
|
|
65
|
+
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.13.5; extra == "dev-pytest"
|
|
66
|
+
Requires-Dist: pytest-mock==3.14.1; extra == "dev-pytest"
|
|
67
|
+
Requires-Dist: pytest-asyncio==1.1.0; extra == "dev-pytest"
|
|
68
|
+
Requires-Dist: async-solipsism==0.8; extra == "dev-pytest"
|
|
69
69
|
Provides-Extra: dev
|
|
70
70
|
Requires-Dist: frequenz-client-microgrid[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]; extra == "dev"
|
|
71
71
|
Dynamic: license-file
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Frequenz Microgrid API Client Release Notes
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
This release removes the `timezonefinder` dependency to significantly reduce package size by 66M+ and enable ARM platform support.
|
|
6
|
+
|
|
7
|
+
> [!WARNING]
|
|
8
|
+
> This is a **breaking change** shipped in a patch release because this feature has no known users.
|
|
9
|
+
|
|
10
|
+
## Upgrading
|
|
11
|
+
|
|
12
|
+
The `Location.timezone` field no longer performs automatic timezone lookup from latitude/longitude coordinates.
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
# Automatic timezone lookup (no longer works)
|
|
16
|
+
location = Location(latitude=52.52, longitude=13.405)
|
|
17
|
+
print(location.timezone) # Previously: ZoneInfo('Europe/Berlin'), now None
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If you need timezone lookup from coordinates, install [`timezonefinder`](https://pypi.org/project/timezonefinder/) separately and implement manual lookup:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
# Install: pip install timezonefinder
|
|
24
|
+
from timezonefinder import TimezoneFinder
|
|
25
|
+
from zoneinfo import ZoneInfo
|
|
26
|
+
from frequenz.client.microgrid import Location
|
|
27
|
+
|
|
28
|
+
tf = TimezoneFinder()
|
|
29
|
+
tz_name = tf.timezone_at(lat=52.52, lng=13.405)
|
|
30
|
+
timezone = ZoneInfo(tz_name) if tz_name else None
|
|
31
|
+
location = Location(latitude=52.52, longitude=13.405, timezone=timezone)
|
|
32
|
+
```
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
[build-system]
|
|
5
5
|
requires = [
|
|
6
|
-
"setuptools == 80.
|
|
6
|
+
"setuptools == 80.9.0",
|
|
7
7
|
"setuptools_scm[toml] == 8.3.1",
|
|
8
|
-
"frequenz-repo-config[lib] == 0.13.
|
|
8
|
+
"frequenz-repo-config[lib] == 0.13.5",
|
|
9
9
|
]
|
|
10
10
|
build-backend = "setuptools.build_meta"
|
|
11
11
|
|
|
@@ -36,13 +36,13 @@ classifiers = [
|
|
|
36
36
|
]
|
|
37
37
|
requires-python = ">= 3.11, < 4"
|
|
38
38
|
dependencies = [
|
|
39
|
-
"frequenz-api-microgrid >= 0.15.
|
|
39
|
+
"frequenz-api-microgrid >= 0.15.5, < 0.16.0",
|
|
40
40
|
"frequenz-channels >= 1.0.0-rc1, < 2.0.0",
|
|
41
|
-
"frequenz-client-base >= 0.8.0, < 0.
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"typing-extensions >= 4.
|
|
41
|
+
"frequenz-client-base >= 0.8.0, < 0.12.0",
|
|
42
|
+
"frequenz-client-common >= 0.3.2, < 0.4.0",
|
|
43
|
+
"grpcio >= 1.63.0, < 2",
|
|
44
|
+
"protobuf >= 5.26.1, < 7",
|
|
45
|
+
"typing-extensions >= 4.13.0, < 5",
|
|
46
46
|
]
|
|
47
47
|
dynamic = ["version"]
|
|
48
48
|
|
|
@@ -52,7 +52,7 @@ email = "floss@frequenz.com"
|
|
|
52
52
|
|
|
53
53
|
[project.optional-dependencies]
|
|
54
54
|
dev-flake8 = [
|
|
55
|
-
"flake8 == 7.
|
|
55
|
+
"flake8 == 7.3.0",
|
|
56
56
|
"flake8-docstrings == 1.7.0",
|
|
57
57
|
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
|
|
58
58
|
"pydoclint == 0.6.6",
|
|
@@ -61,36 +61,36 @@ dev-flake8 = [
|
|
|
61
61
|
dev-formatting = ["black == 25.1.0", "isort == 6.0.1"]
|
|
62
62
|
dev-mkdocs = [
|
|
63
63
|
"black == 25.1.0",
|
|
64
|
-
"Markdown==3.8",
|
|
64
|
+
"Markdown==3.8.2",
|
|
65
65
|
"mike == 2.1.3",
|
|
66
66
|
"mkdocs-gen-files == 0.5.0",
|
|
67
67
|
"mkdocs-literate-nav == 0.6.2",
|
|
68
68
|
"mkdocs-macros-plugin == 1.3.7",
|
|
69
|
-
"mkdocs-material == 9.6.
|
|
70
|
-
"mkdocstrings[python] == 0.
|
|
71
|
-
"mkdocstrings-python == 1.16.
|
|
72
|
-
"frequenz-repo-config[lib] == 0.13.
|
|
69
|
+
"mkdocs-material == 9.6.16",
|
|
70
|
+
"mkdocstrings[python] == 0.30.0",
|
|
71
|
+
"mkdocstrings-python == 1.16.12",
|
|
72
|
+
"frequenz-repo-config[lib] == 0.13.5",
|
|
73
73
|
]
|
|
74
74
|
dev-mypy = [
|
|
75
|
-
"mypy == 1.
|
|
75
|
+
"mypy == 1.17.1",
|
|
76
76
|
"grpc-stubs == 1.53.0.6",
|
|
77
|
-
"types-Markdown == 3.8.0.
|
|
78
|
-
"types-protobuf ==
|
|
77
|
+
"types-Markdown == 3.8.0.20250708",
|
|
78
|
+
"types-protobuf == 6.30.2.20250703",
|
|
79
79
|
# For checking the noxfile, docs/ script, and tests
|
|
80
80
|
"frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]",
|
|
81
81
|
]
|
|
82
|
-
dev-noxfile = ["nox == 2025.5.1", "frequenz-repo-config[lib] == 0.13.
|
|
82
|
+
dev-noxfile = ["nox == 2025.5.1", "frequenz-repo-config[lib] == 0.13.5"]
|
|
83
83
|
dev-pylint = [
|
|
84
|
-
"pylint == 3.3.
|
|
84
|
+
"pylint == 3.3.7",
|
|
85
85
|
# For checking the noxfile, docs/ script, and tests
|
|
86
86
|
"frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]",
|
|
87
87
|
]
|
|
88
88
|
dev-pytest = [
|
|
89
|
-
"pytest == 8.
|
|
90
|
-
"frequenz-repo-config[extra-lint-examples] == 0.13.
|
|
91
|
-
"pytest-mock == 3.14.
|
|
92
|
-
"pytest-asyncio ==
|
|
93
|
-
"async-solipsism == 0.
|
|
89
|
+
"pytest == 8.4.1",
|
|
90
|
+
"frequenz-repo-config[extra-lint-examples] == 0.13.5",
|
|
91
|
+
"pytest-mock == 3.14.1",
|
|
92
|
+
"pytest-asyncio == 1.1.0",
|
|
93
|
+
"async-solipsism == 0.8",
|
|
94
94
|
]
|
|
95
95
|
dev = [
|
|
96
96
|
"frequenz-client-microgrid[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
|
|
@@ -161,7 +161,15 @@ disable = [
|
|
|
161
161
|
]
|
|
162
162
|
|
|
163
163
|
[tool.pytest.ini_options]
|
|
164
|
-
addopts = "-
|
|
164
|
+
addopts = "-vv"
|
|
165
|
+
filterwarnings = [
|
|
166
|
+
"error",
|
|
167
|
+
"once::DeprecationWarning",
|
|
168
|
+
"once::PendingDeprecationWarning",
|
|
169
|
+
# We use a raw string (single quote) to avoid the need to escape special
|
|
170
|
+
# chars as this is a regex
|
|
171
|
+
'ignore:Protobuf gencode version .*exactly one major version older.*:UserWarning',
|
|
172
|
+
]
|
|
165
173
|
testpaths = ["tests", "src"]
|
|
166
174
|
asyncio_mode = "auto"
|
|
167
175
|
asyncio_default_fixture_loop_scope = "function"
|
|
@@ -17,6 +17,9 @@ from frequenz.api.common import components_pb2, metrics_pb2
|
|
|
17
17
|
from frequenz.api.microgrid import microgrid_pb2, microgrid_pb2_grpc, sensor_pb2
|
|
18
18
|
from frequenz.channels import Receiver
|
|
19
19
|
from frequenz.client.base import channel, client, retry, streaming
|
|
20
|
+
from frequenz.client.common.microgrid import MicrogridId
|
|
21
|
+
from frequenz.client.common.microgrid.components import ComponentId
|
|
22
|
+
from frequenz.client.common.microgrid.sensors import SensorId
|
|
20
23
|
from google.protobuf.empty_pb2 import Empty
|
|
21
24
|
from typing_extensions import override
|
|
22
25
|
|
|
@@ -39,7 +42,6 @@ from ._constants import RECEIVER_MAX_SIZE
|
|
|
39
42
|
from ._exception import ApiClientError, ClientNotConnected
|
|
40
43
|
from ._metadata import Location, Metadata
|
|
41
44
|
from ._sensor_proto import sensor_data_samples_from_proto, sensor_from_proto
|
|
42
|
-
from .id import ComponentId, MicrogridId, SensorId
|
|
43
45
|
from .sensor import Sensor, SensorDataSamples, SensorMetric
|
|
44
46
|
|
|
45
47
|
DEFAULT_GRPC_CALL_TIMEOUT = 60.0
|
|
@@ -8,8 +8,7 @@ from enum import Enum
|
|
|
8
8
|
|
|
9
9
|
from frequenz.api.common import components_pb2
|
|
10
10
|
from frequenz.api.microgrid import grid_pb2, inverter_pb2
|
|
11
|
-
|
|
12
|
-
from .id import ComponentId
|
|
11
|
+
from frequenz.client.common.microgrid.components import ComponentId
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
class ComponentType(Enum):
|
|
@@ -9,6 +9,7 @@ from datetime import datetime, timezone
|
|
|
9
9
|
from typing import Self
|
|
10
10
|
|
|
11
11
|
from frequenz.api.microgrid import microgrid_pb2
|
|
12
|
+
from frequenz.client.common.microgrid.components import ComponentId
|
|
12
13
|
|
|
13
14
|
from ._component_error import BatteryError, InverterError
|
|
14
15
|
from ._component_states import (
|
|
@@ -18,7 +19,6 @@ from ._component_states import (
|
|
|
18
19
|
EVChargerComponentState,
|
|
19
20
|
InverterComponentState,
|
|
20
21
|
)
|
|
21
|
-
from .id import ComponentId
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@dataclass(frozen=True)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# License: MIT
|
|
2
|
+
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
|
|
3
|
+
|
|
4
|
+
"""Metadata that describes a microgrid."""
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from zoneinfo import ZoneInfo
|
|
8
|
+
|
|
9
|
+
from frequenz.client.common.microgrid import MicrogridId
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, kw_only=True)
|
|
13
|
+
class Location:
|
|
14
|
+
"""Metadata for the location of microgrid."""
|
|
15
|
+
|
|
16
|
+
latitude: float | None = None
|
|
17
|
+
"""The latitude of the microgrid in degree."""
|
|
18
|
+
|
|
19
|
+
longitude: float | None = None
|
|
20
|
+
"""The longitude of the microgrid in degree."""
|
|
21
|
+
|
|
22
|
+
timezone: ZoneInfo | None = None
|
|
23
|
+
"""The timezone of the microgrid."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True, kw_only=True)
|
|
27
|
+
class Metadata:
|
|
28
|
+
"""Metadata for the microgrid."""
|
|
29
|
+
|
|
30
|
+
microgrid_id: MicrogridId | None = None
|
|
31
|
+
"""The ID of the microgrid."""
|
|
32
|
+
|
|
33
|
+
location: Location | None = None
|
|
34
|
+
"""The location of the microgrid."""
|
|
@@ -10,10 +10,10 @@ from datetime import datetime
|
|
|
10
10
|
from frequenz.api.common import components_pb2
|
|
11
11
|
from frequenz.api.microgrid import common_pb2, microgrid_pb2, sensor_pb2
|
|
12
12
|
from frequenz.client.base import conversion
|
|
13
|
+
from frequenz.client.common.microgrid.sensors import SensorId
|
|
13
14
|
|
|
14
15
|
from ._lifetime import Lifetime
|
|
15
16
|
from ._util import enum_from_proto
|
|
16
|
-
from .id import SensorId
|
|
17
17
|
from .sensor import (
|
|
18
18
|
Sensor,
|
|
19
19
|
SensorDataSamples,
|
|
@@ -36,9 +36,9 @@ from datetime import datetime
|
|
|
36
36
|
from typing import assert_never
|
|
37
37
|
|
|
38
38
|
from frequenz.api.microgrid import sensor_pb2
|
|
39
|
+
from frequenz.client.common.microgrid.sensors import SensorId
|
|
39
40
|
|
|
40
41
|
from ._lifetime import Lifetime
|
|
41
|
-
from .id import SensorId
|
|
42
42
|
from .metrics import AggregatedMetricValue, AggregationMethod
|
|
43
43
|
|
|
44
44
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: frequenz-client-microgrid
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: Microgrid API client for Python
|
|
5
5
|
Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
|
|
6
6
|
License: MIT
|
|
@@ -21,15 +21,15 @@ Classifier: Typing :: Typed
|
|
|
21
21
|
Requires-Python: <4,>=3.11
|
|
22
22
|
Description-Content-Type: text/markdown
|
|
23
23
|
License-File: LICENSE
|
|
24
|
-
Requires-Dist: frequenz-api-microgrid<0.16.0,>=0.15.
|
|
24
|
+
Requires-Dist: frequenz-api-microgrid<0.16.0,>=0.15.5
|
|
25
25
|
Requires-Dist: frequenz-channels<2.0.0,>=1.0.0-rc1
|
|
26
|
-
Requires-Dist: frequenz-client-base<0.
|
|
27
|
-
Requires-Dist:
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist: typing-extensions<5,>=4.
|
|
26
|
+
Requires-Dist: frequenz-client-base<0.12.0,>=0.8.0
|
|
27
|
+
Requires-Dist: frequenz-client-common<0.4.0,>=0.3.2
|
|
28
|
+
Requires-Dist: grpcio<2,>=1.63.0
|
|
29
|
+
Requires-Dist: protobuf<7,>=5.26.1
|
|
30
|
+
Requires-Dist: typing-extensions<5,>=4.13.0
|
|
31
31
|
Provides-Extra: dev-flake8
|
|
32
|
-
Requires-Dist: flake8==7.
|
|
32
|
+
Requires-Dist: flake8==7.3.0; extra == "dev-flake8"
|
|
33
33
|
Requires-Dist: flake8-docstrings==1.7.0; extra == "dev-flake8"
|
|
34
34
|
Requires-Dist: flake8-pyproject==1.2.3; extra == "dev-flake8"
|
|
35
35
|
Requires-Dist: pydoclint==0.6.6; extra == "dev-flake8"
|
|
@@ -39,33 +39,33 @@ Requires-Dist: black==25.1.0; extra == "dev-formatting"
|
|
|
39
39
|
Requires-Dist: isort==6.0.1; extra == "dev-formatting"
|
|
40
40
|
Provides-Extra: dev-mkdocs
|
|
41
41
|
Requires-Dist: black==25.1.0; extra == "dev-mkdocs"
|
|
42
|
-
Requires-Dist: Markdown==3.8; extra == "dev-mkdocs"
|
|
42
|
+
Requires-Dist: Markdown==3.8.2; extra == "dev-mkdocs"
|
|
43
43
|
Requires-Dist: mike==2.1.3; extra == "dev-mkdocs"
|
|
44
44
|
Requires-Dist: mkdocs-gen-files==0.5.0; extra == "dev-mkdocs"
|
|
45
45
|
Requires-Dist: mkdocs-literate-nav==0.6.2; extra == "dev-mkdocs"
|
|
46
46
|
Requires-Dist: mkdocs-macros-plugin==1.3.7; extra == "dev-mkdocs"
|
|
47
|
-
Requires-Dist: mkdocs-material==9.6.
|
|
48
|
-
Requires-Dist: mkdocstrings[python]==0.
|
|
49
|
-
Requires-Dist: mkdocstrings-python==1.16.
|
|
50
|
-
Requires-Dist: frequenz-repo-config[lib]==0.13.
|
|
47
|
+
Requires-Dist: mkdocs-material==9.6.16; extra == "dev-mkdocs"
|
|
48
|
+
Requires-Dist: mkdocstrings[python]==0.30.0; extra == "dev-mkdocs"
|
|
49
|
+
Requires-Dist: mkdocstrings-python==1.16.12; extra == "dev-mkdocs"
|
|
50
|
+
Requires-Dist: frequenz-repo-config[lib]==0.13.5; extra == "dev-mkdocs"
|
|
51
51
|
Provides-Extra: dev-mypy
|
|
52
|
-
Requires-Dist: mypy==1.
|
|
52
|
+
Requires-Dist: mypy==1.17.1; extra == "dev-mypy"
|
|
53
53
|
Requires-Dist: grpc-stubs==1.53.0.6; extra == "dev-mypy"
|
|
54
|
-
Requires-Dist: types-Markdown==3.8.0.
|
|
55
|
-
Requires-Dist: types-protobuf==
|
|
54
|
+
Requires-Dist: types-Markdown==3.8.0.20250708; extra == "dev-mypy"
|
|
55
|
+
Requires-Dist: types-protobuf==6.30.2.20250703; extra == "dev-mypy"
|
|
56
56
|
Requires-Dist: frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-mypy"
|
|
57
57
|
Provides-Extra: dev-noxfile
|
|
58
58
|
Requires-Dist: nox==2025.5.1; extra == "dev-noxfile"
|
|
59
|
-
Requires-Dist: frequenz-repo-config[lib]==0.13.
|
|
59
|
+
Requires-Dist: frequenz-repo-config[lib]==0.13.5; extra == "dev-noxfile"
|
|
60
60
|
Provides-Extra: dev-pylint
|
|
61
|
-
Requires-Dist: pylint==3.3.
|
|
61
|
+
Requires-Dist: pylint==3.3.7; extra == "dev-pylint"
|
|
62
62
|
Requires-Dist: frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-pylint"
|
|
63
63
|
Provides-Extra: dev-pytest
|
|
64
|
-
Requires-Dist: pytest==8.
|
|
65
|
-
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.13.
|
|
66
|
-
Requires-Dist: pytest-mock==3.14.
|
|
67
|
-
Requires-Dist: pytest-asyncio==
|
|
68
|
-
Requires-Dist: async-solipsism==0.
|
|
64
|
+
Requires-Dist: pytest==8.4.1; extra == "dev-pytest"
|
|
65
|
+
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.13.5; extra == "dev-pytest"
|
|
66
|
+
Requires-Dist: pytest-mock==3.14.1; extra == "dev-pytest"
|
|
67
|
+
Requires-Dist: pytest-asyncio==1.1.0; extra == "dev-pytest"
|
|
68
|
+
Requires-Dist: async-solipsism==0.8; extra == "dev-pytest"
|
|
69
69
|
Provides-Extra: dev
|
|
70
70
|
Requires-Dist: frequenz-client-microgrid[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]; extra == "dev"
|
|
71
71
|
Dynamic: license-file
|
|
@@ -17,7 +17,6 @@ src/frequenz/client/microgrid/_metadata.py
|
|
|
17
17
|
src/frequenz/client/microgrid/_sensor_proto.py
|
|
18
18
|
src/frequenz/client/microgrid/_util.py
|
|
19
19
|
src/frequenz/client/microgrid/conftest.py
|
|
20
|
-
src/frequenz/client/microgrid/id.py
|
|
21
20
|
src/frequenz/client/microgrid/metrics.py
|
|
22
21
|
src/frequenz/client/microgrid/py.typed
|
|
23
22
|
src/frequenz/client/microgrid/sensor.py
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
frequenz-api-microgrid<0.16.0,>=0.15.
|
|
1
|
+
frequenz-api-microgrid<0.16.0,>=0.15.5
|
|
2
2
|
frequenz-channels<2.0.0,>=1.0.0-rc1
|
|
3
|
-
frequenz-client-base<0.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
typing-extensions<5,>=4.
|
|
3
|
+
frequenz-client-base<0.12.0,>=0.8.0
|
|
4
|
+
frequenz-client-common<0.4.0,>=0.3.2
|
|
5
|
+
grpcio<2,>=1.63.0
|
|
6
|
+
protobuf<7,>=5.26.1
|
|
7
|
+
typing-extensions<5,>=4.13.0
|
|
8
8
|
|
|
9
9
|
[dev]
|
|
10
10
|
frequenz-client-microgrid[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]
|
|
11
11
|
|
|
12
12
|
[dev-flake8]
|
|
13
|
-
flake8==7.
|
|
13
|
+
flake8==7.3.0
|
|
14
14
|
flake8-docstrings==1.7.0
|
|
15
15
|
flake8-pyproject==1.2.3
|
|
16
16
|
pydoclint==0.6.6
|
|
@@ -22,34 +22,34 @@ isort==6.0.1
|
|
|
22
22
|
|
|
23
23
|
[dev-mkdocs]
|
|
24
24
|
black==25.1.0
|
|
25
|
-
Markdown==3.8
|
|
25
|
+
Markdown==3.8.2
|
|
26
26
|
mike==2.1.3
|
|
27
27
|
mkdocs-gen-files==0.5.0
|
|
28
28
|
mkdocs-literate-nav==0.6.2
|
|
29
29
|
mkdocs-macros-plugin==1.3.7
|
|
30
|
-
mkdocs-material==9.6.
|
|
31
|
-
mkdocstrings[python]==0.
|
|
32
|
-
mkdocstrings-python==1.16.
|
|
33
|
-
frequenz-repo-config[lib]==0.13.
|
|
30
|
+
mkdocs-material==9.6.16
|
|
31
|
+
mkdocstrings[python]==0.30.0
|
|
32
|
+
mkdocstrings-python==1.16.12
|
|
33
|
+
frequenz-repo-config[lib]==0.13.5
|
|
34
34
|
|
|
35
35
|
[dev-mypy]
|
|
36
|
-
mypy==1.
|
|
36
|
+
mypy==1.17.1
|
|
37
37
|
grpc-stubs==1.53.0.6
|
|
38
|
-
types-Markdown==3.8.0.
|
|
39
|
-
types-protobuf==
|
|
38
|
+
types-Markdown==3.8.0.20250708
|
|
39
|
+
types-protobuf==6.30.2.20250703
|
|
40
40
|
frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]
|
|
41
41
|
|
|
42
42
|
[dev-noxfile]
|
|
43
43
|
nox==2025.5.1
|
|
44
|
-
frequenz-repo-config[lib]==0.13.
|
|
44
|
+
frequenz-repo-config[lib]==0.13.5
|
|
45
45
|
|
|
46
46
|
[dev-pylint]
|
|
47
|
-
pylint==3.3.
|
|
47
|
+
pylint==3.3.7
|
|
48
48
|
frequenz-client-microgrid[dev-mkdocs,dev-noxfile,dev-pytest]
|
|
49
49
|
|
|
50
50
|
[dev-pytest]
|
|
51
|
-
pytest==8.
|
|
52
|
-
frequenz-repo-config[extra-lint-examples]==0.13.
|
|
53
|
-
pytest-mock==3.14.
|
|
54
|
-
pytest-asyncio==
|
|
55
|
-
async-solipsism==0.
|
|
51
|
+
pytest==8.4.1
|
|
52
|
+
frequenz-repo-config[extra-lint-examples]==0.13.5
|
|
53
|
+
pytest-mock==3.14.1
|
|
54
|
+
pytest-asyncio==1.1.0
|
|
55
|
+
async-solipsism==0.8
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Frequenz Microgrid API Client Release Notes
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
This release introduces sensors support and adds official support for Python 3.12. It also includes some bug fixes.
|
|
6
|
-
|
|
7
|
-
## Upgrading
|
|
8
|
-
|
|
9
|
-
- Some minimum versions of dependencies have been bumped to support Python 3.12. You might also need to bump these dependencies in your project.
|
|
10
|
-
|
|
11
|
-
## New Features
|
|
12
|
-
|
|
13
|
-
- The `MicrogridApiClient` can now list sensor retrieving their metadata (`list_sensors()`) and can stream sensor data (`stream_sensor_data()`).
|
|
14
|
-
|
|
15
|
-
## Bug Fixes
|
|
16
|
-
|
|
17
|
-
- When retrieving the microgrid metadata using `metadata()`, if the location was empty in the protobuf message, a wrong location with long=0, lat=0 was used. Now the location will be properly set to `None` in that case.
|
|
18
|
-
- The client now does some missing cleanup (stopping background tasks) when disconnecting (and when used as a context manager).
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# License: MIT
|
|
2
|
-
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
|
|
3
|
-
|
|
4
|
-
"""Metadata that describes a microgrid."""
|
|
5
|
-
|
|
6
|
-
from dataclasses import dataclass
|
|
7
|
-
from zoneinfo import ZoneInfo
|
|
8
|
-
|
|
9
|
-
from timezonefinder import TimezoneFinder
|
|
10
|
-
|
|
11
|
-
from .id import MicrogridId
|
|
12
|
-
|
|
13
|
-
_timezone_finder = TimezoneFinder()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@dataclass(frozen=True, kw_only=True)
|
|
17
|
-
class Location:
|
|
18
|
-
"""Metadata for the location of microgrid."""
|
|
19
|
-
|
|
20
|
-
latitude: float | None = None
|
|
21
|
-
"""The latitude of the microgrid in degree."""
|
|
22
|
-
|
|
23
|
-
longitude: float | None = None
|
|
24
|
-
"""The longitude of the microgrid in degree."""
|
|
25
|
-
|
|
26
|
-
timezone: ZoneInfo | None = None
|
|
27
|
-
"""The timezone of the microgrid.
|
|
28
|
-
|
|
29
|
-
If not passed during construction (or `None` is passed), and there is a `longitude`
|
|
30
|
-
and `latitude`, then the timezone wil be looked up in a database based on the
|
|
31
|
-
coordinates. This lookup could fail, in which case the timezone will still be
|
|
32
|
-
`None`.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def __post_init__(self) -> None:
|
|
36
|
-
"""Initialize the timezone of the microgrid."""
|
|
37
|
-
if self.latitude is None or self.longitude is None or self.timezone is not None:
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
timezone = _timezone_finder.timezone_at(lat=self.latitude, lng=self.longitude)
|
|
41
|
-
if timezone:
|
|
42
|
-
# The dataclass is frozen, so it needs to use __setattr__ to set the timezone.
|
|
43
|
-
object.__setattr__(self, "timezone", ZoneInfo(key=timezone))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@dataclass(frozen=True, kw_only=True)
|
|
47
|
-
class Metadata:
|
|
48
|
-
"""Metadata for the microgrid."""
|
|
49
|
-
|
|
50
|
-
microgrid_id: MicrogridId | None = None
|
|
51
|
-
"""The ID of the microgrid."""
|
|
52
|
-
|
|
53
|
-
location: Location | None = None
|
|
54
|
-
"""The location of the microgrid."""
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
# License: MIT
|
|
2
|
-
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
|
|
3
|
-
|
|
4
|
-
r'''Provides strongly-typed unique identifiers for entities.
|
|
5
|
-
|
|
6
|
-
This module offers a base class,
|
|
7
|
-
[`BaseId`][frequenz.client.microgrid.id.BaseId], which can be subclassed to
|
|
8
|
-
create distinct ID types for different components or concepts within a system.
|
|
9
|
-
These IDs ensure type safety, meaning that an ID for one type of entity (e.g., a
|
|
10
|
-
sensor) cannot be mistakenly used where an ID for another type (e.g., a
|
|
11
|
-
microgrid) is expected.
|
|
12
|
-
|
|
13
|
-
# Creating Custom ID Types
|
|
14
|
-
|
|
15
|
-
To define a new ID type, create a class that inherits from
|
|
16
|
-
[`BaseId`][frequenz.client.microgrid.id.BaseId] and provide a unique
|
|
17
|
-
`str_prefix` as a keyword argument in the class definition. This prefix is used
|
|
18
|
-
in the string representation of the ID and must be unique across all ID types.
|
|
19
|
-
|
|
20
|
-
Note:
|
|
21
|
-
The `str_prefix` must be unique across all ID types. If you try to use a
|
|
22
|
-
prefix that is already registered, a `ValueError` will be raised when defining
|
|
23
|
-
the class.
|
|
24
|
-
|
|
25
|
-
To encourage consistency, the class name must end with the suffix "Id" (e.g.,
|
|
26
|
-
`MyNewId`). This check can be bypassed by passing `allow_custom_name=True` when
|
|
27
|
-
defining the class (e.g., `class MyCustomName(BaseId, str_prefix="MCN",
|
|
28
|
-
allow_custom_name=True):`).
|
|
29
|
-
|
|
30
|
-
Tip:
|
|
31
|
-
Use the [`@typing.final`][typing.final] decorator to prevent subclassing of
|
|
32
|
-
ID classes.
|
|
33
|
-
|
|
34
|
-
Example: Creating a standard ID type
|
|
35
|
-
```python
|
|
36
|
-
from typing import final
|
|
37
|
-
from frequenz.client.microgrid.id import BaseId
|
|
38
|
-
|
|
39
|
-
@final
|
|
40
|
-
class InverterId(BaseId, str_prefix="INV"):
|
|
41
|
-
"""A unique identifier for an inverter."""
|
|
42
|
-
|
|
43
|
-
inv_id = InverterId(123)
|
|
44
|
-
print(inv_id) # Output: INV123
|
|
45
|
-
print(int(inv_id)) # Output: 123
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Example: Creating an ID type with a non-standard name
|
|
49
|
-
```python
|
|
50
|
-
from typing import final
|
|
51
|
-
from frequenz.client.microgrid.id import BaseId
|
|
52
|
-
|
|
53
|
-
@final
|
|
54
|
-
class CustomNameForId(BaseId, str_prefix="CST", allow_custom_name=True):
|
|
55
|
-
"""An ID with a custom name, not ending in 'Id'."""
|
|
56
|
-
|
|
57
|
-
custom_id = CustomNameForId(456)
|
|
58
|
-
print(custom_id) # Output: CST456
|
|
59
|
-
print(int(custom_id)) # Output: 456
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
# Predefined ID Types
|
|
63
|
-
|
|
64
|
-
This module predefines the following ID types:
|
|
65
|
-
|
|
66
|
-
- [`ComponentId`][frequenz.client.microgrid.id.ComponentId]: For identifying
|
|
67
|
-
generic components.
|
|
68
|
-
- [`MicrogridId`][frequenz.client.microgrid.id.MicrogridId]: For identifying
|
|
69
|
-
microgrids.
|
|
70
|
-
- [`SensorId`][frequenz.client.microgrid.id.SensorId]: For identifying sensors.
|
|
71
|
-
'''
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
from typing import Any, ClassVar, Self, cast, final
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class BaseId:
|
|
78
|
-
"""A base class for unique identifiers.
|
|
79
|
-
|
|
80
|
-
Subclasses must provide a unique `str_prefix` keyword argument during
|
|
81
|
-
definition, which is used in the string representation of the ID.
|
|
82
|
-
|
|
83
|
-
By default, subclass names must end with "Id". This can be overridden by
|
|
84
|
-
passing `allow_custom_name=True` during class definition.
|
|
85
|
-
|
|
86
|
-
For more information and examples, see the [module's
|
|
87
|
-
documentation][frequenz.client.microgrid.id].
|
|
88
|
-
"""
|
|
89
|
-
|
|
90
|
-
_id: int
|
|
91
|
-
_str_prefix: ClassVar[str]
|
|
92
|
-
_registered_prefixes: ClassVar[set[str]] = set()
|
|
93
|
-
|
|
94
|
-
def __new__(cls, *_: Any, **__: Any) -> Self:
|
|
95
|
-
"""Create a new instance of the ID class, only if it is a subclass of BaseId."""
|
|
96
|
-
if cls is BaseId:
|
|
97
|
-
raise TypeError("BaseId cannot be instantiated directly. Use a subclass.")
|
|
98
|
-
return super().__new__(cls)
|
|
99
|
-
|
|
100
|
-
def __init_subclass__(
|
|
101
|
-
cls,
|
|
102
|
-
*,
|
|
103
|
-
str_prefix: str,
|
|
104
|
-
allow_custom_name: bool = False,
|
|
105
|
-
**kwargs: Any,
|
|
106
|
-
) -> None:
|
|
107
|
-
"""Initialize a subclass, set its string prefix, and perform checks.
|
|
108
|
-
|
|
109
|
-
Args:
|
|
110
|
-
str_prefix: The string prefix for the ID type (e.g., "MID").
|
|
111
|
-
Must be unique across all ID types.
|
|
112
|
-
allow_custom_name: If True, bypasses the check that the class name
|
|
113
|
-
must end with "Id". Defaults to False.
|
|
114
|
-
**kwargs: Forwarded to the parent's __init_subclass__.
|
|
115
|
-
|
|
116
|
-
Raises:
|
|
117
|
-
ValueError: If the `str_prefix` is already registered by another
|
|
118
|
-
ID type.
|
|
119
|
-
TypeError: If `allow_custom_name` is False and the class name
|
|
120
|
-
does not end with "Id".
|
|
121
|
-
"""
|
|
122
|
-
super().__init_subclass__(**kwargs)
|
|
123
|
-
|
|
124
|
-
if str_prefix in BaseId._registered_prefixes:
|
|
125
|
-
raise ValueError(
|
|
126
|
-
f"Prefix '{str_prefix}' is already registered. "
|
|
127
|
-
"ID prefixes must be unique."
|
|
128
|
-
)
|
|
129
|
-
BaseId._registered_prefixes.add(str_prefix)
|
|
130
|
-
|
|
131
|
-
if not allow_custom_name and not cls.__name__.endswith("Id"):
|
|
132
|
-
raise TypeError(
|
|
133
|
-
f"Class name '{cls.__name__}' for an ID class must end with 'Id' "
|
|
134
|
-
"(e.g., 'SomeId'), or use `allow_custom_name=True`."
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
cls._str_prefix = str_prefix
|
|
138
|
-
|
|
139
|
-
def __init__(self, id_: int, /) -> None:
|
|
140
|
-
"""Initialize this instance.
|
|
141
|
-
|
|
142
|
-
Args:
|
|
143
|
-
id_: The numeric unique identifier.
|
|
144
|
-
|
|
145
|
-
Raises:
|
|
146
|
-
ValueError: If the ID is negative.
|
|
147
|
-
"""
|
|
148
|
-
if id_ < 0:
|
|
149
|
-
raise ValueError(f"{type(self).__name__} can't be negative.")
|
|
150
|
-
self._id = id_
|
|
151
|
-
|
|
152
|
-
@property
|
|
153
|
-
def str_prefix(self) -> str:
|
|
154
|
-
"""The prefix used for the string representation of this ID."""
|
|
155
|
-
return self._str_prefix
|
|
156
|
-
|
|
157
|
-
def __int__(self) -> int:
|
|
158
|
-
"""Return the numeric ID of this instance."""
|
|
159
|
-
return self._id
|
|
160
|
-
|
|
161
|
-
def __eq__(self, other: object) -> bool:
|
|
162
|
-
"""Check if this instance is equal to another object.
|
|
163
|
-
|
|
164
|
-
Equality is defined as being of the exact same type and having the same
|
|
165
|
-
underlying ID.
|
|
166
|
-
"""
|
|
167
|
-
# pylint thinks this is not an unidiomatic typecheck, but in this case
|
|
168
|
-
# it is not. isinstance() returns True for subclasses, which is not
|
|
169
|
-
# what we want here, as different ID types should never be equal.
|
|
170
|
-
# pylint: disable-next=unidiomatic-typecheck
|
|
171
|
-
if type(other) is not type(self):
|
|
172
|
-
return NotImplemented
|
|
173
|
-
# We already checked type(other) is type(self), but mypy doesn't
|
|
174
|
-
# understand that, so we need to cast it to Self.
|
|
175
|
-
other_id = cast(Self, other)
|
|
176
|
-
return self._id == other_id._id
|
|
177
|
-
|
|
178
|
-
def __lt__(self, other: object) -> bool:
|
|
179
|
-
"""Check if this instance is less than another object.
|
|
180
|
-
|
|
181
|
-
Comparison is only defined between instances of the exact same type.
|
|
182
|
-
"""
|
|
183
|
-
# pylint: disable-next=unidiomatic-typecheck
|
|
184
|
-
if type(other) is not type(self):
|
|
185
|
-
return NotImplemented
|
|
186
|
-
other_id = cast(Self, other)
|
|
187
|
-
return self._id < other_id._id
|
|
188
|
-
|
|
189
|
-
def __hash__(self) -> int:
|
|
190
|
-
"""Return the hash of this instance.
|
|
191
|
-
|
|
192
|
-
The hash is based on the exact type and the underlying ID to ensure
|
|
193
|
-
that IDs of different types but with the same numeric value have different hashes.
|
|
194
|
-
"""
|
|
195
|
-
return hash((type(self), self._id))
|
|
196
|
-
|
|
197
|
-
def __repr__(self) -> str:
|
|
198
|
-
"""Return the string representation of this instance."""
|
|
199
|
-
return f"{type(self).__name__}({self._id!r})"
|
|
200
|
-
|
|
201
|
-
def __str__(self) -> str:
|
|
202
|
-
"""Return the short string representation of this instance."""
|
|
203
|
-
return f"{type(self)._str_prefix}{self._id}"
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
@final
|
|
207
|
-
class MicrogridId(BaseId, str_prefix="MID"):
|
|
208
|
-
"""A unique identifier for a microgrid."""
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
@final
|
|
212
|
-
class ComponentId(BaseId, str_prefix="CID"):
|
|
213
|
-
"""A unique identifier for a microgrid component."""
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
@final
|
|
217
|
-
class SensorId(BaseId, str_prefix="SID"):
|
|
218
|
-
"""A unique identifier for a microgrid sensor."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|