frequenz-client-common 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright © 2023 Frequenz Energy-as-a-Service GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ exclude .cookiecutter-replay.json
2
+ exclude .editorconfig
3
+ exclude .gitignore
4
+ exclude CODEOWNERS
5
+ exclude CONTRIBUTING.md
6
+ exclude mkdocs.yml
7
+ exclude noxfile.py
8
+ exclude src/conftest.py
9
+ recursive-exclude .github *
10
+ recursive-exclude benchmarks *
11
+ recursive-exclude docs *
12
+ recursive-exclude tests *
13
+ recursive-include py *.pyi
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.1
2
+ Name: frequenz-client-common
3
+ Version: 0.1.0
4
+ Summary: Common code and utilities for Frequenz API clients
5
+ Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
6
+ License: MIT
7
+ Project-URL: Documentation, https://frequenz-floss.github.io/frequenz-client-common-python/
8
+ Project-URL: Changelog, https://github.com/frequenz-floss/frequenz-client-common-python/releases
9
+ Project-URL: Issues, https://github.com/frequenz-floss/frequenz-client-common-python/issues
10
+ Project-URL: Repository, https://github.com/frequenz-floss/frequenz-client-common-python
11
+ Project-URL: Support, https://github.com/frequenz-floss/frequenz-client-common-python/discussions/categories/support
12
+ Keywords: frequenz,python,lib,library,client-common
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: <4,>=3.11
21
+ Description-Content-Type: text/markdown
22
+ Provides-Extra: dev-flake8
23
+ Provides-Extra: dev-formatting
24
+ Provides-Extra: dev-mkdocs
25
+ Provides-Extra: dev-mypy
26
+ Provides-Extra: dev-noxfile
27
+ Provides-Extra: dev-pylint
28
+ Provides-Extra: dev-pytest
29
+ Provides-Extra: dev
30
+ License-File: LICENSE
31
+
32
+ # Frequenz Client Common Library
33
+
34
+ [![Build Status](https://github.com/frequenz-floss/frequenz-client-common-python/actions/workflows/ci.yaml/badge.svg)](https://github.com/frequenz-floss/frequenz-client-common-python/actions/workflows/ci.yaml)
35
+ [![PyPI Package](https://img.shields.io/pypi/v/frequenz-client-common)](https://pypi.org/project/frequenz-client-common/)
36
+ [![Docs](https://img.shields.io/badge/docs-latest-informational)](https://frequenz-floss.github.io/frequenz-client-common-python/)
37
+
38
+ ## Introduction
39
+
40
+ Common code and utilities for Frequenz API clients
41
+
42
+ TODO(cookiecutter): Improve the README file
43
+
44
+ ## Supported Platforms
45
+
46
+ The following platforms are officially supported (tested):
47
+
48
+ - **Python:** 3.11
49
+ - **Operating System:** Ubuntu Linux 20.04
50
+ - **Architectures:** amd64, arm64
51
+
52
+ ## Contributing
53
+
54
+ If you want to know how to build this project and contribute to it, please
55
+ check out the [Contributing Guide](CONTRIBUTING.md).
@@ -0,0 +1,24 @@
1
+ # Frequenz Client Common Library
2
+
3
+ [![Build Status](https://github.com/frequenz-floss/frequenz-client-common-python/actions/workflows/ci.yaml/badge.svg)](https://github.com/frequenz-floss/frequenz-client-common-python/actions/workflows/ci.yaml)
4
+ [![PyPI Package](https://img.shields.io/pypi/v/frequenz-client-common)](https://pypi.org/project/frequenz-client-common/)
5
+ [![Docs](https://img.shields.io/badge/docs-latest-informational)](https://frequenz-floss.github.io/frequenz-client-common-python/)
6
+
7
+ ## Introduction
8
+
9
+ Common code and utilities for Frequenz API clients
10
+
11
+ TODO(cookiecutter): Improve the README file
12
+
13
+ ## Supported Platforms
14
+
15
+ The following platforms are officially supported (tested):
16
+
17
+ - **Python:** 3.11
18
+ - **Operating System:** Ubuntu Linux 20.04
19
+ - **Architectures:** amd64, arm64
20
+
21
+ ## Contributing
22
+
23
+ If you want to know how to build this project and contribute to it, please
24
+ check out the [Contributing Guide](CONTRIBUTING.md).
@@ -0,0 +1,22 @@
1
+ # Frequenz Client Common Library Release Notes
2
+
3
+ ## Summary
4
+
5
+ This is the initial release of the Frequenz Client Common Library.
6
+ It provides wrappers around the types from Frequenz's common API protobuf definitions.
7
+ This version contains types to support pagination in gRPC requests
8
+ and enum types for components and metrics to be used in a microgrid.
9
+
10
+ <!-- Here goes a general summary of what this release is about -->
11
+
12
+ ## Upgrading
13
+
14
+ <!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
15
+
16
+ ## New Features
17
+
18
+ <!-- Here goes the main new features and examples or instructions on how to use them -->
19
+
20
+ ## Bug Fixes
21
+
22
+ <!-- Here goes notable bug fixes that are worth a special mention or explanation -->
@@ -0,0 +1,164 @@
1
+ # License: MIT
2
+ # Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3
+
4
+ [build-system]
5
+ requires = [
6
+ "setuptools == 68.1.0",
7
+ "setuptools_scm[toml] == 7.1.0",
8
+ "frequenz-repo-config[lib] == 0.9.1",
9
+ ]
10
+ build-backend = "setuptools.build_meta"
11
+
12
+ [project]
13
+ name = "frequenz-client-common"
14
+ description = "Common code and utilities for Frequenz API clients"
15
+ readme = "README.md"
16
+ license = { text = "MIT" }
17
+ keywords = ["frequenz", "python", "lib", "library", "client-common"]
18
+ classifiers = [
19
+ "Development Status :: 3 - Alpha",
20
+ "Intended Audience :: Developers",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3 :: Only",
24
+ "Topic :: Software Development :: Libraries",
25
+ "Typing :: Typed",
26
+ ]
27
+ requires-python = ">= 3.11, < 4"
28
+ dependencies = [
29
+ "typing-extensions >= 4.5.0, < 5",
30
+ "frequenz-api-common >= 0.5.4, < 6",
31
+ ]
32
+ dynamic = ["version"]
33
+
34
+ [[project.authors]]
35
+ name = "Frequenz Energy-as-a-Service GmbH"
36
+ email = "floss@frequenz.com"
37
+
38
+ [project.optional-dependencies]
39
+ dev-flake8 = [
40
+ "flake8 == 7.0.0",
41
+ "flake8-docstrings == 1.7.0",
42
+ "flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
43
+ "pydoclint == 0.4.1",
44
+ "pydocstyle == 6.3.0",
45
+ ]
46
+ dev-formatting = ["black == 24.2.0", "isort == 5.13.2"]
47
+ dev-mkdocs = [
48
+ "black == 24.2.0",
49
+ "Markdown==3.5.2",
50
+ "mike == 2.0.0",
51
+ "mkdocs-gen-files == 0.5.0",
52
+ "mkdocs-literate-nav == 0.6.1",
53
+ "mkdocs-macros-plugin == 1.0.5",
54
+ "mkdocs-material == 9.5.12",
55
+ "mkdocstrings[python] == 0.24.1",
56
+ "frequenz-repo-config[lib] == 0.9.1",
57
+ ]
58
+ dev-mypy = [
59
+ "mypy == 1.8.0",
60
+ "types-Markdown == 3.5.0.20240129",
61
+ # For checking the noxfile, docs/ script, and tests
62
+ "frequenz-client-common[dev-mkdocs,dev-noxfile,dev-pytest]",
63
+ ]
64
+ dev-noxfile = [
65
+ "nox == 2023.4.22",
66
+ "frequenz-repo-config[lib] == 0.9.1",
67
+ ]
68
+ dev-pylint = [
69
+ "pylint == 3.1.0",
70
+ # For checking the noxfile, docs/ script, and tests
71
+ "frequenz-client-common[dev-mkdocs,dev-noxfile,dev-pytest]",
72
+ ]
73
+ dev-pytest = [
74
+ "pytest == 8.1.0",
75
+ "frequenz-repo-config[extra-lint-examples] == 0.9.1",
76
+ "pytest-mock == 3.12.0",
77
+ "pytest-asyncio == 0.23.5",
78
+ "async-solipsism == 0.5",
79
+ ]
80
+ dev = [
81
+ "frequenz-client-common[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
82
+ ]
83
+
84
+ [project.urls]
85
+ Documentation = "https://frequenz-floss.github.io/frequenz-client-common-python/"
86
+ Changelog = "https://github.com/frequenz-floss/frequenz-client-common-python/releases"
87
+ Issues = "https://github.com/frequenz-floss/frequenz-client-common-python/issues"
88
+ Repository = "https://github.com/frequenz-floss/frequenz-client-common-python"
89
+ Support = "https://github.com/frequenz-floss/frequenz-client-common-python/discussions/categories/support"
90
+
91
+ [tool.black]
92
+ line-length = 88
93
+ target-version = ['py311']
94
+ include = '\.pyi?$'
95
+
96
+ [tool.isort]
97
+ profile = "black"
98
+ line_length = 88
99
+ src_paths = ["benchmarks", "examples", "src", "tests"]
100
+
101
+ [tool.flake8]
102
+ # We give some flexibility to go over 88, there are cases like long URLs or
103
+ # code in documenation that have extra indentation. Black will still take care
104
+ # of making everything that can be 88 wide, 88 wide.
105
+ max-line-length = 100
106
+ extend-ignore = [
107
+ "E203", # Whitespace before ':' (conflicts with black)
108
+ "W503", # Line break before binary operator (conflicts with black)
109
+ ]
110
+ # pydoclint options
111
+ style = "google"
112
+ check-return-types = false
113
+ check-yield-types = false
114
+ arg-type-hints-in-docstring = false
115
+ arg-type-hints-in-signature = true
116
+ allow-init-docstring = true
117
+
118
+ [tool.pylint.similarities]
119
+ ignore-comments = ['yes']
120
+ ignore-docstrings = ['yes']
121
+ ignore-imports = ['no']
122
+ min-similarity-lines = 40
123
+
124
+ [tool.pylint.messages_control]
125
+ disable = [
126
+ "too-few-public-methods",
127
+ "too-many-return-statements",
128
+ # disabled because it conflicts with isort
129
+ "wrong-import-order",
130
+ "ungrouped-imports",
131
+ # pylint's unsubscriptable check is buggy and is not needed because
132
+ # it is a type-check, for which we already have mypy.
133
+ "unsubscriptable-object",
134
+ # Checked by flake8
135
+ "redefined-outer-name",
136
+ "unused-import",
137
+ "line-too-long",
138
+ "unused-variable",
139
+ "unnecessary-lambda-assignment",
140
+ ]
141
+
142
+ [tool.pytest.ini_options]
143
+ testpaths = ["tests", "src"]
144
+ asyncio_mode = "auto"
145
+ required_plugins = ["pytest-asyncio", "pytest-mock"]
146
+
147
+ [tool.mypy]
148
+ explicit_package_bases = true
149
+ namespace_packages = true
150
+ # This option disables mypy cache, and it is sometimes useful to enable it if
151
+ # you are getting weird intermittent error, or error in the CI but not locally
152
+ # (or vice versa). In particular errors saying that type: ignore is not
153
+ # used but getting the original ignored error when removing the type: ignore.
154
+ # See for example: https://github.com/python/mypy/issues/2960
155
+ #no_incremental = true
156
+ packages = ["frequenz.client.common"]
157
+ strict = true
158
+
159
+ [[tool.mypy.overrides]]
160
+ module = ["mkdocs_macros.*", "sybil", "sybil.*"]
161
+ ignore_missing_imports = true
162
+
163
+ [tool.setuptools_scm]
164
+ version_scheme = "post-release"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,4 @@
1
+ # License: MIT
2
+ # Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3
+
4
+ """Common code and utilities for Frequenz API clients."""
@@ -0,0 +1,13 @@
1
+ # License: MIT
2
+ # Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3
+
4
+ """Validate docstring code examples.
5
+
6
+ Code examples are often wrapped in triple backticks (```) within docstrings.
7
+ This plugin extracts these code examples and validates them using pylint.
8
+ """
9
+
10
+ from frequenz.repo.config.pytest import examples
11
+ from sybil import Sybil
12
+
13
+ pytest_collect_file = Sybil(**examples.get_sybil_arguments()).pytest()
@@ -0,0 +1,140 @@
1
+ # License: MIT
2
+ # Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3
+
4
+ """Module to define the metrics used with the common client."""
5
+
6
+ from enum import Enum
7
+ from typing import Self
8
+
9
+ # pylint: disable=no-name-in-module
10
+ from frequenz.api.common.v1.metrics.metric_sample_pb2 import Metric as PBMetric
11
+
12
+ # pylint: enable=no-name-in-module
13
+
14
+
15
+ class Metric(Enum):
16
+ """List of supported metrics."""
17
+
18
+ # Default value
19
+ UNSPECIFIED = PBMetric.METRIC_UNSPECIFIED
20
+
21
+ # DC electricity metrics
22
+ DC_VOLTAGE = PBMetric.METRIC_DC_VOLTAGE
23
+ DC_CURRENT = PBMetric.METRIC_DC_CURRENT
24
+ DC_POWER = PBMetric.METRIC_DC_POWER
25
+
26
+ # General AC electricity metrics
27
+ AC_FREQUENCY = PBMetric.METRIC_AC_FREQUENCY
28
+ AC_VOLTAGE = PBMetric.METRIC_AC_VOLTAGE
29
+ AC_VOLTAGE_PHASE_1 = PBMetric.METRIC_AC_VOLTAGE_PHASE_1
30
+ AC_VOLTAGE_PHASE_2 = PBMetric.METRIC_AC_VOLTAGE_PHASE_2
31
+ AC_VOLTAGE_PHASE_3 = PBMetric.METRIC_AC_VOLTAGE_PHASE_3
32
+ AC_APPARENT_CURRENT = PBMetric.METRIC_AC_APPARENT_CURRENT
33
+ AC_APPARENT_CURRENT_PHASE_1 = PBMetric.METRIC_AC_APPARENT_CURRENT_PHASE_1
34
+ AC_APPARENT_CURRENT_PHASE_2 = PBMetric.METRIC_AC_APPARENT_CURRENT_PHASE_2
35
+ AC_APPARENT_CURRENT_PHASE_3 = PBMetric.METRIC_AC_APPARENT_CURRENT_PHASE_3
36
+
37
+ # AC power metrics
38
+ AC_APPARENT_POWER = PBMetric.METRIC_AC_APPARENT_POWER
39
+ AC_APPARENT_POWER_PHASE_1 = PBMetric.METRIC_AC_APPARENT_POWER_PHASE_1
40
+ AC_APPARENT_POWER_PHASE_2 = PBMetric.METRIC_AC_APPARENT_POWER_PHASE_2
41
+ AC_APPARENT_POWER_PHASE_3 = PBMetric.METRIC_AC_APPARENT_POWER_PHASE_3
42
+ AC_ACTIVE_POWER = PBMetric.METRIC_AC_ACTIVE_POWER
43
+ AC_ACTIVE_POWER_PHASE_1 = PBMetric.METRIC_AC_ACTIVE_POWER_PHASE_1
44
+ AC_ACTIVE_POWER_PHASE_2 = PBMetric.METRIC_AC_ACTIVE_POWER_PHASE_2
45
+ AC_ACTIVE_POWER_PHASE_3 = PBMetric.METRIC_AC_ACTIVE_POWER_PHASE_3
46
+ AC_REACTIVE_POWER = PBMetric.METRIC_AC_REACTIVE_POWER
47
+ AC_REACTIVE_POWER_PHASE_1 = PBMetric.METRIC_AC_REACTIVE_POWER_PHASE_1
48
+ AC_REACTIVE_POWER_PHASE_2 = PBMetric.METRIC_AC_REACTIVE_POWER_PHASE_2
49
+ AC_REACTIVE_POWER_PHASE_3 = PBMetric.METRIC_AC_REACTIVE_POWER_PHASE_3
50
+
51
+ # AC power factor
52
+ AC_POWER_FACTOR = PBMetric.METRIC_AC_POWER_FACTOR
53
+ AC_POWER_FACTOR_PHASE_1 = PBMetric.METRIC_AC_POWER_FACTOR_PHASE_1
54
+ AC_POWER_FACTOR_PHASE_2 = PBMetric.METRIC_AC_POWER_FACTOR_PHASE_2
55
+ AC_POWER_FACTOR_PHASE_3 = PBMetric.METRIC_AC_POWER_FACTOR_PHASE_3
56
+
57
+ # AC energy metrics
58
+ AC_APPARENT_ENERGY = PBMetric.METRIC_AC_APPARENT_ENERGY
59
+ AC_APPARENT_ENERGY_PHASE_1 = PBMetric.METRIC_AC_APPARENT_ENERGY_PHASE_1
60
+ AC_APPARENT_ENERGY_PHASE_2 = PBMetric.METRIC_AC_APPARENT_ENERGY_PHASE_2
61
+ AC_APPARENT_ENERGY_PHASE_3 = PBMetric.METRIC_AC_APPARENT_ENERGY_PHASE_3
62
+ AC_ACTIVE_ENERGY = PBMetric.METRIC_AC_ACTIVE_ENERGY
63
+ AC_ACTIVE_ENERGY_PHASE_1 = PBMetric.METRIC_AC_ACTIVE_ENERGY_PHASE_1
64
+ AC_ACTIVE_ENERGY_PHASE_2 = PBMetric.METRIC_AC_ACTIVE_ENERGY_PHASE_2
65
+ AC_ACTIVE_ENERGY_PHASE_3 = PBMetric.METRIC_AC_ACTIVE_ENERGY_PHASE_3
66
+ AC_ACTIVE_ENERGY_CONSUMED = PBMetric.METRIC_AC_ACTIVE_ENERGY_CONSUMED
67
+ AC_ACTIVE_ENERGY_CONSUMED_PHASE_1 = (
68
+ PBMetric.METRIC_AC_ACTIVE_ENERGY_CONSUMED_PHASE_1
69
+ )
70
+ AC_ACTIVE_ENERGY_CONSUMED_PHASE_2 = (
71
+ PBMetric.METRIC_AC_ACTIVE_ENERGY_CONSUMED_PHASE_2
72
+ )
73
+ AC_ACTIVE_ENERGY_CONSUMED_PHASE_3 = (
74
+ PBMetric.METRIC_AC_ACTIVE_ENERGY_CONSUMED_PHASE_3
75
+ )
76
+ AC_ACTIVE_ENERGY_DELIVERED = PBMetric.METRIC_AC_ACTIVE_ENERGY_DELIVERED
77
+ AC_ACTIVE_ENERGY_DELIVERED_PHASE_1 = (
78
+ PBMetric.METRIC_AC_ACTIVE_ENERGY_DELIVERED_PHASE_1
79
+ )
80
+ AC_ACTIVE_ENERGY_DELIVERED_PHASE_2 = (
81
+ PBMetric.METRIC_AC_ACTIVE_ENERGY_DELIVERED_PHASE_2
82
+ )
83
+ AC_ACTIVE_ENERGY_DELIVERED_PHASE_3 = (
84
+ PBMetric.METRIC_AC_ACTIVE_ENERGY_DELIVERED_PHASE_3
85
+ )
86
+ AC_REACTIVE_ENERGY = PBMetric.METRIC_AC_REACTIVE_ENERGY
87
+ AC_REACTIVE_ENERGY_PHASE_1 = PBMetric.METRIC_AC_REACTIVE_ENERGY_PHASE_1
88
+ AC_REACTIVE_ENERGY_PHASE_2 = PBMetric.METRIC_AC_REACTIVE_ENERGY_PHASE_2
89
+ AC_REACTIVE_ENERGY_PHASE_3 = PBMetric.METRIC_AC_REACTIVE_ENERGY_PHASE_3
90
+
91
+ # AC harmonics
92
+ AC_THD_CURRENT = PBMetric.METRIC_AC_THD_CURRENT
93
+ AC_THD_CURRENT_PHASE_1 = PBMetric.METRIC_AC_THD_CURRENT_PHASE_1
94
+ AC_THD_CURRENT_PHASE_2 = PBMetric.METRIC_AC_THD_CURRENT_PHASE_2
95
+ AC_THD_CURRENT_PHASE_3 = PBMetric.METRIC_AC_THD_CURRENT_PHASE_3
96
+
97
+ # General BMS metrics
98
+ BATTERY_CAPACITY = PBMetric.METRIC_BATTERY_CAPACITY
99
+ BATTERY_SOC_PCT = PBMetric.METRIC_BATTERY_SOC_PCT
100
+ BATTERY_TEMPERATURE = PBMetric.METRIC_BATTERY_TEMPERATURE
101
+
102
+ # General inverter metrics
103
+ INVERTER_TEMPERATURE = PBMetric.METRIC_INVERTER_TEMPERATURE
104
+ INVERTER_TEMPERATURE_CABINET = PBMetric.METRIC_INVERTER_TEMPERATURE_CABINET
105
+ INVERTER_TEMPERATURE_HEATSINK = PBMetric.METRIC_INVERTER_TEMPERATURE_HEATSINK
106
+ INVERTER_TEMPERATURE_TRANSFORMER = PBMetric.METRIC_INVERTER_TEMPERATURE_TRANSFORMER
107
+
108
+ # EV charging station metrics
109
+ EV_CHARGER_TEMPERATURE = PBMetric.METRIC_EV_CHARGER_TEMPERATURE
110
+
111
+ # General sensor metrics
112
+ SENSOR_WIND_SPEED = PBMetric.METRIC_SENSOR_WIND_SPEED
113
+ SENSOR_WIND_DIRECTION = PBMetric.METRIC_SENSOR_WIND_DIRECTION
114
+ SENSOR_TEMPERATURE = PBMetric.METRIC_SENSOR_TEMPERATURE
115
+ SENSOR_RELATIVE_HUMIDITY = PBMetric.METRIC_SENSOR_RELATIVE_HUMIDITY
116
+ SENSOR_DEW_POINT = PBMetric.METRIC_SENSOR_DEW_POINT
117
+ SENSOR_AIR_PRESSURE = PBMetric.METRIC_SENSOR_AIR_PRESSURE
118
+ SENSOR_IRRADIANCE = PBMetric.METRIC_SENSOR_IRRADIANCE
119
+
120
+ @classmethod
121
+ def from_proto(cls, metric: PBMetric.ValueType) -> Self:
122
+ """Convert a protobuf Metric value to Metric enum.
123
+
124
+ Args:
125
+ metric: Metric to convert.
126
+ Returns:
127
+ Enum value corresponding to the protobuf message.
128
+ """
129
+ if not any(m.value == metric for m in cls):
130
+ return cls(Metric.UNSPECIFIED)
131
+
132
+ return cls(metric)
133
+
134
+ def to_proto(self) -> PBMetric.ValueType:
135
+ """Convert a Metric object to protobuf Metric.
136
+
137
+ Returns:
138
+ Protobuf message corresponding to the Metric object.
139
+ """
140
+ return self.value
@@ -0,0 +1,4 @@
1
+ # License: MIT
2
+ # Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3
+
4
+ """Frequenz microgrid definition."""
@@ -0,0 +1,67 @@
1
+ # License: MIT
2
+ # Copyright © 2022 Frequenz Energy-as-a-Service GmbH
3
+
4
+ """Defines the components that can be used in a microgrid."""
5
+ from __future__ import annotations
6
+
7
+ from enum import Enum
8
+
9
+ # pylint: disable=no-name-in-module
10
+ from frequenz.api.common.v1.microgrid.components.components_pb2 import (
11
+ ComponentCategory as PBComponentCategory,
12
+ )
13
+
14
+ # pylint: enable=no-name-in-module
15
+
16
+
17
+ class ComponentCategory(Enum):
18
+ """Possible types of microgrid component."""
19
+
20
+ UNSPECIFIED = PBComponentCategory.COMPONENT_CATEGORY_UNSPECIFIED
21
+ """An unknown component category.
22
+
23
+ Useful for error handling, and marking unknown components in
24
+ a list of components with otherwise known categories.
25
+ """
26
+
27
+ GRID = PBComponentCategory.COMPONENT_CATEGORY_GRID
28
+ """The point where the local microgrid is connected to the grid."""
29
+
30
+ METER = PBComponentCategory.COMPONENT_CATEGORY_METER
31
+ """A meter, for measuring electrical metrics, e.g., current, voltage, etc."""
32
+
33
+ INVERTER = PBComponentCategory.COMPONENT_CATEGORY_INVERTER
34
+ """An electricity generator, with batteries or solar energy."""
35
+
36
+ BATTERY = PBComponentCategory.COMPONENT_CATEGORY_BATTERY
37
+ """A storage system for electrical energy, used by inverters."""
38
+
39
+ EV_CHARGER = PBComponentCategory.COMPONENT_CATEGORY_EV_CHARGER
40
+ """A station for charging electrical vehicles."""
41
+
42
+ CHP = PBComponentCategory.COMPONENT_CATEGORY_CHP
43
+ """A heat and power combustion plant (CHP stands for combined heat and power)."""
44
+
45
+ @classmethod
46
+ def from_proto(
47
+ cls, component_category: PBComponentCategory.ValueType
48
+ ) -> ComponentCategory:
49
+ """Convert a protobuf ComponentCategory message to ComponentCategory enum.
50
+
51
+ Args:
52
+ component_category: protobuf enum to convert
53
+
54
+ Returns:
55
+ Enum value corresponding to the protobuf message.
56
+ """
57
+ if not any(t.value == component_category for t in ComponentCategory):
58
+ return ComponentCategory.UNSPECIFIED
59
+ return cls(component_category)
60
+
61
+ def to_proto(self) -> PBComponentCategory.ValueType:
62
+ """Convert a ComponentCategory enum to protobuf ComponentCategory message.
63
+
64
+ Returns:
65
+ Enum value corresponding to the protobuf message.
66
+ """
67
+ return self.value
@@ -0,0 +1,87 @@
1
+ # License: MIT
2
+ # Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3
+
4
+ """Module to define the pagination used with the common client."""
5
+
6
+ from __future__ import annotations # required for constructor type hinting
7
+
8
+ from dataclasses import dataclass
9
+ from typing import Self
10
+
11
+ # pylint: disable=no-name-in-module
12
+ from frequenz.api.common.v1.pagination.pagination_info_pb2 import PaginationInfo
13
+ from frequenz.api.common.v1.pagination.pagination_params_pb2 import PaginationParams
14
+
15
+ # pylint: enable=no-name-in-module
16
+
17
+
18
+ @dataclass(frozen=True, kw_only=True)
19
+ class Params:
20
+ """Parameters for paginating list requests."""
21
+
22
+ page_size: int | None = None
23
+ """The maximum number of results to be returned per request."""
24
+
25
+ page_token: str | None = None
26
+ """The token identifying a specific page of the list results."""
27
+
28
+ @classmethod
29
+ def from_proto(cls, pagination_params: PaginationParams) -> Self:
30
+ """Convert a protobuf Params to PaginationParams object.
31
+
32
+ Args:
33
+ pagination_params: Params to convert.
34
+ Returns:
35
+ Params object corresponding to the protobuf message.
36
+ """
37
+ return cls(
38
+ page_size=pagination_params.page_size,
39
+ page_token=pagination_params.page_token,
40
+ )
41
+
42
+ def to_proto(self) -> PaginationParams:
43
+ """Convert a Params object to protobuf PaginationParams.
44
+
45
+ Returns:
46
+ Protobuf message corresponding to the Params object.
47
+ """
48
+ return PaginationParams(
49
+ page_size=self.page_size,
50
+ page_token=self.page_token,
51
+ )
52
+
53
+
54
+ @dataclass(frozen=True, kw_only=True)
55
+ class Info:
56
+ """Information about the pagination of a list request."""
57
+
58
+ total_items: int
59
+ """The total number of items that match the request."""
60
+
61
+ next_page_token: str | None = None
62
+ """The token identifying the next page of results."""
63
+
64
+ @classmethod
65
+ def from_proto(cls, pagination_info: PaginationInfo) -> Self:
66
+ """Convert a protobuf PBPaginationInfo to Info object.
67
+
68
+ Args:
69
+ pagination_info: Info to convert.
70
+ Returns:
71
+ Info object corresponding to the protobuf message.
72
+ """
73
+ return cls(
74
+ total_items=pagination_info.total_items,
75
+ next_page_token=pagination_info.next_page_token,
76
+ )
77
+
78
+ def to_proto(self) -> PaginationInfo:
79
+ """Convert a Info object to protobuf PBPaginationInfo.
80
+
81
+ Returns:
82
+ Protobuf message corresponding to the Info object.
83
+ """
84
+ return PaginationInfo(
85
+ total_items=self.total_items,
86
+ next_page_token=self.next_page_token,
87
+ )
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.1
2
+ Name: frequenz-client-common
3
+ Version: 0.1.0
4
+ Summary: Common code and utilities for Frequenz API clients
5
+ Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
6
+ License: MIT
7
+ Project-URL: Documentation, https://frequenz-floss.github.io/frequenz-client-common-python/
8
+ Project-URL: Changelog, https://github.com/frequenz-floss/frequenz-client-common-python/releases
9
+ Project-URL: Issues, https://github.com/frequenz-floss/frequenz-client-common-python/issues
10
+ Project-URL: Repository, https://github.com/frequenz-floss/frequenz-client-common-python
11
+ Project-URL: Support, https://github.com/frequenz-floss/frequenz-client-common-python/discussions/categories/support
12
+ Keywords: frequenz,python,lib,library,client-common
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: <4,>=3.11
21
+ Description-Content-Type: text/markdown
22
+ Provides-Extra: dev-flake8
23
+ Provides-Extra: dev-formatting
24
+ Provides-Extra: dev-mkdocs
25
+ Provides-Extra: dev-mypy
26
+ Provides-Extra: dev-noxfile
27
+ Provides-Extra: dev-pylint
28
+ Provides-Extra: dev-pytest
29
+ Provides-Extra: dev
30
+ License-File: LICENSE
31
+
32
+ # Frequenz Client Common Library
33
+
34
+ [![Build Status](https://github.com/frequenz-floss/frequenz-client-common-python/actions/workflows/ci.yaml/badge.svg)](https://github.com/frequenz-floss/frequenz-client-common-python/actions/workflows/ci.yaml)
35
+ [![PyPI Package](https://img.shields.io/pypi/v/frequenz-client-common)](https://pypi.org/project/frequenz-client-common/)
36
+ [![Docs](https://img.shields.io/badge/docs-latest-informational)](https://frequenz-floss.github.io/frequenz-client-common-python/)
37
+
38
+ ## Introduction
39
+
40
+ Common code and utilities for Frequenz API clients
41
+
42
+ TODO(cookiecutter): Improve the README file
43
+
44
+ ## Supported Platforms
45
+
46
+ The following platforms are officially supported (tested):
47
+
48
+ - **Python:** 3.11
49
+ - **Operating System:** Ubuntu Linux 20.04
50
+ - **Architectures:** amd64, arm64
51
+
52
+ ## Contributing
53
+
54
+ If you want to know how to build this project and contribute to it, please
55
+ check out the [Contributing Guide](CONTRIBUTING.md).
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ RELEASE_NOTES.md
5
+ pyproject.toml
6
+ src/frequenz/client/common/__init__.py
7
+ src/frequenz/client/common/conftest.py
8
+ src/frequenz/client/common/py.typed
9
+ src/frequenz/client/common/metric/__init__.py
10
+ src/frequenz/client/common/microgrid/__init__.py
11
+ src/frequenz/client/common/microgrid/components/__init__.py
12
+ src/frequenz/client/common/pagination/__init__.py
13
+ src/frequenz_client_common.egg-info/PKG-INFO
14
+ src/frequenz_client_common.egg-info/SOURCES.txt
15
+ src/frequenz_client_common.egg-info/dependency_links.txt
16
+ src/frequenz_client_common.egg-info/requires.txt
17
+ src/frequenz_client_common.egg-info/top_level.txt
@@ -0,0 +1,47 @@
1
+ typing-extensions<5,>=4.5.0
2
+ frequenz-api-common<6,>=0.5.4
3
+
4
+ [dev]
5
+ frequenz-client-common[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]
6
+
7
+ [dev-flake8]
8
+ flake8==7.0.0
9
+ flake8-docstrings==1.7.0
10
+ flake8-pyproject==1.2.3
11
+ pydoclint==0.4.1
12
+ pydocstyle==6.3.0
13
+
14
+ [dev-formatting]
15
+ black==24.2.0
16
+ isort==5.13.2
17
+
18
+ [dev-mkdocs]
19
+ black==24.2.0
20
+ Markdown==3.5.2
21
+ mike==2.0.0
22
+ mkdocs-gen-files==0.5.0
23
+ mkdocs-literate-nav==0.6.1
24
+ mkdocs-macros-plugin==1.0.5
25
+ mkdocs-material==9.5.12
26
+ mkdocstrings[python]==0.24.1
27
+ frequenz-repo-config[lib]==0.9.1
28
+
29
+ [dev-mypy]
30
+ mypy==1.8.0
31
+ types-Markdown==3.5.0.20240129
32
+ frequenz-client-common[dev-mkdocs,dev-noxfile,dev-pytest]
33
+
34
+ [dev-noxfile]
35
+ nox==2023.4.22
36
+ frequenz-repo-config[lib]==0.9.1
37
+
38
+ [dev-pylint]
39
+ pylint==3.1.0
40
+ frequenz-client-common[dev-mkdocs,dev-noxfile,dev-pytest]
41
+
42
+ [dev-pytest]
43
+ pytest==8.1.0
44
+ frequenz-repo-config[extra-lint-examples]==0.9.1
45
+ pytest-mock==3.12.0
46
+ pytest-asyncio==0.23.5
47
+ async-solipsism==0.5