Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/frequenz/client/common/microgrid/_microgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,27 @@ def get_delivery_area_or_none(self) -> DeliveryArea | None:
case unknown:
assert_never(unknown)

def get_location(self) -> Location:
"""Return the location as a [`Location`][....types.Location].

This is the higher-level accessor for the [`location`][..location]
attribute: it resolves the field to a
[`Location`][....types.Location] or raises a clear, catchable error.

The returned instance may still carry raw wire values that fail the
[`Location`][....types.Location] field invariants; use its own
`get_*()` accessors to obtain validated coordinates and country code.

Returns:
The location, when it is set.

Raises:
MissingFieldError: If the location is not set (`None`).
"""
if self.location is None:
raise MissingFieldError(self, "location")
return self.location

def __str__(self) -> str:
"""Return the ID of this microgrid as a string."""
name = f":{self.name}" if self.name else ""
Expand Down
16 changes: 15 additions & 1 deletion src/frequenz/client/common/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
"""Common types."""

from ._lifetime import Lifetime
from ._location import Location
from ._location import (
InvalidCountryCode,
InvalidCountryCodeError,
InvalidLatitude,
InvalidLatitudeError,
InvalidLongitude,
InvalidLongitudeError,
Location,
)

__all__ = [
"InvalidCountryCode",
"InvalidCountryCodeError",
"InvalidLatitude",
"InvalidLatitudeError",
"InvalidLongitude",
"InvalidLongitudeError",
"Lifetime",
"Location",
]
Loading
Loading