pakutz79 0797f37c78 feat: ManualStrategy — community tier scheduling with full manual control
- Add ManualSlotConfig type with weekly repeating support and auto-expiry
- Add ManualStrategy (strategyId="manual"): applies user-defined allocations
  exactly; expired slots logged and skipped; inflexible/critical loads always
  applied as safety fallback; decisionReason never empty
- Extend SchedulerSettings with manualSlots persistence section (INI array)
- Extend SchedulerManager with setManualSlot/removeManualSlot/clearManualSlots
  methods; hydrates ManualStrategy from settings on registerStrategy()
- Add JSON-RPC v11 methods: GetManualSlots, SetManualSlot, RemoveManualSlot,
  ClearManualSlots + ManualSlotActivated push notification
- Register ManualStrategy in energypluginnymea.cpp::init() (no feature flag)
- Add 5 unit tests: basicSlot, noConfig_fallback, expiredSlot, repeatingSlot,
  persistence (JSON round-trip)
- Update doc.md section 11

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 06:34:31 +01:00

81 lines
3.0 KiB
C++

// SPDX-License-Identifier: GPL-3.0-or-later
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (C) 2013 - 2024, nymea GmbH
* Copyright (C) 2024 - 2025, chargebyte austria GmbH
*
* This file is part of nymea-energy-plugin-nymea.
*
* nymea-energy-plugin-nymea.s free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nymea-energy-plugin-nymea.s distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with nymea-energy-plugin-nymea. If not, see <https://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef MANUALSTRATEGY_H
#define MANUALSTRATEGY_H
#include "ischedulingstrategy.h"
#include "types/manualslotconfig.h"
// Community-tier scheduling strategy: the user defines all time windows and
// power allocations explicitly.
//
// For each forecast slot:
// - If a ManualSlotConfig covers that slot: apply its allocations exactly.
// - If a matching config exists but is expired: reason = "Créneau expiré — ignoré",
// apply critical/inflexible loads for safety.
// - If no config matches: apply critical/inflexible loads only, reason =
// "Aucune configuration — charges critiques uniquement".
//
// decisionReason is never empty (contract from ISchedulingStrategy).
class ManualStrategy : public ISchedulingStrategy
{
Q_OBJECT
public:
explicit ManualStrategy(QObject *parent = nullptr);
QString strategyId() const override { return QStringLiteral("manual"); }
QString displayName() const override { return QStringLiteral("Manuel"); }
QString description() const override {
return QStringLiteral(
"L'utilisateur définit lui-même les créneaux de charge. "
"Aucune automatisation — contrôle total.");
}
QList<EnergyTimeSlot> computeSchedule(
const QList<EnergyTimeSlot> &forecast,
const QList<FlexibleLoad> &loads,
const SchedulerConfig &config) override;
QString explainDecision(
const EnergyTimeSlot &slot,
const FlexibleLoad &load) const override;
// Manual slot management
void setManualSlot(const ManualSlotConfig &slotConfig);
void removeManualSlot(const QDateTime &slotStart);
void clearAllManualSlots();
QList<ManualSlotConfig> manualSlots() const;
private:
// Apply critical/inflexible loads to a slot (safety fallback).
// Sets decisionReason if it is still empty after processing.
void applyInflexibleLoads(EnergyTimeSlot &slot,
const QList<FlexibleLoad> &loads) const;
QList<ManualSlotConfig> m_manualSlots;
};
#endif // MANUALSTRATEGY_H