@@ -6517,7 +6517,28 @@ namespace http {
6517
6517
return;
6518
6518
}
6519
6519
}
6520
-
6520
+ if (switchcmd == "Toggle") {
6521
+ //Request current state of switch
6522
+ sprintf(szTmp,
6523
+ "SELECT [Type],[SubType],SwitchType,nValue,sValue FROM DeviceStatus WHERE (ID = %s)", idx.c_str());
6524
+ result = m_sql.query(szTmp);
6525
+ if (result.size() > 0)
6526
+ {
6527
+ std::vector<std::string> sd = result[0];
6528
+ unsigned char devType = (unsigned char)atoi(sd[0].c_str());
6529
+ unsigned char subType = (unsigned char)atoi(sd[1].c_str());
6530
+ _eSwitchType switchtype = (_eSwitchType)atoi(sd[2].c_str());
6531
+ int nValue = atoi(sd[3].c_str());
6532
+ std::string sValue = sd[4];
6533
+ std::string lstatus = "";
6534
+ int llevel = 0;
6535
+ bool bHaveDimmer = false;
6536
+ bool bHaveGroupCmd = false;
6537
+ int maxDimLevel = 0;
6538
+ GetLightStatus(devType, subType, switchtype, nValue, sValue, lstatus, llevel, bHaveDimmer, maxDimLevel, bHaveGroupCmd);
6539
+ switchcmd = (IsLightSwitchOn(lstatus) == true) ? "Off" : "On";
6540
+ }
6541
+ }
6521
6542
if (m_mainworker.SwitchLight(idx,switchcmd,level,"-1",onlyonchange,0)==true)
6522
6543
{
6523
6544
root["status"] = "OK";
@@ -12206,7 +12227,7 @@ namespace http {
12206
12227
}
12207
12228
}
12208
12229
12209
- //Will transfer NEW sensor log to OLD sensor,
12230
+ //Will transfer Newest sensor log to OLD sensor,
12210
12231
//then set the HardwareID/DeviceID/Unit/Name/Type/Subtype/Unit for the OLD sensor to the NEW sensor ID/Type/Subtype/Unit
12211
12232
//then delete the NEW sensor
12212
12233
void CWebServer::RType_TransferDevice(Json::Value &root)
@@ -12221,6 +12242,50 @@ namespace http {
12221
12242
12222
12243
std::stringstream szQuery;
12223
12244
std::vector<std::vector<std::string> > result;
12245
+
12246
+ //Check which device is newer
12247
+
12248
+ time_t now = mytime(NULL);
12249
+ struct tm tm1;
12250
+ localtime_r(&now, &tm1);
12251
+ struct tm LastUpdateTime_A;
12252
+ struct tm LastUpdateTime_B;
12253
+
12254
+ szQuery << "SELECT A.LastUpdate, B.LastUpdate FROM DeviceStatus as A, DeviceStatus as B WHERE (A.ID == " << sidx << ") AND (B.ID == " << newidx << ")";
12255
+ result = m_sql.query(szQuery.str());
12256
+ if (result.size() < 1)
12257
+ return;
12258
+
12259
+ std::string sLastUpdate_A = result[0][0];
12260
+ std::string sLastUpdate_B = result[0][1];
12261
+
12262
+ LastUpdateTime_A.tm_isdst = tm1.tm_isdst;
12263
+ LastUpdateTime_A.tm_year = atoi(sLastUpdate_A.substr(0, 4).c_str()) - 1900;
12264
+ LastUpdateTime_A.tm_mon = atoi(sLastUpdate_A.substr(5, 2).c_str()) - 1;
12265
+ LastUpdateTime_A.tm_mday = atoi(sLastUpdate_A.substr(8, 2).c_str());
12266
+ LastUpdateTime_A.tm_hour = atoi(sLastUpdate_A.substr(11, 2).c_str());
12267
+ LastUpdateTime_A.tm_min = atoi(sLastUpdate_A.substr(14, 2).c_str());
12268
+ LastUpdateTime_A.tm_sec = atoi(sLastUpdate_A.substr(17, 2).c_str());
12269
+
12270
+ LastUpdateTime_B.tm_isdst = tm1.tm_isdst;
12271
+ LastUpdateTime_B.tm_year = atoi(sLastUpdate_B.substr(0, 4).c_str()) - 1900;
12272
+ LastUpdateTime_B.tm_mon = atoi(sLastUpdate_B.substr(5, 2).c_str()) - 1;
12273
+ LastUpdateTime_B.tm_mday = atoi(sLastUpdate_B.substr(8, 2).c_str());
12274
+ LastUpdateTime_B.tm_hour = atoi(sLastUpdate_B.substr(11, 2).c_str());
12275
+ LastUpdateTime_B.tm_min = atoi(sLastUpdate_B.substr(14, 2).c_str());
12276
+ LastUpdateTime_B.tm_sec = atoi(sLastUpdate_B.substr(17, 2).c_str());
12277
+
12278
+ time_t timeA = mktime(&LastUpdateTime_A);
12279
+ time_t timeB = mktime(&LastUpdateTime_B);
12280
+
12281
+ if (timeA < timeB)
12282
+ {
12283
+ //Swap idx with newidx
12284
+ sidx.swap(newidx);
12285
+ }
12286
+
12287
+ szQuery.clear();
12288
+ szQuery.str("");
12224
12289
szQuery << "SELECT HardwareID, DeviceID, Unit, Name, Type, SubType, SignalLevel, BatteryLevel, nValue, sValue FROM DeviceStatus WHERE (ID == " << newidx << ")";
12225
12290
result = m_sql.query(szQuery.str());
12226
12291
if (result.size() < 1)
0 commit comments