5
5
* Original header and copyright notice below
6
6
*/
7
7
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
+ */
21
21
#include " stdafx.h"
22
22
#include " EvohomeScript.h"
23
23
#include " ../main/Logger.h"
24
24
#include " hardwaretypes.h"
25
- // #include "../main/RFXtrx.h"
26
- // #include "../main/Helper.h"
25
+ // #include "../main/RFXtrx.h"
26
+ // #include "../main/Helper.h"
27
27
#include " ../main/SQLHelper.h"
28
28
// #include "../main/localtime_r.h"
29
29
#include " ../main/mainworker.h"
@@ -35,14 +35,14 @@ extern std::string szUserDataFolder;
35
35
36
36
CEvohomeScript::CEvohomeScript (const int ID)
37
37
{
38
- m_HwdID= ID;
38
+ m_HwdID = ID;
39
39
m_bSkipReceiveCheck = true ;
40
40
}
41
41
42
42
43
43
CEvohomeScript::~CEvohomeScript (void )
44
44
{
45
- m_bIsStarted= false ;
45
+ m_bIsStarted = false ;
46
46
}
47
47
48
48
@@ -57,67 +57,67 @@ bool CEvohomeScript::StartHardware()
57
57
RequestStart ();
58
58
59
59
Init ();
60
- m_bIsStarted= true ;
60
+ m_bIsStarted = true ;
61
61
sOnConnected (this );
62
62
return true ;
63
63
}
64
64
65
65
66
66
bool CEvohomeScript::StopHardware ()
67
67
{
68
- m_bIsStarted= false ;
68
+ m_bIsStarted = false ;
69
69
return true ;
70
70
}
71
71
72
72
73
- bool CEvohomeScript::WriteToHardware (const char * pdata, const unsigned char length)
73
+ bool CEvohomeScript::WriteToHardware (const char * pdata, const unsigned char length)
74
74
{
75
- if (!pdata)
75
+ if (!pdata)
76
76
return false ;
77
77
switch (pdata[1 ])
78
78
{
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 ;
99
99
}
100
100
return true ;
101
101
}
102
102
103
103
104
- void CEvohomeScript::RunScript (const char * pdata, const unsigned char /* length*/ )
104
+ void CEvohomeScript::RunScript (const char * pdata, const unsigned char /* length*/ )
105
105
{
106
- if (!pdata)
106
+ if (!pdata)
107
107
return ;
108
- _tEVOHOME2 * tsen= (_tEVOHOME2*)pdata;
108
+ _tEVOHOME2* tsen = (_tEVOHOME2*)pdata;
109
109
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 );
111
111
if (!result.empty ())
112
112
{
113
113
unsigned long ID;
114
- std::vector<std::string> sd= result[0 ];
114
+ std::vector<std::string> sd = result[0 ];
115
115
std::stringstream s_strid;
116
116
s_strid << std::hex << sd[1 ];
117
117
s_strid >> ID;
118
-
118
+
119
119
std::string OnAction (sd[6 ]);
120
- if (OnAction.find (" script://" )!=std::string::npos )
120
+ if (OnAction.find (" script://" ) == 0 )
121
121
{
122
122
s_strid.clear ();
123
123
s_strid.str (" " );
@@ -146,21 +146,21 @@ void CEvohomeScript::RunScript(const char *pdata, const unsigned char /*length*/
146
146
if (scriptname.find (" /" ) != 0 )
147
147
scriptname = szUserDataFolder + " scripts/" + scriptname;
148
148
#endif
149
- std::string scriptparams= " " ;
149
+ std::string scriptparams = " " ;
150
150
// Add parameters
151
- int pindex= scriptname.find (' ' );
152
- if (pindex!= std::string::npos)
151
+ int pindex = scriptname.find (' ' );
152
+ if (pindex != std::string::npos)
153
153
{
154
- scriptparams= scriptname.substr (pindex+ 1 );
155
- scriptname= scriptname.substr (0 ,pindex);
154
+ scriptparams = scriptname.substr (pindex + 1 );
155
+ scriptname = scriptname.substr (0 , pindex);
156
156
}
157
-
157
+
158
158
if (file_exist (scriptname.c_str ()))
159
159
{
160
- m_sql.AddTaskItem (_tTaskItem::ExecuteScript (0 .2f ,scriptname,scriptparams));
160
+ m_sql.AddTaskItem (_tTaskItem::ExecuteScript (0 .2f , scriptname, scriptparams));
161
161
}
162
162
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 ());
164
164
}
165
165
}
166
166
}
0 commit comments