Skip to content

Commit 6b97265

Browse files
committed
Fixed typo in HardwareBase
1 parent 3f5d5ff commit 6b97265

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

hardware/DomoticzHardware.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -547,18 +547,21 @@ void CDomoticzHardwareBase::SendKwhMeterOldWay(const int NodeID, const int Child
547547

548548
void CDomoticzHardwareBase::SendKwhMeter(const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname)
549549
{
550-
int Idx = (NodeID * 256) + ChildID;
550+
int dID = (NodeID << 8) | ChildID;
551+
char szTmp[30];
552+
sprintf(szTmp, "%08X", dID);
553+
551554
bool bDeviceExits = true;
552555
std::vector<std::vector<std::string> > result;
553-
result = m_sql.safe_query("SELECT Name FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)",
554-
m_HwdID, int(Idx), int(pTypeGeneral), int(sTypeKwh));
556+
result = m_sql.safe_query("SELECT Name FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Type==%d) AND (Subtype==%d)",
557+
m_HwdID, szTmp, int(pTypeGeneral), int(sTypeKwh));
555558
if (result.size() < 1)
556559
{
557560
bDeviceExits = false;
558561
}
559562

560563
_tGeneralDevice gdevice;
561-
gdevice.intval1 = Idx;
564+
gdevice.intval1 = dID;
562565
gdevice.subtype = sTypeKwh;
563566
gdevice.floatval1 = (float)musage;
564567
gdevice.floatval2 = (float)(mtotal*1000.0);
@@ -567,17 +570,20 @@ void CDomoticzHardwareBase::SendKwhMeter(const int NodeID, const int ChildID, co
567570
if (!bDeviceExits)
568571
{
569572
//Assign default name for device
570-
m_sql.safe_query("UPDATE DeviceStatus SET Name='%q' WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)",
571-
defaultname.c_str(), m_HwdID, int(Idx), int(pTypeGeneral), int(sTypeKwh));
573+
m_sql.safe_query("UPDATE DeviceStatus SET Name='%q' WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Type==%d) AND (Subtype==%d)",
574+
defaultname.c_str(), m_HwdID, szTmp, int(pTypeGeneral), int(sTypeKwh));
572575
}
573576
}
574577

575578
double CDomoticzHardwareBase::GetKwhMeter(const int NodeID, const int ChildID, bool &bExists)
576579
{
577-
int Idx = (NodeID * 256) + ChildID;
580+
int dID = (NodeID << 8) | ChildID;
581+
char szTmp[30];
582+
sprintf(szTmp, "%08X", dID);
583+
578584
std::vector<std::vector<std::string> > result;
579-
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d) AND (Type==%d) AND (Subtype==%d)",
580-
m_HwdID, int(Idx), int(pTypeGeneral), int(sTypeKwh));
585+
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Type==%d) AND (Subtype==%d)",
586+
m_HwdID, szTmp, int(pTypeGeneral), int(sTypeKwh));
581587
if (result.size() < 1)
582588
{
583589
bExists = false;

0 commit comments

Comments
 (0)