Skip to content

Commit d775daa

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 3011df5 + 095f3d5 commit d775daa

14 files changed

+421
-60
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ hardware/ZWaveBase.cpp
278278
MQTT/mosquittopp.cpp
279279
notifications/NotificationBase.cpp
280280
notifications/NotificationEmail.cpp
281+
notifications/NotificationGCM.cpp
281282
notifications/NotificationHelper.cpp
282283
notifications/NotificationHTTP.cpp
283284
notifications/NotificationKodi.cpp

main/EventSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,7 @@ void CEventSystem::UpdateDevice(const std::string &DevParams)
30313031
break;
30323032
}
30333033
case pTypeGeneral:
3034-
if ((devType == pTypeGeneral) && (subType != sTypeTextStatus) && (subType != sTypeAlert))
3034+
if ((devType == pTypeGeneral) && (subType != sTypeTextStatus) && (subType != sTypeAlert) && (subType != sTypeSwitch))
30353035
{
30363036
break;
30373037
}

main/RFXNames.cpp

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ const char *RFX_Type_SubType_Desc(const unsigned char dType, const unsigned char
671671
{ pTypeGeneral, sTypeCounterIncremental, "Counter Incremental" },
672672
{ pTypeGeneral, sTypeKwh, "kWh" },
673673
{ pTypeGeneral, sTypeWaterflow, "Waterflow" },
674+
{ pTypeGeneral, sTypeSwitch, "Switch" },
674675

675676
{ pTypeThermostat, sTypeThermSetpoint, "SetPoint" },
676677
{ pTypeThermostat, sTypeThermTemperature, "Temperature" },
@@ -983,6 +984,7 @@ const char *RFX_Type_SubType_Values(const unsigned char dType, const unsigned ch
983984
{ pTypeGeneral, sTypeCounterIncremental, "Counter Incremental" },
984985
{ pTypeGeneral, sTypeKwh, "Instant,Usage" },
985986
{ pTypeGeneral, sTypeWaterflow, "Percentage" },
987+
{ pTypeGeneral, sTypeSwitch, "Status" },
986988

987989
{ pTypeThermostat, sTypeThermSetpoint, "Temperature" },
988990
{ pTypeThermostat, sTypeThermTemperature, "Temperature" },
@@ -1557,6 +1559,48 @@ void GetLightStatus(
15571559
break;
15581560
}
15591561
break;
1562+
case pTypeGeneral:
1563+
switch (dSubType)
1564+
{
1565+
case sTypeSwitch:
1566+
{
1567+
maxDimLevel = 100;
1568+
bHaveDimmer = true;
1569+
llevel = (int)float((100.0f / float(maxDimLevel))*atof(sValue.c_str()));
1570+
bHaveGroupCmd = true;
1571+
switch (nValue)
1572+
{
1573+
case gswitch_sOff:
1574+
lstatus = "Off";
1575+
break;
1576+
case gswitch_sOn:
1577+
lstatus = "On";
1578+
break;
1579+
case gswitch_sSetLevel:
1580+
sprintf(szTmp, "Set Level: %d %%", llevel);
1581+
if (sValue != "0")
1582+
lstatus = szTmp;
1583+
else
1584+
lstatus = "Off";
1585+
break;
1586+
case gswitch_sGroupOff:
1587+
lstatus = "Group Off";
1588+
break;
1589+
case gswitch_sGroupOn:
1590+
lstatus = "Group On";
1591+
break;
1592+
case gswitch_sSetGroupLevel:
1593+
sprintf(szTmp, "Set Group Level: %d %%", atoi(sValue.c_str()));
1594+
if (sValue != "0")
1595+
lstatus = szTmp;
1596+
else
1597+
lstatus = "Off";
1598+
break;
1599+
}
1600+
}
1601+
break;
1602+
}
1603+
break;
15601604
case pTypeGeneralSwitch:
15611605
maxDimLevel = 100;
15621606

@@ -2366,6 +2410,106 @@ bool GetLightCommand(
23662410
else
23672411
return false;
23682412
break;
2413+
case pTypeGeneral:
2414+
switch (dSubType)
2415+
{
2416+
case sTypeSwitch:
2417+
{
2418+
if (switchtype == STYPE_Doorbell)
2419+
{
2420+
if ((switchcmd == "On") || (switchcmd == "Group On"))
2421+
{
2422+
cmd = gswitch_sGroupOn;
2423+
return true;
2424+
}
2425+
//no other combinations for the door switch
2426+
return false;
2427+
}
2428+
else if (switchtype == STYPE_X10Siren)
2429+
{
2430+
if ((switchcmd == "On") || (switchcmd == "Group On"))
2431+
{
2432+
cmd = gswitch_sGroupOn;
2433+
return true;
2434+
}
2435+
else if ((switchcmd == "Off") || (switchcmd == "Group Off"))
2436+
{
2437+
cmd = gswitch_sGroupOff;
2438+
return true;
2439+
}
2440+
return false;
2441+
}
2442+
if (switchcmd == "Off")
2443+
{
2444+
cmd = gswitch_sOff;
2445+
return true;
2446+
}
2447+
else if (switchcmd == "On")
2448+
{
2449+
cmd = gswitch_sOn;
2450+
return true;
2451+
}
2452+
else if (switchcmd == "Set Level")
2453+
{
2454+
cmd = gswitch_sSetLevel;
2455+
return true;
2456+
}
2457+
else if (switchcmd == "Group Off")
2458+
{
2459+
cmd = gswitch_sGroupOff;
2460+
return true;
2461+
}
2462+
else if (switchcmd == "Group On")
2463+
{
2464+
cmd = gswitch_sGroupOn;
2465+
return true;
2466+
}
2467+
else if (switchcmd == "Set Group Level")
2468+
{
2469+
cmd = gswitch_sSetGroupLevel;
2470+
return true;
2471+
}
2472+
else if (switchcmd == "Stop")
2473+
{
2474+
cmd = gswitch_sStop;
2475+
return true;
2476+
}
2477+
else if ((switchcmd == "Paused") || (switchcmd == "Pause"))
2478+
{
2479+
cmd = gswitch_sPause;
2480+
return true;
2481+
}
2482+
else if ((switchcmd == "Playing") || (switchcmd == "Play"))
2483+
{
2484+
cmd = gswitch_sPlay;
2485+
return true;
2486+
}
2487+
else if (switchcmd == "Play Playlist")
2488+
{
2489+
cmd = gswitch_sPlayPlaylist;
2490+
return true;
2491+
}
2492+
else if (switchcmd == "Play Favorites")
2493+
{
2494+
cmd = gswitch_sPlayFavorites;
2495+
return true;
2496+
}
2497+
else if (switchcmd == "Set Volume")
2498+
{
2499+
cmd = gswitch_sSetVolume;
2500+
return true;
2501+
}
2502+
else if (switchcmd == "Execute")
2503+
{
2504+
cmd = gswitch_sExecute;
2505+
return true;
2506+
}
2507+
else
2508+
return false;
2509+
}
2510+
break;
2511+
}
2512+
break;
23692513
case pTypeGeneralSwitch:
23702514
if (switchtype == STYPE_Doorbell)
23712515
{

main/SQLHelper.cpp

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

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

3636
extern http::server::CWebServerHelper m_webservers;
3737
extern std::string szWWWFolder;
@@ -580,6 +580,16 @@ const char *sqlCreateUserSessions =
580580
" [LastUpdate] DATETIME DEFAULT(datetime('now', 'localtime')),"
581581
" PRIMARY KEY([SessionID]));";
582582

583+
const char *sqlCreateMobileDevices =
584+
"CREATE TABLE IF NOT EXISTS [MobileDevices]("
585+
"[ID] INTEGER PRIMARY KEY, "
586+
"[Active] BOOLEAN DEFAULT false, "
587+
"[Name] VARCHAR(100) DEFAULT '',"
588+
"[SenderID] TEXT NOT NULL,"
589+
"[UUID] TEXT NOT NULL, "
590+
"[LastUpdate] DATETIME DEFAULT(datetime('now', 'localtime'))"
591+
");";
592+
583593
extern std::string szUserDataFolder;
584594

585595
CSQLHelper::CSQLHelper(void)
@@ -701,6 +711,7 @@ bool CSQLHelper::OpenDatabase()
701711
query(sqlCreateMySensorsChilds);
702712
query(sqlCreateToonDevices);
703713
query(sqlCreateUserSessions);
714+
query(sqlCreateMobileDevices);
704715
//Add indexes to log tables
705716
query("create index if not exists f_idx on Fan(DeviceRowID);");
706717
query("create index if not exists fc_idx on Fan_Calendar(DeviceRowID);");
@@ -1738,7 +1749,10 @@ bool CSQLHelper::OpenDatabase()
17381749
query("ALTER TABLE SetpointTimers ADD COLUMN [Occurence] INTEGER DEFAULT 0");
17391750
}
17401751
}
1741-
1752+
if (dbversion < 96)
1753+
{
1754+
query("ALTER TABLE MobileDevices ADD COLUMN [Name] VARCHAR(100) DEFAULT ''");
1755+
}
17421756
}
17431757
else if (bNewInstall)
17441758
{

main/WebServer.cpp

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ namespace http {
533533
RegisterCommandCode("clearshortlog", boost::bind(&CWebServer::Cmd_ClearShortLog, this, _1, _2, _3));
534534
RegisterCommandCode("vacuumdatabase", boost::bind(&CWebServer::Cmd_VacuumDatabase, this, _1, _2, _3));
535535

536+
RegisterCommandCode("addmobiledevice", boost::bind(&CWebServer::Cmd_AddMobileDevice, this, _1, _2, _3));
537+
RegisterCommandCode("deletemobiledevice", boost::bind(&CWebServer::Cmd_DeleteMobileDevice, this, _1, _2, _3));
538+
536539
RegisterRType("graph", boost::bind(&CWebServer::RType_HandleGraph, this, _1, _2, _3));
537540
RegisterRType("lightlog", boost::bind(&CWebServer::RType_LightLog, this, _1, _2, _3));
538541
RegisterRType("textlog", boost::bind(&CWebServer::RType_TextLog, this, _1, _2, _3));
@@ -10827,7 +10830,55 @@ namespace http {
1082710830
m_sql.VacuumDatabase();
1082810831
}
1082910832

10830-
10833+
void CWebServer::Cmd_AddMobileDevice(WebEmSession & session, const request& req, Json::Value &root)
10834+
{
10835+
std::string suuid = request::findValue(&req, "uuid");
10836+
std::string ssenderid = request::findValue(&req, "senderid");
10837+
if (
10838+
(suuid.empty()) ||
10839+
(ssenderid.empty())
10840+
)
10841+
return;
10842+
root["status"] = "OK";
10843+
root["title"] = "AddMobileDevice";
10844+
10845+
std::vector<std::vector<std::string> > result;
10846+
result = m_sql.safe_query("SELECT ID FROM MobileDevices WHERE (UUID=='%q')", suuid.c_str());
10847+
if (result.empty())
10848+
{
10849+
//New
10850+
m_sql.safe_query("INSERT INTO MobileDevices (UUID,SenderID) VALUES ('%q','%q')", suuid.c_str(), ssenderid.c_str());
10851+
}
10852+
else
10853+
{
10854+
//Update
10855+
time_t now = time(0);
10856+
struct tm ltime;
10857+
localtime_r(&now, &ltime);
10858+
m_sql.safe_query("UPDATE MobileDevices SET SenderID='%q', LastUpdate='%04d-%02d-%02d %02d:%02d:%02d' WHERE (UUID == '%q')",
10859+
ssenderid.c_str(),
10860+
ltime.tm_year + 1900, ltime.tm_mon + 1, ltime.tm_mday, ltime.tm_hour, ltime.tm_min, ltime.tm_sec,
10861+
suuid.c_str()
10862+
);
10863+
}
10864+
}
10865+
10866+
void CWebServer::Cmd_DeleteMobileDevice(WebEmSession & session, const request& req, Json::Value &root)
10867+
{
10868+
if (session.rights != 2)
10869+
return;//Only admin user allowed
10870+
std::string suuid = request::findValue(&req, "uuid");
10871+
if (suuid.empty())
10872+
return;
10873+
std::vector<std::vector<std::string> > result;
10874+
result = m_sql.safe_query("SELECT ID FROM MobileDevices WHERE (UUID=='%q')", suuid.c_str());
10875+
if (result.empty())
10876+
return;
10877+
m_sql.safe_query("DELETE FROM MobileDevices WHERE (UUID == '%q')", suuid.c_str());
10878+
root["status"] = "OK";
10879+
root["title"] = "DeleteMobileDevice";
10880+
}
10881+
1083110882

1083210883
void CWebServer::RType_GetTransfers(WebEmSession & session, const request& req, Json::Value &root)
1083310884
{
@@ -10962,9 +11013,12 @@ namespace http {
1096211013
std::map<std::string, CNotificationBase*>::const_iterator ittNotifiers;
1096311014
for (ittNotifiers = m_notifications.m_notifiers.begin(); ittNotifiers != m_notifications.m_notifiers.end(); ++ittNotifiers)
1096411015
{
10965-
root["notifiers"][ii]["name"] = ittNotifiers->first;
10966-
root["notifiers"][ii]["description"] = ittNotifiers->first;
10967-
ii++;
11016+
if (ittNotifiers->first != "gcm")
11017+
{
11018+
root["notifiers"][ii]["name"] = ittNotifiers->first;
11019+
root["notifiers"][ii]["description"] = ittNotifiers->first;
11020+
ii++;
11021+
}
1096811022
}
1096911023

1097011024
unsigned long long idx = 0;

main/WebServer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ class CWebServer : public session_store
208208
void Cmd_GetHttpLinks(WebEmSession & session, const request& req, Json::Value &root);
209209
void Cmd_SaveHttpLink(WebEmSession & session, const request& req, Json::Value &root);
210210
void Cmd_DeleteHttpLink(WebEmSession & session, const request& req, Json::Value &root);
211-
void Cmd_GetDevicesForHttpLink(WebEmSession & session, const request& req, Json::Value &root);
212211
void Cmd_AddLogMessage(WebEmSession & session, const request& req, Json::Value &root);
213212
void Cmd_ClearShortLog(WebEmSession & session, const request& req, Json::Value &root);
214213
void Cmd_VacuumDatabase(WebEmSession & session, const request& req, Json::Value &root);
@@ -219,6 +218,8 @@ class CWebServer : public session_store
219218
void Cmd_PanasonicRemoveNode(WebEmSession & session, const request& req, Json::Value &root);
220219
void Cmd_PanasonicClearNodes(WebEmSession & session, const request& req, Json::Value &root);
221220
void Cmd_PanasonicMediaCommand(WebEmSession & session, const request& req, Json::Value &root);
221+
void Cmd_AddMobileDevice(WebEmSession & session, const request& req, Json::Value &root);
222+
void Cmd_DeleteMobileDevice(WebEmSession & session, const request& req, Json::Value &root);
222223

223224

224225
//RTypes

0 commit comments

Comments
 (0)