Skip to content

Commit 75a31f9

Browse files
committed
Changed: Transferring a device will now look internally which device is newer/older
Implemented:JSON API, option to 'Toggle' a switch state between On/Off
1 parent b2ef660 commit 75a31f9

File tree

3 files changed

+79
-10
lines changed

3 files changed

+79
-10
lines changed

History.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Version 2.0.xxxx (xxxx 2015)
22
- Implemented: Fritzbox Hardware type for caller ID (Beta!)
33
- Changed: Avoiding possible RTC/NTP clock drifts
4+
- Changed: Transferring a device will now look internally which device is newer/older
5+
- Implemented:JSON API, option to 'Toggle' a switch state between On/Off
46

57
Version 2.0.2284 (February 22th 2015)
68
- Fixed: Firefox, RGBW/Setpoint popup
@@ -14,7 +16,7 @@ Version 2.0.2283 (February 21th 2015)
1416
- Fixed: OpenZWave, converted home_id to correct variable
1517
- Fixed: Blinds1, T6 DC160 should work now
1618
- Implemented: Dewpoint devices in Blockly
17-
- Updated: floorplan interface, german translation
19+
- Updated: floorplan interface, German translation
1820
- Fixed: Setting default security network key for openzwave
1921
- Implemented: Devices tab, CM180 log option
2022
- Implemented: Logging counter values for P1 meter (not displayed yet)
@@ -37,9 +39,9 @@ Version 2.0.2283 (February 21th 2015)
3739
- Changed: Renamed SMASpot to SBFSpot
3840
- Implemented: Automatic OpenZWave heal network command at 04:00am
3941
- Implemented: Thermostat Setpoint timers
40-
- Testing: Philips Hue native support (not ready yet!)
42+
- Implemented: Philips Hue native support
4143
- Changed: Dimmer value is now updating on screen
42-
- Changed: New patch for logitech harmony (thanks again!)
44+
- Changed: New patch for Logitech harmony (thanks again!)
4345
- Implemented: Text Sensor (update via udevice json call)
4446
- Implemented: Option for Dummy device to create Switch Sensor
4547
- Implemented: Changing color in scene/groups will now also change it on actual device (for preview)
@@ -68,8 +70,8 @@ Version 2.0.2283 (February 21th 2015)
6870
- Implemented: Alert Sensor (update via udevice json call)
6971
- Implemented: Roomplan selector on switches/utility tab
7072
- Changed: Date/Time notation in log to ISO-8601 (thanks to Ugo)
71-
- Changed: OpenZWave logging, more persistant with node id's (thanks to Ugo)
72-
- Implemented: Scene/Group, Blinds Percentage(+Inverted) can now set the percentage level
73+
- Changed: OpenZWave logging, more persistent with node id's (thanks to Ugo)
74+
- Implemented: Scene/Group, Blinds Percentage (+Inverted) can now set the percentage level
7375
- Fixed: Setpoint timers, 'when' selection
7476
- Implemented: ttyACM serial ports if available
7577
- Implemented: ZWave battery values for all sensor types that reports this
@@ -89,7 +91,7 @@ Version 2.0.2283 (February 21th 2015)
8991
- Implemented: PushAlot notification system (Thanks to Toni!)
9092
- Implemented: Previous Baro meter to month/year graph
9193
- Changed: Settings Page
92-
- Fixed: Windows Exit application from trayicon
94+
- Fixed: Windows Exit application from tray icon
9395
- Implemented: OTGW, added support for setting the Control Setpoint
9496
- Implemented: Wind Gust chart
9597
- Fixed: Dimmer slider resize

main/WebServer.cpp

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6517,7 +6517,28 @@ namespace http {
65176517
return;
65186518
}
65196519
}
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+
}
65216542
if (m_mainworker.SwitchLight(idx,switchcmd,level,"-1",onlyonchange,0)==true)
65226543
{
65236544
root["status"] = "OK";
@@ -12206,7 +12227,7 @@ namespace http {
1220612227
}
1220712228
}
1220812229

12209-
//Will transfer NEW sensor log to OLD sensor,
12230+
//Will transfer Newest sensor log to OLD sensor,
1221012231
//then set the HardwareID/DeviceID/Unit/Name/Type/Subtype/Unit for the OLD sensor to the NEW sensor ID/Type/Subtype/Unit
1221112232
//then delete the NEW sensor
1221212233
void CWebServer::RType_TransferDevice(Json::Value &root)
@@ -12221,6 +12242,50 @@ namespace http {
1222112242

1222212243
std::stringstream szQuery;
1222312244
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("");
1222412289
szQuery << "SELECT HardwareID, DeviceID, Unit, Name, Type, SubType, SignalLevel, BatteryLevel, nValue, sValue FROM DeviceStatus WHERE (ID == " << newidx << ")";
1222512290
result = m_sql.query(szQuery.str());
1222612291
if (result.size() < 1)

main/mainworker.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,10 @@ void MainWorker::Do_Work()
10531053
{
10541054
m_ScheduleLastMinuteTime = atime;
10551055
m_ScheduleLastMinute = ltime.tm_min;
1056+
1057+
m_sql.CheckDeviceTimeout();
1058+
m_sql.CheckBatteryLow();
1059+
10561060
//check for 5 minute schedule
10571061
if (ltime.tm_min % 5 == 0)
10581062
{
@@ -1075,8 +1079,6 @@ void MainWorker::Do_Work()
10751079
m_ScheduleLastHourTime = atime;
10761080
m_ScheduleLastHour = ltime.tm_hour;
10771081
GetSunSettings();
1078-
m_sql.CheckDeviceTimeout();
1079-
m_sql.CheckBatteryLow();
10801082

10811083
//check for daily schedule
10821084
if (ltime.tm_hour == 0)

0 commit comments

Comments
 (0)