Repository navigation
update time charged type #3156
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
update time charged type #3156
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 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,7 +57,7 @@ | |||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| class UpdateConfig: | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| DATASTORE_VERSION = 107 | ||||||||||||||||||||||||||||||||||||
| DATASTORE_VERSION = 108 | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| valid_topic = [ | ||||||||||||||||||||||||||||||||||||
| "^openWB/bat/config/bat_control_permitted$", | ||||||||||||||||||||||||||||||||||||
|
|
@@ -2724,3 +2724,14 @@ def upgrade(topic: str, payload) -> None: | |||||||||||||||||||||||||||||||||||
| return {topic: provider} | ||||||||||||||||||||||||||||||||||||
| self._loop_all_received_topics(upgrade) | ||||||||||||||||||||||||||||||||||||
| self._append_datastore_version(107) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def upgrade_datastore_108(self) -> None: | ||||||||||||||||||||||||||||||||||||
| def upgrade(topic: str, payload) -> None: | ||||||||||||||||||||||||||||||||||||
| if re.search("openWB/chargepoint/[0-9]+/set/log$", topic) is not None: | ||||||||||||||||||||||||||||||||||||
| log_data = decode_payload(payload) | ||||||||||||||||||||||||||||||||||||
| if log_data.get("time_charged") is not None: | ||||||||||||||||||||||||||||||||||||
| if isinstance(log_data["time_charged"], str): | ||||||||||||||||||||||||||||||||||||
| log_data["time_charged"] = 0 | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| log_data["time_charged"] = 0 | |
| value = log_data["time_charged"] | |
| seconds = 0 | |
| if value.isdigit(): | |
| seconds = int(value) | |
| else: | |
| parts = value.split(":") | |
| try: | |
| if len(parts) == 3: | |
| hours, minutes, secs = map(int, parts) | |
| seconds = hours * 3600 + minutes * 60 + secs | |
| elif len(parts) == 2: | |
| minutes, secs = map(int, parts) | |
| seconds = minutes * 60 + secs | |
| except ValueError: | |
| seconds = 0 | |
| log_data["time_charged"] = seconds |
Copilot
AI
Feb 23, 2026
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 inner upgrade() callback is annotated as returning None, but it conditionally returns a dict of modified topics. For consistency with most other datastore upgrades in this file (which use Optional[dict] for callbacks passed to _loop_all_received_topics) and to avoid misleading type checking, update the return annotation accordingly.
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.
time_chargedin chargepointset/logpayload is defined as numeric seconds (seecontrol/chargepoint/chargepoint_data.pyLog.time_charged: float). This migration currently replaces any string value with0, which discards the previously accumulated charging duration and can reset in-progress statistics after an update/restart. Consider converting known string formats instead (e.g. numeric strings viafloat(...), orH:MM/D:H:MMinto seconds) and only falling back to0.0when parsing fails.