Skip to content

Commit d2d56f5

Browse files
committed
Mobile Device (Notification) Editor
GCM/FCM, default Active per device now, and using the active flag now Updated translations
1 parent e4efaea commit d2d56f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+344
-26
lines changed

main/SQLHelper.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define __STDC_FORMAT_MACROS
3333
#include <inttypes.h>
3434

35-
#define DB_VERSION 115
35+
#define DB_VERSION 116
3636

3737
extern http::server::CWebServerHelper m_webservers;
3838
extern std::string szWWWFolder;
@@ -627,6 +627,7 @@ const char *sqlCreateMobileDevices =
627627
"[ID] INTEGER PRIMARY KEY, "
628628
"[Active] BOOLEAN DEFAULT false, "
629629
"[Name] VARCHAR(100) DEFAULT '',"
630+
"[DeviceType] VARCHAR(100) DEFAULT '',"
630631
"[SenderID] TEXT NOT NULL,"
631632
"[UUID] TEXT NOT NULL, "
632633
"[LastUpdate] DATETIME DEFAULT(datetime('now', 'localtime'))"
@@ -2221,15 +2222,15 @@ bool CSQLHelper::OpenDatabase()
22212222
}
22222223
}
22232224
}
2224-
if (dbversion < 114)
2225-
{
2226-
//Set default values for new parameters in EcoDevices and Teleinfo EDF
2227-
std::stringstream szQuery1, szQuery2;
2228-
szQuery1 << "UPDATE Hardware SET Mode1 = 0, Mode2 = 60 WHERE Type =" << HTYPE_ECODEVICES ;
2229-
query(szQuery1.str());
2230-
szQuery2 << "UPDATE Hardware SET Mode1 = 0, Mode2 = 0, Mode3 = 60 WHERE Type =" << HTYPE_TeleinfoMeter ;
2231-
query(szQuery2.str());
2232-
}
2225+
if (dbversion < 114)
2226+
{
2227+
//Set default values for new parameters in EcoDevices and Teleinfo EDF
2228+
std::stringstream szQuery1, szQuery2;
2229+
szQuery1 << "UPDATE Hardware SET Mode1 = 0, Mode2 = 60 WHERE Type =" << HTYPE_ECODEVICES;
2230+
query(szQuery1.str());
2231+
szQuery2 << "UPDATE Hardware SET Mode1 = 0, Mode2 = 0, Mode3 = 60 WHERE Type =" << HTYPE_TeleinfoMeter;
2232+
query(szQuery2.str());
2233+
}
22332234
if (dbversion < 115)
22342235
{
22352236
//Patch for Evohome Web
@@ -2261,13 +2262,21 @@ bool CSQLHelper::OpenDatabase()
22612262
}
22622263
}
22632264
}
2264-
2265+
if (dbversion < 116)
2266+
{
2267+
//Patch for GCM/FCM
2268+
safe_query("UPDATE MobileDevices SET Active=1");
2269+
if (!DoesColumnExistsInTable("DeviceType", "MobileDevices"))
2270+
{
2271+
query("ALTER TABLE MobileDevices ADD COLUMN [DeviceType] VARCHAR(100) DEFAULT ('')");
2272+
}
2273+
}
22652274
}
22662275
else if (bNewInstall)
22672276
{
22682277
//place here actions that needs to be performed on new databases
22692278
query("INSERT INTO Plans (Name) VALUES ('$Hidden Devices')");
2270-
// Add hardawre for internal use
2279+
// Add hardware for internal use
22712280
m_sql.safe_query("INSERT INTO Hardware (Name, Enabled, Type, Address, Port, Username, Password, Mode1, Mode2, Mode3, Mode4, Mode5, Mode6) VALUES ('Domoticz Internal',1, %d,'',1,'','',0,0,0,0,0,0)", HTYPE_DomoticzInternal);
22722281
}
22732282
UpdatePreferencesVar("DB_Version",DB_VERSION);

main/WebServer.cpp

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,13 @@ namespace http {
538538
RegisterCommandCode("vacuumdatabase", boost::bind(&CWebServer::Cmd_VacuumDatabase, this, _1, _2, _3));
539539

540540
RegisterCommandCode("addmobiledevice", boost::bind(&CWebServer::Cmd_AddMobileDevice, this, _1, _2, _3));
541+
RegisterCommandCode("updatemobiledevice", boost::bind(&CWebServer::Cmd_UpdateMobileDevice, this, _1, _2, _3));
541542
RegisterCommandCode("deletemobiledevice", boost::bind(&CWebServer::Cmd_DeleteMobileDevice, this, _1, _2, _3));
542543

543544
RegisterCommandCode("addyeelight", boost::bind(&CWebServer::Cmd_AddYeeLight, this, _1, _2, _3));
544545

545-
546546
RegisterCommandCode("addArilux", boost::bind(&CWebServer::Cmd_AddArilux, this, _1, _2, _3));
547547

548-
549548
RegisterRType("graph", boost::bind(&CWebServer::RType_HandleGraph, this, _1, _2, _3));
550549
RegisterRType("lightlog", boost::bind(&CWebServer::RType_LightLog, this, _1, _2, _3));
551550
RegisterRType("textlog", boost::bind(&CWebServer::RType_TextLog, this, _1, _2, _3));
@@ -558,6 +557,7 @@ namespace http {
558557
RegisterRType("deletedevice", boost::bind(&CWebServer::RType_DeleteDevice, this, _1, _2, _3));
559558
RegisterRType("cameras", boost::bind(&CWebServer::RType_Cameras, this, _1, _2, _3));
560559
RegisterRType("users", boost::bind(&CWebServer::RType_Users, this, _1, _2, _3));
560+
RegisterRType("mobiles", boost::bind(&CWebServer::RType_Mobiles, this, _1, _2, _3));
561561

562562
RegisterRType("timers", boost::bind(&CWebServer::RType_Timers, this, _1, _2, _3));
563563
RegisterRType("scenetimers", boost::bind(&CWebServer::RType_SceneTimers, this, _1, _2, _3));
@@ -11214,6 +11214,43 @@ namespace http {
1121411214
}
1121511215
}
1121611216

11217+
void CWebServer::RType_Mobiles(WebEmSession & session, const request& req, Json::Value &root)
11218+
{
11219+
bool bHaveUser = (session.username != "");
11220+
int urights = 3;
11221+
if (bHaveUser)
11222+
{
11223+
int iUser = FindUser(session.username.c_str());
11224+
if (iUser != -1)
11225+
urights = static_cast<int>(m_users[iUser].userrights);
11226+
}
11227+
if (urights < 2)
11228+
return;
11229+
11230+
root["status"] = "OK";
11231+
root["title"] = "Mobiles";
11232+
11233+
std::vector<std::vector<std::string> > result;
11234+
result = m_sql.safe_query("SELECT ID, Active, Name, UUID, LastUpdate, DeviceType FROM MobileDevices ORDER BY Name ASC");
11235+
if (result.size() > 0)
11236+
{
11237+
std::vector<std::vector<std::string> >::const_iterator itt;
11238+
int ii = 0;
11239+
for (itt = result.begin(); itt != result.end(); ++itt)
11240+
{
11241+
std::vector<std::string> sd = *itt;
11242+
11243+
root["result"][ii]["idx"] = sd[0];
11244+
root["result"][ii]["Enabled"] = (sd[1] == "1") ? "true" : "false";
11245+
root["result"][ii]["Name"] = sd[2];
11246+
root["result"][ii]["UUID"] = sd[3];
11247+
root["result"][ii]["LastUpdate"] = sd[4];
11248+
root["result"][ii]["DeviceType"] = sd[5];
11249+
ii++;
11250+
}
11251+
}
11252+
}
11253+
1121711254
void CWebServer::Cmd_SetSetpoint(WebEmSession & session, const request& req, Json::Value &root)
1121811255
{
1121911256
bool bHaveUser = (session.username != "");
@@ -11759,7 +11796,7 @@ namespace http {
1175911796
if (result.empty())
1176011797
{
1176111798
//New
11762-
m_sql.safe_query("INSERT INTO MobileDevices (UUID,SenderID) VALUES ('%q','%q')", suuid.c_str(), ssenderid.c_str());
11799+
m_sql.safe_query("INSERT INTO MobileDevices (Active,UUID,SenderID) VALUES (1,'%q','%q')", suuid.c_str(), ssenderid.c_str());
1176311800
}
1176411801
else
1176511802
{
@@ -11775,6 +11812,34 @@ namespace http {
1177511812
}
1177611813
}
1177711814

11815+
void CWebServer::Cmd_UpdateMobileDevice(WebEmSession & session, const request& req, Json::Value &root)
11816+
{
11817+
if (session.rights != 2)
11818+
{
11819+
session.reply_status = reply::forbidden;
11820+
return; //Only admin user allowed
11821+
}
11822+
std::string sidx = request::findValue(&req, "idx");
11823+
std::string enabled = request::findValue(&req, "enabled");
11824+
std::string name = request::findValue(&req, "name");
11825+
11826+
if (
11827+
(sidx.empty()) ||
11828+
(enabled.empty()) ||
11829+
(name.empty())
11830+
)
11831+
return;
11832+
uint64_t idx = 0;
11833+
std::stringstream s_str(sidx);
11834+
s_str >> idx;
11835+
11836+
m_sql.safe_query("UPDATE MobileDevices SET Name='%q', Active=%d WHERE (ID==%" PRIu64 ")",
11837+
name.c_str(), (enabled == "true") ? 1 : 0, idx);
11838+
11839+
root["status"] = "OK";
11840+
root["title"] = "UpdateMobile";
11841+
}
11842+
1177811843
void CWebServer::Cmd_DeleteMobileDevice(WebEmSession & session, const request& req, Json::Value &root)
1177911844
{
1178011845
if (session.rights != 2)

main/WebServer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ class CWebServer : public session_store, public boost::enable_shared_from_this<C
255255
void Cmd_PanasonicClearNodes(WebEmSession & session, const request& req, Json::Value &root);
256256
void Cmd_PanasonicMediaCommand(WebEmSession & session, const request& req, Json::Value &root);
257257
void Cmd_AddMobileDevice(WebEmSession & session, const request& req, Json::Value &root);
258+
void Cmd_UpdateMobileDevice(WebEmSession & session, const request& req, Json::Value &root);
258259
void Cmd_DeleteMobileDevice(WebEmSession & session, const request& req, Json::Value &root);
259260
void Cmd_HEOSSetMode(WebEmSession & session, const request& req, Json::Value &root);
260261
void Cmd_HEOSMediaCommand(WebEmSession & session, const request& req, Json::Value &root);
@@ -293,6 +294,7 @@ class CWebServer : public session_store, public boost::enable_shared_from_this<C
293294
void RType_Devices(WebEmSession & session, const request& req, Json::Value &root);
294295
void RType_Cameras(WebEmSession & session, const request& req, Json::Value &root);
295296
void RType_Users(WebEmSession & session, const request& req, Json::Value &root);
297+
void RType_Mobiles(WebEmSession & session, const request& req, Json::Value &root);
296298
void RType_Timers(WebEmSession & session, const request& req, Json::Value &root);
297299
void RType_SceneTimers(WebEmSession & session, const request& req, Json::Value &root);
298300
void RType_SetpointTimers(WebEmSession & session, const request& req, Json::Value &root);

msbuild/domoticz.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<None Include="..\www\app\LoginController.js" />
131131
<None Include="..\www\app\LogoutController.js" />
132132
<None Include="..\www\app\main.js" />
133+
<None Include="..\www\app\MobileNotificationsController.js" />
133134
<None Include="..\www\app\NotificationController.js" />
134135
<None Include="..\www\app\OfflineController.js" />
135136
<None Include="..\www\app\RestoreDatabaseController.js" />
@@ -1344,4 +1345,4 @@
13441345
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
13451346
<ImportGroup Label="ExtensionTargets">
13461347
</ImportGroup>
1347-
</Project>
1348+
</Project>

msbuild/domoticz.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,9 @@
13251325
<None Include="..\www\views\floorplans.html">
13261326
<Filter>www\views</Filter>
13271327
</None>
1328+
<None Include="..\www\app\MobileNotificationsController.js">
1329+
<Filter>www\app</Filter>
1330+
</None>
13281331
</ItemGroup>
13291332
<ItemGroup>
13301333
<ClInclude Include="..\webserver\Base64.h">

notifications/NotificationGCM.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool CNotificationGCM::SendMessageImplementation(
3232

3333
//Get All Devices
3434
std::vector<std::vector<std::string> > result;
35-
result = m_sql.safe_query("SELECT SenderID, Active FROM MobileDevices");// WHERE(Active == true)");
35+
result = m_sql.safe_query("SELECT SenderID FROM MobileDevices WHERE (Active == 1)");
3636
if (result.empty())
3737
return true;
3838

@@ -45,14 +45,10 @@ bool CNotificationGCM::SendMessageImplementation(
4545
for (itt = result.begin(); itt != result.end(); ++itt)
4646
{
4747
std::vector<std::string> sd = *itt;
48-
//bool Active = (sd[1] == "true");
49-
//if (Active)
50-
{
51-
if (ii != 0)
52-
sstr << ", ";
53-
sstr << "\"" << sd[0] << "\"";
54-
ii++;
55-
}
48+
if (ii != 0)
49+
sstr << ", ";
50+
sstr << "\"" << sd[0] << "\"";
51+
ii++;
5652
}
5753
sstr << "], \"data\" : { \"subject\": \""<< Subject << "\", \"body\": \""<< Text << "\", \"extradata\": \""<< ExtraData << "\", \"priority\": \""<< boost::lexical_cast<std::string>(Priority) << "\", ";
5854
sstr << "\"deviceid\": \""<< boost::lexical_cast<std::string>(Idx) << "\", \"message\": \"" << Subject << "\" } }";

0 commit comments

Comments
 (0)