@@ -231,7 +231,7 @@ void MySensorsBase::LoadDevicesFromDatabase()
231
231
boost::lock_guard<boost::mutex> l (readQueueMutex);
232
232
m_nodes.clear ();
233
233
234
- std::vector<std::vector<std::string> > result;
234
+ std::vector<std::vector<std::string> > result,result2 ;
235
235
result = m_sql.safe_query (" SELECT ID, Name, SketchName, SketchVersion FROM MySensors WHERE (HardwareID=%d) ORDER BY ID ASC" , m_HwdID);
236
236
if (result.size () > 0 )
237
237
{
@@ -251,6 +251,23 @@ void MySensorsBase::LoadDevicesFromDatabase()
251
251
mNode .SketchName = SkectName;
252
252
mNode .SketchVersion = SkectVersion;
253
253
mNode .lastreceived = 0 ;
254
+ // Load the Childs
255
+ result2 = m_sql.safe_query (" SELECT ChildID, [Type], [Name], UseAck FROM MySensorsChilds WHERE (HardwareID=%d) AND (NodeID=%d) ORDER BY ChildID ASC" , m_HwdID, ID);
256
+ if (result2.size () > 0 )
257
+ {
258
+ std::vector<std::vector<std::string> >::const_iterator itt2;
259
+ for (itt2 = result2.begin (); itt2 != result2.end (); ++itt2)
260
+ {
261
+ std::vector<std::string> sd2 = *itt2;
262
+ _tMySensorChild mSensor ;
263
+ mSensor .nodeID = ID;
264
+ mSensor .childID = atoi (sd2[0 ].c_str ());
265
+ mSensor .presType = (_ePresentationType)atoi (sd2[1 ].c_str ());
266
+ mSensor .childName = sd2[2 ];
267
+ mSensor .useAck = atoi (sd2[3 ].c_str ()) != 0 ;
268
+ mNode .m_childs .push_back (mSensor );
269
+ }
270
+ }
254
271
m_nodes[ID] = mNode ;
255
272
}
256
273
}
@@ -1144,12 +1161,12 @@ bool MySensorsBase::WriteToHardware(const char *pdata, const unsigned char lengt
1144
1161
if ((light_command == light2_sOn) || (light_command == light2_sOff))
1145
1162
{
1146
1163
std::string lState = (light_command == light2_sOn) ? " 1" : " 0" ;
1147
- if (FindChildWithValueType (node_id, V_LOCK_STATUS) != NULL )
1164
+ if (pChild-> presType == S_LOCK )
1148
1165
{
1149
1166
// Door lock
1150
1167
return SendNodeSetCommand (node_id, child_sensor_id, MT_Set, V_LOCK_STATUS, lState, pChild->useAck );
1151
1168
}
1152
- else if (( FindChildWithValueType (node_id, V_SCENE_ON) != NULL ) || ( FindChildWithValueType (node_id, V_SCENE_OFF) != NULL ) )
1169
+ else if (pChild-> presType == S_SCENE_CONTROLLER )
1153
1170
{
1154
1171
// Scene Controller
1155
1172
return SendNodeSetCommand (node_id, child_sensor_id, MT_Set, (light_command == light2_sOn) ? V_SCENE_ON : V_SCENE_OFF, lState, pChild->useAck );
@@ -2027,8 +2044,7 @@ namespace http {
2027
2044
std::vector<std::vector<std::string> > result, result2;
2028
2045
char szTmp[100 ];
2029
2046
2030
- result = m_sql.safe_query (" SELECT ID,Name,SketchName,SketchVersion FROM MySensors WHERE (HardwareID==%d) ORDER BY ID ASC" ,
2031
- iHardwareID);
2047
+ result = m_sql.safe_query (" SELECT ID,Name,SketchName,SketchVersion FROM MySensors WHERE (HardwareID==%d) ORDER BY ID ASC" , iHardwareID);
2032
2048
if (result.size () > 0 )
2033
2049
{
2034
2050
std::vector<std::vector<std::string> >::const_iterator itt;
@@ -2065,7 +2081,7 @@ namespace http {
2065
2081
{
2066
2082
root[" result" ][ii][" LastReceived" ] = " -" ;
2067
2083
}
2068
- result2 = m_sql.safe_query (" SELECT COUNT(*) FROM MySensorsChilds WHERE( NodeID == %d)" , NodeID);
2084
+ result2 = m_sql.safe_query (" SELECT COUNT(*) FROM MySensorsChilds WHERE (HardwareID=%d) AND ( NodeID == %d)" , iHardwareID , NodeID);
2069
2085
int totChilds = 0 ;
2070
2086
if (!result2.empty ())
2071
2087
{
@@ -2102,7 +2118,7 @@ namespace http {
2102
2118
MySensorsBase::_tMySensorNode* pNode = pMySensorsHardware->FindNode (NodeID);
2103
2119
std::vector<std::vector<std::string> >::const_iterator itt2;
2104
2120
std::vector<std::vector<std::string> > result;
2105
- result = m_sql.safe_query (" SELECT ChildID, [Type], Name, UseAck FROM MySensorsChilds WHERE( NodeID == %d) ORDER BY ChildID ASC" , NodeID);
2121
+ result = m_sql.safe_query (" SELECT ChildID, [Type], Name, UseAck FROM MySensorsChilds WHERE (HardwareID=%d) AND ( NodeID == %d) ORDER BY ChildID ASC" , iHardwareID , NodeID);
2106
2122
int ii = 0 ;
2107
2123
for (itt2 = result.begin (); itt2 != result.end (); ++itt2)
2108
2124
{
0 commit comments