Skip to content

Commit 2f1366c

Browse files
committed
- Implemented: MySensors, Heartbeat LastUpdate for Blinds/RGB/W
1 parent 25ad771 commit 2f1366c

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

hardware/MySensorsBase.cpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,19 +457,18 @@ void MySensorsBase::UpdateNodeHeartbeat(const int nodeID)
457457
case V_SCENE_OFF:
458458
if (itt->GetValue(vType, intValue))
459459
UpdateSwitchLastUpdate(nodeID, itt->childID + intValue);
460-
// Dimmer value. 0 - 100 %
461-
break;
462-
/*
463-
case V_RGB:
464-
case V_RGBW:
465-
UpdateRGBWSwitchhLastUpdate(pChild->nodeID, pChild->childID);
466460
break;
467461
case V_UP:
468462
case V_DOWN:
469463
case V_STOP:
470-
UpdateBlindSensorhLastUpdate(pChild->nodeID, pChild->childID);
464+
if (itt->GetValue(vType, intValue))
465+
UpdateBlindSensorLastUpdate(nodeID, itt->childID);
466+
break;
467+
case V_RGB:
468+
case V_RGBW:
469+
if (itt->GetValue(vType, intValue))
470+
UpdateRGBWSwitchLastUpdate(nodeID, itt->childID);
471471
break;
472-
*/
473472
}
474473
}
475474
}
@@ -1030,6 +1029,44 @@ void MySensorsBase::UpdateSwitchLastUpdate(const unsigned char Idx, const int Su
10301029
m_sql.safe_query("UPDATE DeviceStatus SET LastUpdate='%q' WHERE (ID = '%q')", szLastUpdate, result[0][0].c_str());
10311030
}
10321031

1032+
void MySensorsBase::UpdateBlindSensorLastUpdate(const int NodeID, const int ChildID)
1033+
{
1034+
char szIdx[10];
1035+
sprintf(szIdx, "%02X%02X%02X", 0, 0, NodeID);
1036+
std::vector<std::vector<std::string> > result;
1037+
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit==%d)", m_HwdID, szIdx, ChildID);
1038+
if (result.size() < 1)
1039+
return;
1040+
time_t now = time(0);
1041+
struct tm ltime;
1042+
localtime_r(&now, &ltime);
1043+
1044+
char szLastUpdate[40];
1045+
sprintf(szLastUpdate, "%04d-%02d-%02d %02d:%02d:%02d", ltime.tm_year + 1900, ltime.tm_mon + 1, ltime.tm_mday, ltime.tm_hour, ltime.tm_min, ltime.tm_sec);
1046+
m_sql.safe_query("UPDATE DeviceStatus SET LastUpdate='%q' WHERE (ID = '%q')", szLastUpdate, result[0][0].c_str());
1047+
}
1048+
1049+
void MySensorsBase::UpdateRGBWSwitchLastUpdate(const int NodeID, const int ChildID)
1050+
{
1051+
char szIdx[10];
1052+
if (NodeID == 1)
1053+
sprintf(szIdx, "%d", 1);
1054+
else
1055+
sprintf(szIdx, "%08x", (unsigned int)NodeID);
1056+
1057+
std::vector<std::vector<std::string> > result;
1058+
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit==%d)", m_HwdID, szIdx, ChildID);
1059+
if (result.size() < 1)
1060+
return;
1061+
time_t now = time(0);
1062+
struct tm ltime;
1063+
localtime_r(&now, &ltime);
1064+
1065+
char szLastUpdate[40];
1066+
sprintf(szLastUpdate, "%04d-%02d-%02d %02d:%02d:%02d", ltime.tm_year + 1900, ltime.tm_mon + 1, ltime.tm_mday, ltime.tm_hour, ltime.tm_min, ltime.tm_sec);
1067+
m_sql.safe_query("UPDATE DeviceStatus SET LastUpdate='%q' WHERE (ID = '%q')", szLastUpdate, result[0][0].c_str());
1068+
}
1069+
10331070
void MySensorsBase::UpdateSwitch(const unsigned char Idx, const int SubUnit, const bool bOn, const double Level, const std::string &defaultname, const int BatLevel)
10341071
{
10351072
bool bDeviceExits = true;

hardware/MySensorsBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ class MySensorsBase : public CDomoticzHardwareBase
374374

375375

376376
void UpdateSwitch(const unsigned char Idx, const int SubUnit, const bool bOn, const double Level, const std::string &defaultname, const int BatLevel);
377+
377378
void UpdateSwitchLastUpdate(const unsigned char Idx, const int SubUnit);
379+
void UpdateBlindSensorLastUpdate(const int NodeID, const int ChildID);
380+
void UpdateRGBWSwitchLastUpdate(const int NodeID, const int ChildID);
378381

379382
bool GetSwitchValue(const unsigned char Idx, const int SubUnit, const int sub_type, std::string &sSwitchValue);
380383

0 commit comments

Comments
 (0)