- EnergyArbitrator : public SmartChargingManager — raison documentée dans AGENTS.md §DÉCISIONS DE DESIGN - SmartChargingManager : protected slots + virtual update() + 3 accesseurs inline [ETM] - RuleBasedScheduler::getPlan() wraps planSurplusCharging/planSpotMarketCharging, annote chaque action d'un reason français - EvAdapter : ILoadAdapter concret pour evcharger — applyAction() implémenté, NON appelé en 3b (dispatch via adjustEvChargers() amont, iso-fonctionnel) - ETM_ARBITRATOR : commenté dans .pro — ne s'active qu'après preuve iso-fonctionnelle (3b-iv) - Doxygen \brief + invariants + contrats sur toutes les classes/méthodes publiques etm/ (DoD §5) - plan.h : timeSlots (pas slots, mot-clé Qt) ; commentaire JSON sérialisation "slots" OPTIMIZER_PROTOCOL §6 - .clangd : flags de repli Qt/nymea pour clangd via symlink ~/Schreibtisch/ - compile_commands.json gitignore (chemins absolus locaux) - Build : 0 erreurs, 0 warnings — libnymea_energypluginnymea.so 914 KB Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
104 lines
4.0 KiB
C++
104 lines
4.0 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Copyright (C) 2025 - 2026, Patrick Schurig / ETM PowerSync
|
|
#pragma once
|
|
|
|
#include "../smartchargingmanager.h"
|
|
#include "scheduler/ischeduler.h"
|
|
#include "types/surpluscontext.h"
|
|
#include "types/plan.h"
|
|
|
|
class EvAdapter;
|
|
class RuleBasedScheduler;
|
|
|
|
/*!
|
|
* \brief Arbitre central ETM — remplace SmartChargingManager::update() (ETM_ARBITRATOR).
|
|
*
|
|
* Hérite de SmartChargingManager pour conserver la compatibilité API complète avec
|
|
* NymeaEnergyJsonHandler sans modifier le code amont.
|
|
* Seul update() est surchargé : préparation → sécurité → planificateur → adapters.
|
|
*
|
|
* \invariant UN seul arbitre : EnergyArbitrator décide, les EvAdapter exécutent (règle 1).
|
|
* \invariant verifyOverloadProtection() est toujours appelée avant la planification (règle 4).
|
|
* \invariant Toute LoadAction transmise aux adapters a un \c reason non vide (règle 7).
|
|
* \invariant L'absence du root meter n'empêche pas le démarrage — cycle ignoré silencieusement.
|
|
*/
|
|
class EnergyArbitrator : public SmartChargingManager
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit EnergyArbitrator(EnergyManager *energyManager, ThingManager *thingManager,
|
|
SpotMarketManager *spotMarketManager,
|
|
EnergyManagerConfiguration *configuration,
|
|
QObject *parent = nullptr);
|
|
|
|
/*!
|
|
* \brief Déclenche planSurplusCharging() (protégée) — appelé par RuleBasedScheduler.
|
|
* \param now Instant courant du cycle.
|
|
*/
|
|
void runSurplusPlanning(const QDateTime &now);
|
|
|
|
/*!
|
|
* \brief Déclenche planSpotMarketCharging() (protégée) — appelé par RuleBasedScheduler.
|
|
* \param now Instant courant du cycle.
|
|
*/
|
|
void runSpotMarketPlanning(const QDateTime &now);
|
|
|
|
/*!
|
|
* \brief Actions planifiées (résultat de runSurplus/SpotMarket).
|
|
* \return Référence constante vers la table EvCharger* → ChargingActions.
|
|
* \note Valide seulement après runSurplusPlanning() / runSpotMarketPlanning().
|
|
*/
|
|
const QHash<EvCharger *, ChargingActions> &scheduledActions() const;
|
|
|
|
/*!
|
|
* \brief Pont d'exécution pour EvAdapter — délègue à executeChargingAction() protégée.
|
|
* \param charger Borne EV cible.
|
|
* \param action ChargingAction à appliquer.
|
|
* \param now Instant de l'action (pour les locks anti-rebond).
|
|
*/
|
|
void doExecuteChargingAction(EvCharger *charger, const ChargingAction &action, const QDateTime &now);
|
|
|
|
/*!
|
|
* \brief Liste des EvCharger enregistrés (lecture seule).
|
|
* \return Table ThingId → EvCharger*.
|
|
*/
|
|
const QHash<ThingId, EvCharger *> ®isteredEvChargers() const;
|
|
|
|
/*!
|
|
* \brief Root meter courant.
|
|
* \return Pointeur ou nullptr si aucun compteur principal n'est enregistré.
|
|
*/
|
|
RootMeter *registeredRootMeter() const;
|
|
|
|
protected:
|
|
/*!
|
|
* \brief Boucle principale ETM — surcharge SmartChargingManager::update().
|
|
*
|
|
* Ordre garanti :
|
|
* 1. updateManualSoCsWithoutMeter()
|
|
* 2. prepareInformation()
|
|
* 3. verifyOverloadProtection() + verifyOverloadProtectionRecovery()
|
|
* 4. m_scheduler->getPlan() → log des decisionReason
|
|
* 5. adjustEvChargers() → dispatch matériel + mise à jour états
|
|
*
|
|
* \param currentDateTime Instant courant (timer ou simulation).
|
|
*/
|
|
void update(const QDateTime ¤tDateTime) override;
|
|
|
|
private:
|
|
/*!
|
|
* \brief Construit un SurplusContext minimal (3b stub — timestamp seul).
|
|
* \note Contexte complet prévu en 3d (§5 complet avec site/meter/pv/battery/loads).
|
|
*/
|
|
SurplusContext buildContext(const QDateTime &now) const;
|
|
|
|
/*!
|
|
* \brief Synchronise m_adapters avec les EvCharger actuellement enregistrés.
|
|
* Crée les adapters manquants, supprime les adapters obsolètes.
|
|
*/
|
|
void syncAdapters();
|
|
|
|
RuleBasedScheduler *m_scheduler = nullptr;
|
|
QHash<QString, EvAdapter *> m_adapters; //!< loadId (ThingId string) → EvAdapter*.
|
|
};
|