-
-
Notifications
You must be signed in to change notification settings - Fork 92
Battery curve support for string keys, unit testing fixes #3126
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
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -831,36 +831,6 @@ def str2time(str): | |||||||||||||||||||||
| return tdata | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def get_curve_value(curve, key, default=1.0): | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| Get a value from a battery power curve dictionary. | ||||||||||||||||||||||
| Supports both integer and string keys for compatibility with YAML configurations. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Args: | ||||||||||||||||||||||
| curve: Dictionary containing the power curve (e.g., battery_charge_power_curve) | ||||||||||||||||||||||
| key: Integer SOC percentage to look up | ||||||||||||||||||||||
| default: Default value if key not found (default: 1.0) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||
| The curve value at the given SOC percentage, or default if not found | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Note: | ||||||||||||||||||||||
| This function handles both integer keys (100, 99, 98) and string keys ("100", "99", "98") | ||||||||||||||||||||||
| to support YAML configurations that require string keys for encryption (e.g., SOPS). | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| # Try integer key first (most common case) | ||||||||||||||||||||||
| if key in curve: | ||||||||||||||||||||||
| return curve[key] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Try string key for YAML configs with string-based keys | ||||||||||||||||||||||
| str_key = str(key) | ||||||||||||||||||||||
| if str_key in curve: | ||||||||||||||||||||||
| return curve[str_key] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Return default if neither found | ||||||||||||||||||||||
| return default | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def calc_percent_limit(charge_limit, soc_max): | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| Calculate a charge limit in percent | ||||||||||||||||||||||
|
|
@@ -974,18 +944,35 @@ def get_discharge_rate_curve(soc, discharge_rate_setting, soc_max, battery_rate_ | |||||||||||||||||||||
| return max(min(discharge_rate_setting, max_discharge_rate), battery_rate_min) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| Get value from curve with integer or string index | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def get_curve_value(curve, index, default=1.0): | ||||||||||||||||||||||
| if index in curve: | ||||||||||||||||||||||
| return curve[index] | ||||||||||||||||||||||
|
Comment on lines
+948
to
+954
|
||||||||||||||||||||||
| elif str(index) in curve: | ||||||||||||||||||||||
|
Comment on lines
+953
to
+955
|
||||||||||||||||||||||
| if index in curve: | |
| return curve[index] | |
| elif str(index) in curve: | |
| try: | |
| if index in curve: | |
| return curve[index] | |
| except TypeError: | |
| # Unhashable index (e.g. list); fall back to string/default handling | |
| pass | |
| if str(index) in curve: |
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.
The documentation for get_curve_value should use a proper docstring format (triple-quoted string inside the function) instead of a comment above the function. This is inconsistent with the documentation style used throughout the rest of utils.py (e.g., find_battery_temperature_cap, get_charge_rate_curve, calc_percent_limit). The docstring should include Args and Returns sections explaining the parameters and return value.