-
Notifications
You must be signed in to change notification settings - Fork 17
Fetch and expose microgrid ID and location #708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
daniel-zullo-frequenz
merged 6 commits into
frequenz-floss:v1.x.x
from
daniel-zullo-frequenz:feature/microgrid-metadata
Nov 7, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e416543
Add microgrid metadata types
daniel-zullo-frequenz bd02b9d
Add function to retrieve the microgrid metadata
daniel-zullo-frequenz 8d82f90
Fetch metadata when connecting to the microgrid
daniel-zullo-frequenz 9bcaeeb
Expose microgrid ID and location
daniel-zullo-frequenz dd9a4da
Amend tests to reflect microgrid metadata changes
daniel-zullo-frequenz d0284c9
Update release notes
daniel-zullo-frequenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# License: MIT | ||
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH | ||
|
||
"""Metadata that describes a microgrid.""" | ||
|
||
from dataclasses import dataclass | ||
from zoneinfo import ZoneInfo | ||
|
||
from timezonefinder import TimezoneFinder | ||
|
||
_timezone_finder = TimezoneFinder() | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class Location: | ||
"""Metadata for the location of microgrid.""" | ||
|
||
latitude: float | None = None | ||
"""The latitude of the microgrid in degree.""" | ||
|
||
longitude: float | None = None | ||
"""The longitude of the microgrid in degree.""" | ||
|
||
timezone: ZoneInfo | None = None | ||
"""The timezone of the microgrid. | ||
|
||
The timezone will be set to None if the latitude or longitude points | ||
are not set or the timezone cannot be found given the location points. | ||
""" | ||
|
||
def __post_init__(self) -> None: | ||
"""Initialize the timezone of the microgrid.""" | ||
if self.latitude is None or self.longitude is None or self.timezone is not None: | ||
return | ||
|
||
timezone = _timezone_finder.timezone_at(lat=self.latitude, lng=self.longitude) | ||
if timezone: | ||
# The dataclass is frozen, so it needs to use __setattr__ to set the timezone. | ||
object.__setattr__(self, "timezone", ZoneInfo(key=timezone)) | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class Metadata: | ||
"""Metadata for the microgrid.""" | ||
|
||
microgrid_id: int | None = None | ||
"""The ID of the microgrid.""" | ||
|
||
location: Location | None = None | ||
"""The location of the microgrid.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is being used all over the place in the SDK, but if we use this instead, then we don't need the
# pylint disable=...
:Maybe we can create an issue to change it in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #774
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not there, but we will need it later, where we say
empty_pb2.Empty
, I think it just moves the hint to a different place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think some symbols are dynamically generated and
pylint
falis to see them at the import level, but once it is imported it works fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked it and Sahas is right, this just moves the pylint error to the place
empty_pb2.Empty
is used, so fromno-name-in-module
tono-member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I also saw that, I closed #774 as invalid, and it seems
pylnt
3 should fix the issue, but a preliminary test didn't work. We'll see.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the follow up!