Anlauferkennung, Betriebsmodus zurücksetzen, Befehle für Pläne#3588
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Erweitert die Verbraucher-Logik um Anlauferkennung (“wait for start”), neue/erweiterte MQTT-Set-Topics sowie Commands zum Anlegen/Löschen von Verbraucher-Plänen; zusätzlich wird ein nächtliches Zurücksetzen bestimmter Zustände implementiert.
Changes:
- Mitternachts-Handler setzt
wait_for_start-State und (optional) den Lademodus zurück. - MQTT-Handling erweitert: Consumer-
/set/*Topics werden zugelassen, validiert und inSubData/ConsumerData.Setverarbeitet (inkl. Enum-Decoding). - Commands für Verbraucher-Zielladen-/Zeitladen-Pläne hinzugefügt sowie neue Tests für die Wait-for-start-Statemachine.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/main.py | Setzt Verbraucher-Zustände um Mitternacht zurück. |
| packages/helpermodules/update_config.py | Whitelist um Consumer-/set/* Topics erweitert. |
| packages/helpermodules/timecheck.py | Typen für neue Consumer-Plan-Klassen ergänzt. |
| packages/helpermodules/subdata.py | Enum-Werte aus MQTT-Payloads werden für Klassenattribute gesetzt. |
| packages/helpermodules/setdata.py | Validierung für neue Consumer-/set/* Topics ergänzt. |
| packages/helpermodules/command.py | Neue Commands zum Hinzufügen/Löschen von Verbraucher-Plänen. |
| packages/helpermodules/abstract_plans.py | Default-Namen für Consumer-Plan-Typen angepasst. |
| packages/control/consumer/consumer.py | Neue Wait-for-start-Logik, Reset-Funktionen, Anpassungen an min_current/min_intervall. |
| packages/control/consumer/consumer_test.py | Neue Tests für wait_for_start_handler. |
| packages/control/consumer/consumer_data.py | Neue Enums/Reset-Konfig, Umzug min_current/min_intervall in ConsumerConfig, neue Set-Topics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
352
to
355
| def wait_for_start_handler( | ||
| self, func: Callable[[], Tuple[int, str, Optional[str], int]]) -> Tuple[int, str, Optional[str], int]: | ||
| self, func: Callable[[], Tuple[int, str, Optional[str], int]] | ||
| ) -> Tuple[int, Chargemode, Optional[Chargemode], int]: | ||
| if self.data.usage.wait_for_start_active: |
Comment on lines
+1216
to
+1224
| # check if "payload" contains "data.copy" | ||
| if "data" in payload and "copy" in payload["data"] and usage.scheduled_charging.plans is not None: | ||
| for plan in usage.scheduled_charging.plans: | ||
| if plan.id == payload["data"]["copy"]: | ||
| new_consumer_schedule_plan = copy.deepcopy(plan) | ||
| break | ||
| new_consumer_schedule_plan.name = f'Kopie von {new_consumer_schedule_plan.name}' | ||
| else: | ||
| new_consumer_schedule_plan = GET_PLAN_CLASS_FOR_USAGE[usage.type]() |
Comment on lines
+1241
to
+1245
| if self.max_id_consumer_scheduled_plan < payload["data"]["plan"]: | ||
| log.error( | ||
| payload, connection_id, | ||
| f'Die ID \'{payload["data"]["plan"]}\' ist größer als die maximal vergebene ' | ||
| f'ID \'{self.max_id_usage_plan}\'.', MessageType.ERROR) | ||
| f'ID \'{self.max_id_consumer_scheduled_plan}\'.', MessageType.ERROR) |
Comment on lines
+1261
to
+1269
| # check if "payload" contains "data.copy" | ||
| if "data" in payload and "copy" in payload["data"]: | ||
| for plan in usage.time_charging.plans: | ||
| if plan.id == payload["data"]["copy"]: | ||
| new_time_charging_plan = copy.deepcopy(plan) | ||
| break | ||
| new_time_charging_plan.name = f'Kopie von {new_time_charging_plan.name}' | ||
| else: | ||
| new_time_charging_plan = TimeChargingPlanConsumer() |
Comment on lines
+1286
to
+1289
| if self.max_id_consumer_time_plan < payload["data"]["plan"]: | ||
| log.error(payload, connection_id, "Die ID ist größer als die maximal vergebene ID.", | ||
| MessageType.ERROR) | ||
| for plan in usage.time_charging.plans: |
Comment on lines
+111
to
+121
| def scheduled_charging(self) -> Tuple[Chargemode, str]: | ||
| return self.data.config.min_current, "Zielladen noch nicht implementiert", Chargemode.STOP, Chargemode.STOP | ||
| plan_data, remaining_time, duration = self._find_recent_plan(self.data.usage.scheduled_charging.plans) | ||
| if plan_data: | ||
| control_parameter.current_plan = plan_data.id | ||
| else: | ||
| control_parameter.current_plan = None | ||
| return self.scheduled_charging_calc_current( | ||
| plan_data, | ||
| remaining_time, | ||
| duration) |
Comment on lines
+439
to
+441
| if ((submode == "time_charging" and self.data.control_parameter.chargemode != "time_charging") or | ||
| (submode != "time_charging" and | ||
| self.data.control_parameter.chargemode != mode)): |
Comment on lines
+399
to
+413
| def reset_chargemode_at_midnight(self): | ||
| if self.data.usage.reset_chargemode.mode == ResetModes.MIDNIGHT: | ||
| if self.data.usage.chargemode != self.data.usage.reset_chargemode.chargemode: | ||
| log.info(f"Zurücksetzen des Lademodus auf {self.data.usage.reset_chargemode.chargemode} " | ||
| f"für Verbraucher {self.num} um Mitternacht.") | ||
| self.data.usage.chargemode = self.data.usage.reset_chargemode.chargemode | ||
|
|
||
| def reset_chargemode_at_time(self): | ||
| if (self.data.usage.reset_chargemode.mode == ResetModes.TIME and | ||
| self.data.usage.reset_chargemode.time is not None): | ||
| if timecheck.create_timestamp() > self.data.usage.reset_chargemode.time: | ||
| if self.data.usage.chargemode != self.data.usage.reset_chargemode.chargemode: | ||
| log.info(f"Zurücksetzen des Lademodus auf {self.data.usage.reset_chargemode.chargemode} " | ||
| f"für Verbraucher {self.num} um definierte Zeit.") | ||
| self.data.usage.chargemode = self.data.usage.reset_chargemode.chargemode |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
No description provided.