Skip to content

Commit 45fe40b

Browse files
committed
Correcting on/off actions with http text as parameter (3236)
1 parent aab10ed commit 45fe40b

File tree

3 files changed

+80
-70
lines changed

3 files changed

+80
-70
lines changed

hardware/EvohomeScript.cpp

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
* Original header and copyright notice below
66
*/
77

8-
/**
9-
* Evohome class for HGI80 gateway, evohome control, monitoring and integration with Domoticz
10-
*
11-
* Copyright 2014 - fullTalgoRythm https://github.com/fullTalgoRythm/Domoticz-evohome
12-
*
13-
* Licensed under GNU General Public License 3.0 or later.
14-
* Some rights reserved. See COPYING, AUTHORS.
15-
*
16-
* @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
17-
*
18-
* based in part on https://github.com/mouse256/evomon
19-
* and details available at http://www.domoticaforum.eu/viewtopic.php?f=7&t=5806&start=90#p72564
20-
*/
8+
/**
9+
* Evohome class for HGI80 gateway, evohome control, monitoring and integration with Domoticz
10+
*
11+
* Copyright 2014 - fullTalgoRythm https://github.com/fullTalgoRythm/Domoticz-evohome
12+
*
13+
* Licensed under GNU General Public License 3.0 or later.
14+
* Some rights reserved. See COPYING, AUTHORS.
15+
*
16+
* @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
17+
*
18+
* based in part on https://github.com/mouse256/evomon
19+
* and details available at http://www.domoticaforum.eu/viewtopic.php?f=7&t=5806&start=90#p72564
20+
*/
2121
#include "stdafx.h"
2222
#include "EvohomeScript.h"
2323
#include "../main/Logger.h"
2424
#include "hardwaretypes.h"
25-
//#include "../main/RFXtrx.h"
26-
//#include "../main/Helper.h"
25+
//#include "../main/RFXtrx.h"
26+
//#include "../main/Helper.h"
2727
#include "../main/SQLHelper.h"
2828
//#include "../main/localtime_r.h"
2929
#include "../main/mainworker.h"
@@ -35,14 +35,14 @@ extern std::string szUserDataFolder;
3535

3636
CEvohomeScript::CEvohomeScript(const int ID)
3737
{
38-
m_HwdID=ID;
38+
m_HwdID = ID;
3939
m_bSkipReceiveCheck = true;
4040
}
4141

4242

4343
CEvohomeScript::~CEvohomeScript(void)
4444
{
45-
m_bIsStarted=false;
45+
m_bIsStarted = false;
4646
}
4747

4848

@@ -57,67 +57,67 @@ bool CEvohomeScript::StartHardware()
5757
RequestStart();
5858

5959
Init();
60-
m_bIsStarted=true;
60+
m_bIsStarted = true;
6161
sOnConnected(this);
6262
return true;
6363
}
6464

6565

6666
bool CEvohomeScript::StopHardware()
6767
{
68-
m_bIsStarted=false;
68+
m_bIsStarted = false;
6969
return true;
7070
}
7171

7272

73-
bool CEvohomeScript::WriteToHardware(const char *pdata, const unsigned char length)
73+
bool CEvohomeScript::WriteToHardware(const char* pdata, const unsigned char length)
7474
{
75-
if(!pdata)
75+
if (!pdata)
7676
return false;
7777
switch (pdata[1])
7878
{
79-
case pTypeEvohome:
80-
if (length<sizeof(_tEVOHOME1))
81-
return false;
82-
//This is a switch so the on action script will be run anyway
83-
break;
84-
case pTypeEvohomeZone:
85-
if (length<sizeof(_tEVOHOME2))
86-
return false;
87-
RunScript(pdata,length);
88-
break;
89-
case pTypeEvohomeWater:
90-
if (length<sizeof(_tEVOHOME2))
91-
return false;
92-
RunScript(pdata,length);
93-
break;
94-
case pTypeEvohomeRelay:
95-
if (length<sizeof(_tEVOHOME3))
96-
return false;
97-
//Only supported by HGI80
98-
break;
79+
case pTypeEvohome:
80+
if (length < sizeof(_tEVOHOME1))
81+
return false;
82+
//This is a switch so the on action script will be run anyway
83+
break;
84+
case pTypeEvohomeZone:
85+
if (length < sizeof(_tEVOHOME2))
86+
return false;
87+
RunScript(pdata, length);
88+
break;
89+
case pTypeEvohomeWater:
90+
if (length < sizeof(_tEVOHOME2))
91+
return false;
92+
RunScript(pdata, length);
93+
break;
94+
case pTypeEvohomeRelay:
95+
if (length < sizeof(_tEVOHOME3))
96+
return false;
97+
//Only supported by HGI80
98+
break;
9999
}
100100
return true;
101101
}
102102

103103

104-
void CEvohomeScript::RunScript(const char *pdata, const unsigned char /*length*/)
104+
void CEvohomeScript::RunScript(const char* pdata, const unsigned char /*length*/)
105105
{
106-
if(!pdata)
106+
if (!pdata)
107107
return;
108-
_tEVOHOME2 *tsen=(_tEVOHOME2*)pdata;
108+
_tEVOHOME2* tsen = (_tEVOHOME2*)pdata;
109109
std::vector<std::vector<std::string> > result;
110-
result = m_sql.safe_query("SELECT HardwareID, DeviceID,Unit,Type,SubType,SwitchType,StrParam1 FROM DeviceStatus WHERE (HardwareID==%d) AND (Unit==%d) AND (Type==%d)", m_HwdID, (int)tsen->zone, (int)tsen->type);
110+
result = m_sql.safe_query("SELECT HardwareID, DeviceID,Unit,Type,SubType,SwitchType,StrParam1 FROM DeviceStatus WHERE (HardwareID==%d) AND (Unit==%d) AND (Type==%d)", m_HwdID, (int)tsen->zone, (int)tsen->type);
111111
if (!result.empty())
112112
{
113113
unsigned long ID;
114-
std::vector<std::string> sd=result[0];
114+
std::vector<std::string> sd = result[0];
115115
std::stringstream s_strid;
116116
s_strid << std::hex << sd[1];
117117
s_strid >> ID;
118-
118+
119119
std::string OnAction(sd[6]);
120-
if (OnAction.find("script://")!=std::string::npos)
120+
if (OnAction.find("script://") == 0)
121121
{
122122
s_strid.clear();
123123
s_strid.str("");
@@ -146,21 +146,21 @@ void CEvohomeScript::RunScript(const char *pdata, const unsigned char /*length*/
146146
if (scriptname.find("/") != 0)
147147
scriptname = szUserDataFolder + "scripts/" + scriptname;
148148
#endif
149-
std::string scriptparams="";
149+
std::string scriptparams = "";
150150
//Add parameters
151-
int pindex=scriptname.find(' ');
152-
if (pindex!=std::string::npos)
151+
int pindex = scriptname.find(' ');
152+
if (pindex != std::string::npos)
153153
{
154-
scriptparams=scriptname.substr(pindex+1);
155-
scriptname=scriptname.substr(0,pindex);
154+
scriptparams = scriptname.substr(pindex + 1);
155+
scriptname = scriptname.substr(0, pindex);
156156
}
157-
157+
158158
if (file_exist(scriptname.c_str()))
159159
{
160-
m_sql.AddTaskItem(_tTaskItem::ExecuteScript(0.2f,scriptname,scriptparams));
160+
m_sql.AddTaskItem(_tTaskItem::ExecuteScript(0.2f, scriptname, scriptparams));
161161
}
162162
else
163-
_log.Log(LOG_ERROR,"evohome: Error script not found '%s'",scriptname.c_str());
163+
_log.Log(LOG_ERROR, "evohome: Error script not found '%s'", scriptname.c_str());
164164
}
165165
}
166166
}

main/SQLHelper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7462,11 +7462,11 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
74627462
if (OnAction.empty())
74637463
return true;
74647464

7465-
if ((OnAction.find("http://") != std::string::npos) || (OnAction.find("https://") != std::string::npos))
7465+
if ((OnAction.find("http://") == 0) || (OnAction.find("https://") == 0))
74667466
{
74677467
AddTaskItem(_tTaskItem::GetHTTPPage(0.2f, OnAction, "SwitchActionOn"));
74687468
}
7469-
else if (OnAction.find("script://") != std::string::npos)
7469+
else if (OnAction.find("script://") == 0)
74707470
{
74717471
//Execute possible script
74727472
if (OnAction.find("../") != std::string::npos)
@@ -7502,11 +7502,11 @@ bool CSQLHelper::HandleOnOffAction(const bool bIsOn, const std::string &OnAction
75027502
if (OffAction.empty())
75037503
return true;
75047504

7505-
if ((OffAction.find("http://") != std::string::npos) || (OffAction.find("https://") != std::string::npos))
7505+
if ((OffAction.find("http://") == 0) || (OffAction.find("https://") == 0))
75067506
{
75077507
AddTaskItem(_tTaskItem::GetHTTPPage(0.2f, OffAction, "SwitchActionOff"));
75087508
}
7509-
else if (OffAction.find("script://") != std::string::npos)
7509+
else if (OffAction.find("script://") == 0)
75107510
{
75117511
//Execute possible script
75127512
if (OffAction.find("../") != std::string::npos)

www/app/ScenesController.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,38 @@ define(['app'], function (app) {
106106
var offaction = $("#scenecontent #offaction").val();
107107

108108
if (onaction != "") {
109-
if ((onaction.indexOf("http://") != 0) && (onaction.indexOf("https://") != 0) && (onaction.indexOf("script://") != 0)) {
110-
bootbox.alert($.t("Invalid ON Action!"));
111-
return;
112-
}
113-
else {
109+
if (
110+
(onaction.indexOf("http://") == 0) ||
111+
(onaction.indexOf("https://") == 0) ||
112+
(onaction.indexOf("script://") == 0)
113+
)
114+
{
114115
if (checkLength($("#scenecontent #onaction"), 10, 500) == false) {
115116
bootbox.alert($.t("Invalid ON Action!"));
116117
return;
117118
}
118119
}
119-
}
120-
if (offaction != "") {
121-
if ((offaction.indexOf("http://") != 0) && (offaction.indexOf("https://") != 0) && (offaction.indexOf("script://") != 0)) {
122-
bootbox.alert($.t("Invalid Off Action!"));
120+
else {
121+
bootbox.alert($.t("Invalid ON Action!"));
123122
return;
124123
}
125-
else {
124+
}
125+
if (offaction != "") {
126+
if (
127+
(offaction.indexOf("http://") == 0) ||
128+
(offaction.indexOf("https://") == 0) ||
129+
(offaction.indexOf("script://") == 0)
130+
)
131+
{
126132
if (checkLength($("#scenecontent #offaction"), 10, 500) == false) {
127133
bootbox.alert($.t("Invalid Off Action!"));
128134
return;
129135
}
130136
}
137+
else {
138+
bootbox.alert($.t("Invalid Off Action!"));
139+
return;
140+
}
131141
}
132142

133143
if (bValid) {

0 commit comments

Comments
 (0)