Skip to content

Commit ad61121

Browse files
committed
Merge pull request #383 from EddyK69/schedules
Implemented: Extended schedules for SetPoints
2 parents a080e6f + d271895 commit ad61121

File tree

9 files changed

+380
-30
lines changed

9 files changed

+380
-30
lines changed

main/SQLHelper.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "../msbuild/WindowsHelper.h"
3232
#endif
3333

34-
#define DB_VERSION 94
34+
#define DB_VERSION 95
3535

3636
extern http::server::CWebServerHelper m_webservers;
3737
extern std::string szWWWFolder;
@@ -1723,6 +1723,21 @@ bool CSQLHelper::OpenDatabase()
17231723
szQuery << "UPDATE SceneTimers SET [Type]=[Type]+2 WHERE ([Type]>" << TTYPE_FIXEDDATETIME << ")";
17241724
query(szQuery.str());
17251725
}
1726+
if (dbversion < 95)
1727+
{
1728+
if (!DoesColumnExistsInTable("Month", "SetpointTimers"))
1729+
{
1730+
query("ALTER TABLE SetpointTimers ADD COLUMN [Month] INTEGER DEFAULT 0");
1731+
}
1732+
if (!DoesColumnExistsInTable("MDay", "SetpointTimers"))
1733+
{
1734+
query("ALTER TABLE SetpointTimers ADD COLUMN [MDay] INTEGER DEFAULT 0");
1735+
}
1736+
if (!DoesColumnExistsInTable("Occurence", "SetpointTimers"))
1737+
{
1738+
query("ALTER TABLE SetpointTimers ADD COLUMN [Occurence] INTEGER DEFAULT 0");
1739+
}
1740+
}
17261741

17271742
}
17281743
else if (bNewInstall)

main/Scheduler.cpp

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void CScheduler::ReloadSchedules()
243243
}
244244

245245
//Add Setpoint Timers
246-
result = m_sql.safe_query("SELECT T1.DeviceRowID, T1.Time, T1.Type, T1.Temperature, T1.Days, T2.Name, T1.[Date] FROM SetpointTimers as T1, DeviceStatus as T2 WHERE ((T1.Active == 1) AND (T1.TimerPlan == %d) AND (T2.ID == T1.DeviceRowID)) ORDER BY T1.ID",
246+
result = m_sql.safe_query("SELECT T1.DeviceRowID, T1.Time, T1.Type, T1.Temperature, T1.Days, T2.Name, T1.[Date], T1.MDay, T1.Month, T1.Occurence FROM SetpointTimers as T1, DeviceStatus as T2 WHERE ((T1.Active == 1) AND (T1.TimerPlan == %d) AND (T2.ID == T1.DeviceRowID)) ORDER BY T1.ID",
247247
m_sql.m_ActiveTimerPlan);
248248
if (result.size() > 0)
249249
{
@@ -257,6 +257,9 @@ void CScheduler::ReloadSchedules()
257257
titem.bEnabled = true;
258258
titem.bIsScene = false;
259259
titem.bIsThermostat = true;
260+
titem.MDay = 0;
261+
titem.Month = 0;
262+
titem.Occurence = 0;
260263

261264
std::stringstream s_str(sd[0]);
262265
s_str >> titem.RowID;
@@ -272,6 +275,38 @@ void CScheduler::ReloadSchedules()
272275
titem.startMonth = (unsigned char)atoi(sdate.substr(5, 2).c_str());
273276
titem.startDay = (unsigned char)atoi(sdate.substr(8, 2).c_str());
274277
}
278+
else if (timerType == TTYPE_MONTHLY)
279+
{
280+
std::string smday = sd[7];
281+
if (smday == "0")
282+
continue; //invalid
283+
titem.MDay = atoi(smday.c_str());
284+
}
285+
else if (timerType == TTYPE_MONTHLY_WD)
286+
{
287+
std::string socc = sd[9];
288+
if (socc == "0")
289+
continue; //invalid
290+
titem.Occurence = atoi(socc.c_str());
291+
}
292+
else if (timerType == TTYPE_YEARLY)
293+
{
294+
std::string smday = sd[7];
295+
std::string smonth = sd[8];
296+
if ((smday == "0") || (smonth == "0"))
297+
continue; //invalid
298+
titem.MDay = atoi(smday.c_str());
299+
titem.Month = atoi(smonth.c_str());
300+
}
301+
else if (timerType == TTYPE_YEARLY_WD)
302+
{
303+
std::string smonth = sd[8];
304+
std::string socc = sd[9];
305+
if ((smonth == "0") || (socc == "0"))
306+
continue; //invalid
307+
titem.Month = atoi(smonth.c_str());
308+
titem.Occurence = atoi(socc.c_str());
309+
}
275310

276311
titem.startHour = (unsigned char)atoi(sd[1].substr(0, 2).c_str());
277312
titem.startMin = (unsigned char)atoi(sd[1].substr(3, 2).c_str());
@@ -1234,11 +1269,11 @@ namespace http {
12341269
if (idx == 0)
12351270
return;
12361271
root["status"] = "OK";
1237-
root["title"] = "Timers";
1272+
root["title"] = "SetpointTimers";
12381273
char szTmp[50];
12391274

12401275
std::vector<std::vector<std::string> > result;
1241-
result = m_sql.safe_query("SELECT ID, Active, [Date], Time, Type, Temperature, Days FROM SetpointTimers WHERE (DeviceRowID=%llu) AND (TimerPlan==%d) ORDER BY ID",
1276+
result = m_sql.safe_query("SELECT ID, Active, [Date], Time, Type, Temperature, Days, MDay, Month, Occurence FROM SetpointTimers WHERE (DeviceRowID=%llu) AND (TimerPlan==%d) ORDER BY ID",
12421277
idx, m_sql.m_ActiveTimerPlan);
12431278
if (result.size() > 0)
12441279
{
@@ -1268,6 +1303,9 @@ namespace http {
12681303
root["result"][ii]["Type"] = iTimerType;
12691304
root["result"][ii]["Temperature"] = atof(sd[5].c_str());
12701305
root["result"][ii]["Days"] = atoi(sd[6].c_str());
1306+
root["result"][ii]["MDay"] = atoi(sd[7].c_str());
1307+
root["result"][ii]["Month"] = atoi(sd[8].c_str());
1308+
root["result"][ii]["Occurence"] = atoi(sd[9].c_str());
12711309
ii++;
12721310
}
12731311
}
@@ -1288,6 +1326,9 @@ namespace http {
12881326
std::string smin = request::findValue(&req, "min");
12891327
std::string stvalue = request::findValue(&req, "tvalue");
12901328
std::string sdays = request::findValue(&req, "days");
1329+
std::string smday = "0";
1330+
std::string smonth = "0";
1331+
std::string soccurence = "0";
12911332
if (
12921333
(idx == "") ||
12931334
(active == "") ||
@@ -1316,22 +1357,50 @@ namespace http {
13161357
Year = atoi(sdate.substr(6, 4).c_str());
13171358
}
13181359
}
1360+
else if (iTimerType == TTYPE_MONTHLY)
1361+
{
1362+
smday = request::findValue(&req, "mday");
1363+
if (smday == "") return;
1364+
}
1365+
else if (iTimerType == TTYPE_MONTHLY_WD)
1366+
{
1367+
soccurence = request::findValue(&req, "occurence");
1368+
if (soccurence == "") return;
1369+
}
1370+
else if (iTimerType == TTYPE_YEARLY)
1371+
{
1372+
smday = request::findValue(&req, "mday");
1373+
smonth = request::findValue(&req, "month");
1374+
if ((smday == "") || (smonth == "")) return;
1375+
}
1376+
else if (iTimerType == TTYPE_YEARLY_WD)
1377+
{
1378+
smonth = request::findValue(&req, "month");
1379+
soccurence = request::findValue(&req, "occurence");
1380+
if ((smonth == "") || (soccurence == "")) return;
1381+
}
13191382

13201383
unsigned char hour = atoi(shour.c_str());
13211384
unsigned char min = atoi(smin.c_str());
13221385
int days = atoi(sdays.c_str());
13231386
float temperature = static_cast<float>(atof(stvalue.c_str()));
1387+
int mday = atoi(smday.c_str());
1388+
int month = atoi(smonth.c_str());
1389+
int occurence = atoi(soccurence.c_str());
13241390
root["status"] = "OK";
13251391
root["title"] = "AddSetpointTimer";
13261392
m_sql.safe_query(
1327-
"INSERT INTO SetpointTimers (Active, DeviceRowID, [Date], Time, Type, Temperature, Days, TimerPlan) VALUES (%d,'%q','%04d-%02d-%02d','%02d:%02d',%d,%.1f,%d,%d)",
1393+
"INSERT INTO SetpointTimers (Active, DeviceRowID, [Date], Time, Type, Temperature, Days, MDay, Month, Occurence, TimerPlan) VALUES (%d,'%q','%04d-%02d-%02d','%02d:%02d',%d,%.1f,%d,%d,%d,%d,%d)",
13281394
(active == "true") ? 1 : 0,
13291395
idx.c_str(),
13301396
Year, Month, Day,
13311397
hour, min,
13321398
iTimerType,
13331399
temperature,
13341400
days,
1401+
mday,
1402+
month,
1403+
occurence,
13351404
m_sql.m_ActiveTimerPlan
13361405
);
13371406
m_mainworker.m_scheduler.ReloadSchedules();
@@ -1353,6 +1422,9 @@ namespace http {
13531422
std::string smin = request::findValue(&req, "min");
13541423
std::string stvalue = request::findValue(&req, "tvalue");
13551424
std::string sdays = request::findValue(&req, "days");
1425+
std::string smday = "0";
1426+
std::string smonth = "0";
1427+
std::string soccurence = "0";
13561428
if (
13571429
(idx == "") ||
13581430
(active == "") ||
@@ -1381,21 +1453,49 @@ namespace http {
13811453
Year = atoi(sdate.substr(6, 4).c_str());
13821454
}
13831455
}
1456+
else if (iTimerType == TTYPE_MONTHLY)
1457+
{
1458+
smday = request::findValue(&req, "mday");
1459+
if (smday == "") return;
1460+
}
1461+
else if (iTimerType == TTYPE_MONTHLY_WD)
1462+
{
1463+
soccurence = request::findValue(&req, "occurence");
1464+
if (soccurence == "") return;
1465+
}
1466+
else if (iTimerType == TTYPE_YEARLY)
1467+
{
1468+
smday = request::findValue(&req, "mday");
1469+
smonth = request::findValue(&req, "month");
1470+
if ((smday == "") || (smonth == "")) return;
1471+
}
1472+
else if (iTimerType == TTYPE_YEARLY_WD)
1473+
{
1474+
smonth = request::findValue(&req, "month");
1475+
soccurence = request::findValue(&req, "occurence");
1476+
if ((smonth == "") || (soccurence == "")) return;
1477+
}
13841478

13851479
unsigned char hour = atoi(shour.c_str());
13861480
unsigned char min = atoi(smin.c_str());
13871481
int days = atoi(sdays.c_str());
13881482
float tempvalue = static_cast<float>(atof(stvalue.c_str()));
1483+
int mday = atoi(smday.c_str());
1484+
int month = atoi(smonth.c_str());
1485+
int occurence = atoi(soccurence.c_str());
13891486
root["status"] = "OK";
13901487
root["title"] = "UpdateSetpointTimer";
13911488
m_sql.safe_query(
1392-
"UPDATE SetpointTimers SET Active=%d, [Date]='%04d-%02d-%02d', Time='%02d:%02d', Type=%d, Temperature=%.1f, Days=%d WHERE (ID == '%q')",
1489+
"UPDATE SetpointTimers SET Active=%d, [Date]='%04d-%02d-%02d', Time='%02d:%02d', Type=%d, Temperature=%.1f, Days=%d, MDay=%d, Month=%d, Occurence=%d WHERE (ID == '%q')",
13931490
(active == "true") ? 1 : 0,
13941491
Year, Month, Day,
13951492
hour, min,
13961493
iTimerType,
13971494
tempvalue,
13981495
days,
1496+
mday,
1497+
month,
1498+
occurence,
13991499
idx.c_str()
14001500
);
14011501
m_mainworker.m_scheduler.ReloadSchedules();

main/WebServer.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ namespace http {
360360
m_pWebEm->RegisterIncludeCode("switchtypes", boost::bind(&CWebServer::DisplaySwitchTypesCombo, this));
361361
m_pWebEm->RegisterIncludeCode("metertypes", boost::bind(&CWebServer::DisplayMeterTypesCombo, this));
362362
m_pWebEm->RegisterIncludeCode("timertypes", boost::bind(&CWebServer::DisplayTimerTypesCombo, this));
363-
m_pWebEm->RegisterIncludeCode("timertypesextended", boost::bind(&CWebServer::DisplayTimerTypesComboExtendend, this));
364363
m_pWebEm->RegisterIncludeCode("combolanguage", boost::bind(&CWebServer::DisplayLanguageCombo, this));
365364

366365
m_pWebEm->RegisterPageCode("/json.htm", boost::bind(&CWebServer::GetJSonPage, this, _1, _2));
@@ -6782,18 +6781,6 @@ namespace http {
67826781
}
67836782

67846783
char * CWebServer::DisplayTimerTypesCombo()
6785-
{
6786-
m_retstr = "";
6787-
char szTmp[200];
6788-
for (int ii = 0; ii <= TTYPE_FIXEDDATETIME; ii++)
6789-
{
6790-
sprintf(szTmp, "<option data-i18n=\"%s\" value=\"%d\">%s</option>\n", Timer_Type_Desc(ii), ii, Timer_Type_Desc(ii));
6791-
m_retstr += szTmp;
6792-
}
6793-
return (char*)m_retstr.c_str();
6794-
}
6795-
6796-
char * CWebServer::DisplayTimerTypesComboExtendend()
67976784
{
67986785
m_retstr = "";
67996786
char szTmp[200];

main/WebServer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class CWebServer : public session_store
3939
char * DisplaySwitchTypesCombo();
4040
char * DisplayMeterTypesCombo();
4141
char * DisplayTimerTypesCombo();
42-
char * DisplayTimerTypesComboExtendend();
4342
char * DisplayLanguageCombo();
4443
std::string GetJSonPage(WebEmSession & session, const request& req);
4544
std::string GetAppCache(WebEmSession & session, const request& req);

0 commit comments

Comments
 (0)