-
Notifications
You must be signed in to change notification settings - Fork 5
Add sensors listing and data streaming #144
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
Changes from all commits
e5af5ca
258939f
aaf52ad
025b072
17e05e8
0aca677
474f16a
f3f15b9
06f7bd1
218ce82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # License: MIT | ||
| # Copyright © 2025 Frequenz Energy-as-a-Service GmbH | ||
|
|
||
| """Lifetime of a microgrid asset.""" | ||
|
|
||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import datetime, timezone | ||
| from functools import cached_property | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class Lifetime: | ||
| """An active operational period of a microgrid asset. | ||
|
|
||
| Warning: | ||
| The [`end`][frequenz.client.microgrid.Lifetime.end] timestamp indicates that the | ||
| asset has been permanently removed from the system. | ||
| """ | ||
|
|
||
| start: 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`][frequenz.client.microgrid.Lifetime.end]. | ||
| """ | ||
|
|
||
| end: 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. | ||
| """ | ||
|
|
||
| def __post_init__(self) -> None: | ||
| """Validate this lifetime.""" | ||
| if self.start is not None and self.end is not None and self.start > self.end: | ||
| raise ValueError("Start must be before or equal to end.") | ||
|
|
||
| def active_at(self, timestamp: datetime) -> bool: | ||
| """Check whether this lifetime is active at a specific timestamp.""" | ||
| if self.start is not None and self.start > timestamp: | ||
| return False | ||
| if self.end is not None: | ||
| return self.end >= timestamp | ||
| # Both are None, so it is always active | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
| return True | ||
|
|
||
| @cached_property | ||
| def active(self) -> bool: | ||
| """Whether this lifetime is currently active.""" | ||
| return self.active_at(datetime.now(timezone.utc)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be a |
||
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.
What happened to all our deployments at https://en.wikipedia.org/wiki/Null_Island? 😱
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.
We are fine, now microgrids in Null Island need to provide a explicit (0, 0) location 😆