File tree Expand file tree Collapse file tree 5 files changed +64
-0
lines changed
src/frequenz/client/common/microgrid Expand file tree Collapse file tree 5 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ requires-python = ">= 3.11, < 4"
2828dependencies = [
2929 " typing-extensions >= 4.6.0, < 5" ,
3030 " frequenz-api-common >= 0.6.0, < 7" ,
31+ " frequenz-core >= 1.0.0, < 2" ,
3132]
3233dynamic = [" version" ]
3334
Original file line number Diff line number Diff line change 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."""
Original file line number Diff line number Diff line change 22# Copyright © 2022 Frequenz Energy-as-a-Service GmbH
33
44"""Defines the components that can be used in a microgrid."""
5+
56from __future__ import annotations
67
78from enum import Enum
9+ from typing import final
810
911# pylint: disable=no-name-in-module
1012from frequenz .api .common .v1 .microgrid .components .components_pb2 import (
1618from 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+
2331class ComponentCategory (Enum ):
2432 """Possible types of microgrid component."""
2533
Original file line number Diff line number Diff line change 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."""
Original file line number Diff line number Diff line change 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)"
You can’t perform that action at this time.
0 commit comments