Skip to content

Commit ec129d1

Browse files
committed
Add microgrid-related ID types
Adds: EnterpriseId, MicrogridId, ComponentId and SensorId. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent fd68238 commit ec129d1

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ requires-python = ">= 3.11, < 4"
2828
dependencies = [
2929
"typing-extensions >= 4.6.0, < 5",
3030
"frequenz-api-common >= 0.6.0, < 7",
31+
"frequenz-core >= 1.0.0, < 2",
3132
]
3233
dynamic = ["version"]
3334

src/frequenz/client/common/microgrid/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,17 @@
22
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
33

44
"""Frequenz microgrid definition."""
5+
6+
from typing import final
7+
8+
from frequenz.core.id import BaseId
9+
10+
11+
@final
12+
class EnterpriseId(BaseId, str_prefix="EID"):
13+
"""A unique identifier for an enterprise account."""
14+
15+
16+
@final
17+
class MicrogridId(BaseId, str_prefix="MID"):
18+
"""A unique identifier for a microgrid."""

src/frequenz/client/common/microgrid/components/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# Copyright © 2022 Frequenz Energy-as-a-Service GmbH
33

44
"""Defines the components that can be used in a microgrid."""
5+
56
from __future__ import annotations
67

78
from enum import Enum
9+
from typing import final
810

911
# pylint: disable=no-name-in-module
1012
from frequenz.api.common.v1.microgrid.components.components_pb2 import (
@@ -16,10 +18,16 @@
1618
from frequenz.api.common.v1.microgrid.components.components_pb2 import (
1719
ComponentStateCode as PBComponentStateCode,
1820
)
21+
from frequenz.core.id import BaseId
1922

2023
# pylint: enable=no-name-in-module
2124

2225

26+
@final
27+
class ComponentId(BaseId, str_prefix="CID"):
28+
"""A unique identifier for a microgrid component."""
29+
30+
2331
class ComponentCategory(Enum):
2432
"""Possible types of microgrid component."""
2533

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Microgrid sensors."""
5+
6+
from typing import final
7+
8+
from frequenz.core.id import BaseId
9+
10+
11+
@final
12+
class SensorId(BaseId, str_prefix="SID"):
13+
"""A unique identifier for a microgrid sensor."""

tests/microgrid/test_ids.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Tests for microgrid-related IDs."""
5+
6+
import pytest
7+
from frequenz.core.id import BaseId
8+
9+
from frequenz.client.common.microgrid import EnterpriseId, MicrogridId
10+
from frequenz.client.common.microgrid.components import ComponentId
11+
from frequenz.client.common.microgrid.sensors import SensorId
12+
13+
14+
@pytest.mark.parametrize(
15+
"id_class, prefix",
16+
[
17+
(EnterpriseId, "EID"),
18+
(MicrogridId, "MID"),
19+
(ComponentId, "CID"),
20+
(SensorId, "SID"),
21+
],
22+
)
23+
def test_string_representation(id_class: type[BaseId], prefix: str) -> None:
24+
"""Test string representation of IDs."""
25+
_id = id_class(123)
26+
27+
assert str(_id) == f"{prefix}123"
28+
assert repr(_id) == f"{id_class.__name__}(123)"

0 commit comments

Comments
 (0)