Skip to content

Commit ee54e30

Browse files
committed
JSON udevice, native support for General/Sound, Added notification for Air Quality
1 parent a35958c commit ee54e30

File tree

3 files changed

+61
-30
lines changed

3 files changed

+61
-30
lines changed

hardware/MySensorsBase.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,9 +1676,8 @@ void MySensorsBase::ParseLine()
16761676
m_AckNodeID = m_AckChildID = -1;
16771677
m_AckSetType = V_UNKNOWN;
16781678
m_bAckReceived = true;
1679-
//No need to process ack commands
1680-
return;
1681-
1679+
//No need to process ack commands
1680+
return;
16821681
}
16831682

16841683
bool bHaveValue = false;

hardware/PhilipsHue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ bool CPhilipsHue::SwitchLight(const int nodeID, const std::string &LCmd, const i
282282
std::string sURL = sstr2.str();
283283
if (!HTTPClient::PUT(sURL, sPostData.str(), ExtraHeaders, sResult))
284284
{
285-
_log.Log(LOG_ERROR, "Philips Hue: Error connecting to Hue bridge, (Check IPAddress/Username)");
285+
_log.Log(LOG_ERROR, "Philips Hue: Error connecting to Hue bridge (Switch Light/Scene), (Check IPAddress/Username)");
286286
return false;
287287
}
288288

@@ -292,7 +292,7 @@ bool CPhilipsHue::SwitchLight(const int nodeID, const std::string &LCmd, const i
292292
bool ret = jReader.parse(sResult, root);
293293
if (!ret)
294294
{
295-
_log.Log(LOG_ERROR, "Philips Hue: Invalid data received, or invalid IPAddress/Username!");
295+
_log.Log(LOG_ERROR, "Philips Hue: Invalid data received (Switch Light/Scene), or invalid IPAddress/Username!");
296296
return false;
297297
}
298298

main/mainworker.cpp

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11983,6 +11983,12 @@ void MainWorker::HeartbeatCheck()
1198311983
bool MainWorker::UpdateDevice(const int HardwareID, const std::string &DeviceID, const int unit, const int devType, const int subType, const int nValue, const std::string &sValue, const int signallevel, const int batterylevel, const bool parseTrigger)
1198411984
{
1198511985
CDomoticzHardwareBase *pHardware = GetHardware(HardwareID);
11986+
11987+
unsigned long ID = 0;
11988+
std::stringstream s_strid;
11989+
s_strid << std::hex << DeviceID;
11990+
s_strid >> ID;
11991+
1198611992
if (pHardware)
1198711993
{
1198811994
if (devType == pTypeLighting2)
@@ -12011,36 +12017,62 @@ bool MainWorker::UpdateDevice(const int HardwareID, const std::string &DeviceID,
1201112017
lcmd.LIGHTING2.level = (unsigned char)atoi(sValue.c_str());
1201212018
lcmd.LIGHTING2.filler = 0;
1201312019
lcmd.LIGHTING2.rssi = signallevel;
12014-
DecodeRXMessage(pHardware, (const unsigned char *)&lcmd.LIGHTING2, NULL, -1);
12020+
DecodeRXMessage(pHardware, (const unsigned char *)&lcmd.LIGHTING2, NULL, batterylevel);
1201512021
return true;
1201612022
}
12017-
else if ((devType == pTypeGeneral) && (subType == sTypePercentage))
12023+
else if (devType == pTypeGeneral)
1201812024
{
12019-
unsigned long ID;
12020-
std::stringstream s_strid;
12021-
s_strid << std::hex << DeviceID;
12022-
s_strid >> ID;
12023-
_tGeneralDevice gDevice;
12024-
gDevice.subtype = sTypePercentage;
12025-
gDevice.id = unit;
12026-
gDevice.floatval1 = (float)atof(sValue.c_str());
12027-
gDevice.intval1 = static_cast<int>(ID);
12028-
DecodeRXMessage(pHardware, (const unsigned char *)&gDevice, NULL, -1);
12029-
return true;
12025+
if (subType == sTypePercentage)
12026+
{
12027+
_tGeneralDevice gDevice;
12028+
gDevice.subtype = sTypePercentage;
12029+
gDevice.id = unit;
12030+
gDevice.floatval1 = (float)atof(sValue.c_str());
12031+
gDevice.intval1 = static_cast<int>(ID);
12032+
DecodeRXMessage(pHardware, (const unsigned char *)&gDevice, NULL, batterylevel);
12033+
return true;
12034+
}
12035+
else if (subType == sTypeWaterflow)
12036+
{
12037+
unsigned long ID;
12038+
std::stringstream s_strid;
12039+
s_strid << std::hex << DeviceID;
12040+
s_strid >> ID;
12041+
_tGeneralDevice gDevice;
12042+
gDevice.subtype = sTypeWaterflow;
12043+
gDevice.id = unit;
12044+
gDevice.floatval1 = (float)atof(sValue.c_str());
12045+
gDevice.intval1 = static_cast<int>(ID);
12046+
DecodeRXMessage(pHardware, (const unsigned char *)&gDevice, NULL, batterylevel);
12047+
return true;
12048+
}
12049+
else if (subType == sTypeSoundLevel)
12050+
{
12051+
_tGeneralDevice gDevice;
12052+
gDevice.subtype = sTypeSoundLevel;
12053+
gDevice.id = unit;
12054+
gDevice.intval1 = static_cast<int>(ID);
12055+
gDevice.intval2 = atoi(sValue.c_str());
12056+
DecodeRXMessage(pHardware, (const unsigned char *)&gDevice, NULL, batterylevel);
12057+
return true;
12058+
}
1203012059
}
12031-
else if ((devType == pTypeGeneral) && (subType == sTypeWaterflow))
12060+
else if ((devType == pTypeAirQuality) && (subType == sTypeVoltcraft))
1203212061
{
12033-
unsigned long ID;
12034-
std::stringstream s_strid;
12035-
s_strid << std::hex << DeviceID;
12036-
s_strid >> ID;
12037-
_tGeneralDevice gDevice;
12038-
gDevice.subtype = sTypeWaterflow;
12039-
gDevice.id = unit;
12040-
gDevice.floatval1 = (float)atof(sValue.c_str());
12041-
gDevice.intval1 = static_cast<int>(ID);
12042-
DecodeRXMessage(pHardware, (const unsigned char *)&gDevice, NULL, -1);
12043-
return true;
12062+
std::vector<std::vector<std::string> > result;
12063+
result = m_sql.safe_query(
12064+
"SELECT ID,Name FROM DeviceStatus WHERE (HardwareID=%d AND DeviceID='%q' AND Unit=%d AND Type=%d AND SubType=%d)",
12065+
HardwareID, DeviceID.c_str(), unit, devType, subType);
12066+
if (!result.empty())
12067+
{
12068+
std::vector<std::string> sd = result[0];
12069+
unsigned long long dID = 0;
12070+
std::stringstream s_strid;
12071+
s_strid << sd[0];
12072+
s_strid >> dID;
12073+
12074+
m_notifications.CheckAndHandleNotification(dID, sd[1], devType, subType, NTYPE_USAGE, (const float)nValue);
12075+
}
1204412076
}
1204512077
}
1204612078

0 commit comments

Comments
 (0)