Skip to content

Commit ffee110

Browse files
committed
added global function to detect if sensor is a light/switch
1 parent 191d474 commit ffee110

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

hardware/MQTT.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,7 @@ void MQTT::SendDeviceInfo(const int m_HwdID, const unsigned long long DeviceRowI
499499
root["dtype"] = RFX_Type_Desc(dType,1);
500500
root["stype"] = RFX_Type_SubType_Desc(dType, dSubType);
501501

502-
// only devices appearing on the 'lights' page have a switch type
503-
// where can we find if a device is a 'light' ?
504-
if (dType == pTypeLighting2) {
502+
if (IsLightOrSwitch(dType, dSubType) == true) {
505503
root["switchType"] = Switch_Type_Desc(switchType);
506504
}
507505

main/Helper.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include "../msbuild/WindowsHelper.h"
1515
#endif
1616

17+
#include "RFXtrx.h"
18+
#include "../hardware/hardwaretypes.h"
19+
1720
void StringSplit(std::string str, const std::string &delim, std::vector<std::string> &results)
1821
{
1922
results.clear();
@@ -541,3 +544,33 @@ void padLeft(std::string &str, const size_t num, const char paddingChar)
541544
if (num > str.size())
542545
str.insert(0, num - str.size(), paddingChar);
543546
}
547+
548+
bool IsLightOrSwitch(const int devType, const int subType)
549+
{
550+
bool bIsLightSwitch = false;
551+
switch (devType)
552+
{
553+
case pTypeLighting1:
554+
case pTypeLighting2:
555+
case pTypeLighting3:
556+
case pTypeLighting4:
557+
case pTypeLighting5:
558+
case pTypeLighting6:
559+
case pTypeLimitlessLights:
560+
case pTypeSecurity1:
561+
case pTypeSecurity2:
562+
case pTypeCurtain:
563+
case pTypeBlinds:
564+
case pTypeRFY:
565+
case pTypeThermostat2:
566+
case pTypeThermostat3:
567+
case pTypeRemote:
568+
case pTypeGeneralSwitch:
569+
bIsLightSwitch = true;
570+
break;
571+
case pTypeRadiator1:
572+
bIsLightSwitch = (subType == sTypeSmartwaresSwitchRadiator);
573+
break;
574+
}
575+
return bIsLightSwitch;
576+
}

main/Helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ std::string GenerateMD5Hash(const std::string &InputString, const std::string &S
3434
void hue2rgb(const float hue, int &outR, int &outG, int &outB, const double maxValue = 100.0);
3535
bool is_number(const std::string& s);
3636
void padLeft(std::string &str, const size_t num, const char paddingChar = '0');
37+
38+
bool IsLightOrSwitch(const int devType, const int subType);

main/SQLHelper.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,33 +2324,10 @@ unsigned long long CSQLHelper::UpdateValue(const int HardwareID, const char* ID,
23242324
if (devRowID == -1)
23252325
return -1;
23262326

2327-
bool bIsLightSwitch=false;
2328-
switch (devType)
2327+
if (!IsLightOrSwitch(devType, subType))
23292328
{
2330-
case pTypeLighting1:
2331-
case pTypeLighting2:
2332-
case pTypeLighting3:
2333-
case pTypeLighting4:
2334-
case pTypeLighting5:
2335-
case pTypeLighting6:
2336-
case pTypeLimitlessLights:
2337-
case pTypeSecurity1:
2338-
case pTypeSecurity2:
2339-
case pTypeCurtain:
2340-
case pTypeBlinds:
2341-
case pTypeRFY:
2342-
case pTypeThermostat2:
2343-
case pTypeThermostat3:
2344-
case pTypeRemote:
2345-
case pTypeGeneralSwitch:
2346-
bIsLightSwitch = true;
2347-
break;
2348-
case pTypeRadiator1:
2349-
bIsLightSwitch = (subType == sTypeSmartwaresSwitchRadiator);
2350-
break;
2351-
}
2352-
if (!bIsLightSwitch)
23532329
return devRowID;
2330+
}
23542331

23552332
//Get the ID of this device
23562333
std::vector<std::vector<std::string> > result,result2;

0 commit comments

Comments
 (0)