-
Notifications
You must be signed in to change notification settings - Fork 7
Add unit conversion tests #39
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -360,11 +360,48 @@ async def print_dataset(name, dataset): | |||||||||||||||||
| if count > 24: | ||||||||||||||||||
| break | ||||||||||||||||||
|
|
||||||||||||||||||
| async def get_history(interface, nw, sensor_name, now, incrementing, max_increment, days, use_db, reset_low, reset_high, max_age): | ||||||||||||||||||
| async def convert_units(dataset, from_units, to_units): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Convert units in the dataset from from_units to to_units. | ||||||||||||||||||
| Currently supports conversion between kWh and Wh. | ||||||||||||||||||
| Handles list format from HA API. | ||||||||||||||||||
| """ | ||||||||||||||||||
| print("Converting units from {} to {}".format(from_units, to_units)) | ||||||||||||||||||
| factor = 1.0 | ||||||||||||||||||
|
||||||||||||||||||
| factor = 1.0 |
Copilot
AI
Dec 31, 2025
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 error handling silently ignores conversion failures without logging any information. When a ValueError or KeyError occurs, the original value is kept but no warning is printed. This makes debugging difficult if data is malformed. Consider adding a print statement or warning when conversion fails to maintain consistency with the warning message on line 380 for unsupported conversions.
| # Keep original if conversion fails | |
| pass | |
| # Keep original if conversion fails, but log a warning for visibility | |
| print( | |
| "Warn: Failed to convert state '{}' from {} to {}. Keeping original value.".format( | |
| item.get("state"), from_units, to_units | |
| ) | |
| ) |
Copilot
AI
Dec 31, 2025
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 condition (required_units is not None) is redundant here. The outer if required_units: on line 400 already checks this condition, so this inner check is unnecessary and reduces code clarity.
| if (required_units is not None) and (units is not None) and (units != required_units): | |
| if (units is not None) and (units != required_units): |
Copilot
AI
Dec 31, 2025
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.
This change appears to be an unintentional whitespace modification. Two spaces were removed from the banner message, changing "Starting PredAI" alignment. This seems unrelated to the unit conversion feature being added.
| print("********* Starting PredAI *********") | |
| print("********* Starting PredAI *********") |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,7 @@ def _patched_torch_load(*args, **kwargs): | |||||
| # Add the rootfs directory to the path | ||||||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'predai', 'rootfs')) | ||||||
|
|
||||||
| from predai import HAInterface, Prophet, timestr_to_datetime | ||||||
| from predai import HAInterface, Prophet, timestr_to_datetime, convert_units, get_history | ||||||
|
||||||
| from predai import HAInterface, Prophet, timestr_to_datetime, convert_units, get_history | |
| from predai import HAInterface, Prophet, convert_units, get_history |
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 comment is incomplete and outdated. It states the function "Currently supports conversion between kWh and Wh" but the implementation also supports W↔kW conversions. The documentation should be updated to reflect all supported conversions: kWh↔Wh and W↔kW.