Index
frequenz.client.common.microgrid ¤
Frequenz microgrid definition.
Classes¤
frequenz.client.common.microgrid.BaseLifetime
dataclass
¤
A base class for well-formed and malformed operational lifetimes.
This class cannot be instantiated directly. Use Lifetime
for a valid period or InvalidLifetime to preserve
malformed wire data.
Source code in src/frequenz/client/common/microgrid/_lifetime.py
Attributes¤
end_time
class-attribute
instance-attribute
¤
end_time: datetime | None = None
The moment when the asset's operational activity ceased.
If None, the asset is considered to be active with no plans to be deactivated.
start_time
class-attribute
instance-attribute
¤
start_time: datetime | None = None
The moment when the asset became operationally active.
If None, the asset is considered to be active in any past moment previous to the
end_time.
Methods:¤
__new__ ¤
Prevent instantiation of this class.
frequenz.client.common.microgrid.EnterpriseId ¤
Bases: BaseId
A unique identifier for an enterprise account.
Source code in src/frequenz/client/common/microgrid/_ids.py
Attributes¤
Methods:¤
__eq__ ¤
Check if this instance is equal to another object.
Equality is defined as being of the exact same type and having the same underlying ID.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The object to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if |
bool
|
|
Source code in frequenz/core/id.py
__hash__ ¤
__hash__() -> int
Return the hash of this instance.
The hash is based on the exact type and the underlying ID to ensure that IDs of different types but with the same numeric value have different hashes.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The hash of this instance. |
Source code in frequenz/core/id.py
__init__ ¤
__init__(id_: int) -> None
Initialize this instance.
| PARAMETER | DESCRIPTION |
|---|---|
id_
|
The numeric unique identifier.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the ID is negative. |
Source code in frequenz/core/id.py
__init_subclass__ ¤
Initialize a subclass, set its string prefix, and perform checks.
| PARAMETER | DESCRIPTION |
|---|---|
str_prefix
|
The string prefix for the ID type (e.g., "MID"). Must be unique across all ID types.
TYPE:
|
allow_custom_name
|
If True, bypasses the check that the class name must end with "Id". Defaults to False.
TYPE:
|
**kwargs
|
Forwarded to the parent's init_subclass.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in frequenz/core/id.py
__lt__ ¤
Check if this instance is less than another object.
Comparison is only defined between instances of the exact same type.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The object to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if this instance is less than |
bool
|
|
Source code in frequenz/core/id.py
__new__ ¤
Create a new instance of the ID class, only if it is a subclass of BaseId.
frequenz.client.common.microgrid.InvalidLifetime
dataclass
¤
Bases: BaseLifetime
An operational lifetime with malformed data received from the wire.
This class preserves lifetime data that fails the invariants required for
a well-formed Lifetime, allowing callers to inspect the raw
timestamps without accidentally using them for operational checks. Use a
semantic accessor, such as ElectricalComponent.get_operational_lifetime(),
to receive a clear InvalidLifetimeError.
Source code in src/frequenz/client/common/microgrid/_lifetime.py
Attributes¤
end_time
class-attribute
instance-attribute
¤
end_time: datetime | None = None
The moment when the asset's operational activity ceased.
If None, the asset is considered to be active with no plans to be deactivated.
start_time
class-attribute
instance-attribute
¤
start_time: datetime | None = None
The moment when the asset became operationally active.
If None, the asset is considered to be active in any past moment previous to the
end_time.
Methods:¤
__new__ ¤
Prevent instantiation of this class.
__str__ ¤
__str__() -> str
Return a compact string representation of this invalid lifetime.
Source code in src/frequenz/client/common/microgrid/_lifetime.py
frequenz.client.common.microgrid.InvalidLifetimeError ¤
Bases: InvalidAttributeError
Raised when a semantic accessor sees an invalid lifetime.
The offending InvalidLifetime is available as the
lifetime attribute so callers can inspect the raw wire data.
This is also a ValueError for convenience.
Source code in src/frequenz/client/common/microgrid/_lifetime.py
Attributes¤
attr_name
instance-attribute
¤
attr_name: str = attr_name
The name of the attribute that had an invalid value.
instance
instance-attribute
¤
instance: object = instance
The object instance that had an invalid value.
lifetime
instance-attribute
¤
lifetime: InvalidLifetime = lifetime
The invalid lifetime that caused this error.
Methods:¤
__init__ ¤
__init__(
instance: object,
attr_name: str,
lifetime: InvalidLifetime,
message: str | None = None,
) -> None
Initialize this error.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The instance that was being accessed when this error was raised.
TYPE:
|
attr_name
|
The name of the attribute that was being accessed.
TYPE:
|
lifetime
|
The invalid lifetime instance.
TYPE:
|
message
|
A custom error message. If
TYPE:
|
Source code in src/frequenz/client/common/microgrid/_lifetime.py
frequenz.client.common.microgrid.Lifetime
dataclass
¤
Bases: BaseLifetime
An active operational period of an asset.
When both start_time and end_time are
None, the lifetime is unbounded and the asset is considered operational
at every timestamp.
Warning
The end_time timestamp indicates that the asset has been
permanently removed from service.
Note
Raises a ValueError if start_time is later than the
end_time timestamp. Use
InvalidLifetime to represent malformed lifetime
data received from the wire.
Source code in src/frequenz/client/common/microgrid/_lifetime.py
Attributes¤
end_time
class-attribute
instance-attribute
¤
end_time: datetime | None = None
The moment when the asset's operational activity ceased.
If None, the asset is considered to be active with no plans to be deactivated.
start_time
class-attribute
instance-attribute
¤
start_time: datetime | None = None
The moment when the asset became operationally active.
If None, the asset is considered to be active in any past moment previous to the
end_time.
Methods:¤
__new__ ¤
Prevent instantiation of this class.
__post_init__ ¤
Validate this lifetime.
Source code in src/frequenz/client/common/microgrid/_lifetime.py
__str__ ¤
__str__() -> str
Return a compact string representation of this lifetime.
Source code in src/frequenz/client/common/microgrid/_lifetime.py
is_operational_at ¤
Check whether this lifetime is active at a specific timestamp.
Source code in src/frequenz/client/common/microgrid/_lifetime.py
frequenz.client.common.microgrid.Microgrid
dataclass
¤
A localized grouping of electricity generation, energy storage, and loads.
A microgrid is a localized grouping of electricity generation, energy storage, and loads that normally operates connected to a traditional centralized grid.
Each microgrid has a unique identifier and is associated with an enterprise account.
A key feature is that it has a physical location and is situated in a delivery area.
Key Concepts
- Physical Location: Geographical coordinates specify the exact physical location of the microgrid.
- Delivery Area: Each microgrid is part of a broader delivery area, which is crucial for energy trading and compliance.
Source code in src/frequenz/client/common/microgrid/_microgrid.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
Attributes¤
create_time
instance-attribute
¤
create_time: datetime
The UTC timestamp indicating when the microgrid was initially created.
delivery_area
instance-attribute
¤
delivery_area: DeliveryArea | InvalidDeliveryArea | None
The delivery area where the microgrid is located.
None means the field was not set on the wire. An
InvalidDeliveryArea means the wire
carried a delivery area that fails its invariants.
Tip
This is the lower-level field; prefer get_delivery_area()
to obtain a valid DeliveryArea or a clear error.
enterprise_id
instance-attribute
¤
enterprise_id: EnterpriseId
The unique identifier linking this microgrid to its parent enterprise account.
location
instance-attribute
¤
location: Location | None
The physical location of the microgrid, in geographical co-ordinates.
Methods:¤
__post_init__ ¤
Reject direct construction of this read-only type.
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the instance was not created via the
|
Source code in src/frequenz/client/common/microgrid/_microgrid.py
get_delivery_area ¤
get_delivery_area() -> DeliveryArea
Return the delivery area as a well-formed DeliveryArea.
This is the higher-level accessor for the delivery_area
attribute: it resolves the field to a valid
DeliveryArea or raises a clear, catchable error.
| RETURNS | DESCRIPTION |
|---|---|
DeliveryArea
|
The delivery area, when it is a well-formed
|
| RAISES | DESCRIPTION |
|---|---|
MissingFieldError
|
If the delivery area is not set ( |
InvalidDeliveryAreaError
|
If the delivery area is an
|
Source code in src/frequenz/client/common/microgrid/_microgrid.py
get_delivery_area_or_none ¤
get_delivery_area_or_none() -> DeliveryArea | None
Return the delivery area as a well-formed DeliveryArea, or None.
This is the higher-level accessor for the delivery_area
attribute that tolerates a missing field: it resolves the field to a
valid DeliveryArea, returns None when the
field was not set on the wire, or raises a clear, catchable error when
the field carries an invalid delivery area.
| RETURNS | DESCRIPTION |
|---|---|
DeliveryArea | None
|
The delivery area when it is a well-formed
|
| RAISES | DESCRIPTION |
|---|---|
InvalidDeliveryAreaError
|
If the delivery area is an
|
Source code in src/frequenz/client/common/microgrid/_microgrid.py
get_location ¤
get_location() -> Location
Return the location as a Location.
This is the higher-level accessor for the location
attribute: it resolves the field to a
Location or raises a clear, catchable error.
The returned instance may still carry raw wire values that fail the
Location field invariants; use its own
get_*() accessors to obtain validated coordinates and country code.
| RETURNS | DESCRIPTION |
|---|---|
Location
|
The location, when it is set. |
| RAISES | DESCRIPTION |
|---|---|
MissingFieldError
|
If the location is not set ( |
Source code in src/frequenz/client/common/microgrid/_microgrid.py
is_active ¤
is_active() -> bool
Return whether the microgrid is active.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether the microgrid is active. |
| RAISES | DESCRIPTION |
|---|---|
UnspecifiedEnumValueError
|
If the status is unspecified. |
UnrecognizedEnumValueError
|
If the status is not recognized. The raw
status value is available on the error's |
Source code in src/frequenz/client/common/microgrid/_microgrid.py
frequenz.client.common.microgrid.MicrogridId ¤
Bases: BaseId
A unique identifier for a microgrid.
Source code in src/frequenz/client/common/microgrid/_ids.py
Attributes¤
Methods:¤
__eq__ ¤
Check if this instance is equal to another object.
Equality is defined as being of the exact same type and having the same underlying ID.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The object to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if |
bool
|
|
Source code in frequenz/core/id.py
__hash__ ¤
__hash__() -> int
Return the hash of this instance.
The hash is based on the exact type and the underlying ID to ensure that IDs of different types but with the same numeric value have different hashes.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The hash of this instance. |
Source code in frequenz/core/id.py
__init__ ¤
__init__(id_: int) -> None
Initialize this instance.
| PARAMETER | DESCRIPTION |
|---|---|
id_
|
The numeric unique identifier.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the ID is negative. |
Source code in frequenz/core/id.py
__init_subclass__ ¤
Initialize a subclass, set its string prefix, and perform checks.
| PARAMETER | DESCRIPTION |
|---|---|
str_prefix
|
The string prefix for the ID type (e.g., "MID"). Must be unique across all ID types.
TYPE:
|
allow_custom_name
|
If True, bypasses the check that the class name must end with "Id". Defaults to False.
TYPE:
|
**kwargs
|
Forwarded to the parent's init_subclass.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in frequenz/core/id.py
__lt__ ¤
Check if this instance is less than another object.
Comparison is only defined between instances of the exact same type.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
The object to compare against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if this instance is less than |
bool
|
|
Source code in frequenz/core/id.py
__new__ ¤
Create a new instance of the ID class, only if it is a subclass of BaseId.