Newer
Older
#ifndef HEATCONTROL_H
#define HEATCONTROL_H
#include <QObject>
#include <QFile>
static const QTime startTimeDayDefault = QTime(7,15);
static const QTime startTimeNightDefault = QTime(23,0);
static const float autoTempMargin = 2.5;
static const char sep = ';';
static const QString CSVfileName = "SHcontrol.csv";
class HeatControl : public QObject
{
Q_OBJECT
public:
constexpr static const float maxTempDayDefault = 24.0;
constexpr static const float maxTempNightDefault = 18.5;
enum class Mode {Off, Auto, Smart, Timed, On, RemoteOn, size}; // Namen in HeatControl::modeName()
explicit HeatControl(SHsensor * temp, SHactuator * swtch,
float maxTempDay=maxTempDayDefault, float maxTempNight=maxTempNightDefault,
QTime startTimeDay=startTimeDayDefault, QTime startTimeNight=startTimeNightDefault,
QObject *parent = nullptr);
virtual ~HeatControl();
Mode mode() const;
QString value() const; // mode als string
virtual int demand() const;
bool suspended() const;
QString susName() const;
QString name() const;
void grant(bool ON);
void checkSusExpiration();
void checkResetSus(bool supplyPossible);
bool grantPossible(bool supplyPossible) const;
void checkMaxTempSus(bool supplyPossible);
void checkMinTempSus(bool supplyPossible);
protected:
friend class TestSHserver;
SHsensor * m_temp;
SHactuator * m_switch;
Mode m_mode;
Mode m_previousMode; // für Remote Control
SHactuator::State m_previousState; // für Remote Control
float m_maxTempDay;
float m_maxTempNight;
QTime m_startTimeDay; // Beginn Tag-Betrieb
QTime m_startTimeNight; // Beginn Nacht-Betrieb
int m_pos; // Hash-Adresse, zugleich ID
bool m_granted; // für aktuelle Anzeige in solarControl
enum class Suspension {NONE, MinTemp, MaxTemp};
Suspension m_suspended; // eine zeitlang true, wenn Temperatur erreicht ist
QDateTime m_expireTime;
float minTemp() const;
float temperature() const;
virtual int suspensionTime() const;
void processTimed();
void process();
// statics:
public slots:
static void processALL();
public:
virtual bool minReached() const;
virtual bool maxReached() const;
static void readCSV();
static void writeCSV();
static QString modeName(Mode m);
static Mode toMode(const QString &m);
static void setMode(int pos, const Mode &toMode);
static QString getName(int nid, int sid);
static Mode getMode(int nid, int sid);
static float getMaxTempDay(int nid, int sid);
static float getMaxTempNight(int nid, int sid);
static QTime getStartTimeDay(int nid, int sid);
static QTime getStartTimeNight(int nid, int sid);
static void setMaxTempDay(int pos, float maxTempDay);
static void setMaxTempNight(int pos, float maxTempNight);
static void setStartTimeDay(int pos, const QTime &startTimeDay);
static void setStartTimeNight(int pos, const QTime &startTimeNight);
static void remoteOn(int pos);
static void resumeMode(int pos);
bool granted() const;