Expose operational mode through individual properties - #291
Merged
Conversation
llucax
requested review from
ela-kotulska-frequenz and
hannah-stevenson-frequenz
and removed request for
a team
July 22, 2026 10:48
The operational mode field and the ElectricalComponentOperationalMode enum were added to the ElectricalComponent protobuf message in frequenz-api-common v0.8.3, but the enum value ELECTRICAL_COMPONENT_OPERATIONAL_MODE_TELEMETRY_ONLY was misspelled (TELEMTRY) in that release and only corrected in v0.8.4. The client now reads that field and references the enum by name, so require v0.8.4 as the minimum version. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Using the operational mode protobuf enum as a component attribute is not very convenient. Users would need to check for multiple combinations to find out whether telemetry or control is available, plus handle the unspecified value, which should be rare but is possible. Instead, keep the operational mode representation entirely in the protobuf conversion layer and expose it through two Component accessors that are much safer to use: - `provides_telemetry()`: whether the component provides telemetry data - `accepts_control()`: whether the component accepts control commands Both raise `ValueError` when the operational mode is unspecified or unrecognized, so callers get an explicit failure instead of a silently wrong boolean. The mode is stored internally as two private `bool | None` fields that default to `None` (unspecified), so existing component construction sites remain unaffected. This is a port of commit [5c729ba][] from `frequenz-client-common`, so we upgrade to it the migration should be smooth. [5c729ba]: frequenz-floss/frequenz-client-common-python@5c729ba Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Contributor
Author
|
One thing to have is mind is that these methods raise a built-in |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Using the operational mode protobuf enum as a component attribute is not very convenient. Users would need to check for multiple combinations to find out whether telemetry or control is available, plus handle the unspecified value, which should be rare but is possible.
Instead, keep the operational mode representation entirely in the protobuf conversion layer and expose it through two Component accessors that are much safer to use:
provides_telemetry(): whether the component provides telemetry dataaccepts_control(): whether the component accepts control commandsBoth raise
ValueErrorwhen the operational mode is unspecified or unrecognized, so callers get an explicit failure instead of a silently wrong boolean. The mode is stored internally as two privatebool | Nonefields that default toNone(unspecified), so existing component construction sites remain unaffected.This is a port of commit 5c729ba from
frequenz-client-common, so we upgrade to it the migration should be smooth.