Skip to content

Commit 60c0655

Browse files
authored
Merge pull request #815 from llagendijk/goodwe-warning-fixes
Goodwe warning fixes
2 parents d6a0d3c + 8bb7e9d commit 60c0655

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

hardware/GoodweAPI.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ int GoodweAPI::getSunRiseSunSetMinutes(const bool bGetSunRise)
152152
return 0;
153153
}
154154

155-
int GoodweAPI::hash(std::string str)
155+
156+
uint32_t GoodweAPI::hash(std::string str)
156157
{
157158
/*
158159
* We need a way to generate the NoddeId from the stationID
@@ -165,14 +166,15 @@ int GoodweAPI::hash(std::string str)
165166
*/
166167

167168
long hash = 5381;
168-
int i = 0;
169+
size_t i = 0;
169170
int c;
170171

171-
while(c = str[i++])
172+
for (i = 0; i < str.size(); i++)
172173
{
174+
c = str[i++];
173175
hash = ((hash << 5) + hash) + c;
174176
}
175-
return (int)hash;
177+
return (uint32_t)hash;
176178
}
177179

178180
float GoodweAPI::getPowerWatt(const std::string str)
@@ -347,7 +349,7 @@ void GoodweAPI::ParseStation(const std::string sStationId, const std::string sSt
347349

348350
// Calcullate NodeID from stationId
349351

350-
int NodeID = hash(sStationId);
352+
uint32_t NodeID = hash(sStationId);
351353

352354
// Use the station name from the Goodwe website as defaultname
353355

@@ -439,12 +441,13 @@ void GoodweAPI::ParseDevice(Json::Value device, std::string sStationId, std::str
439441

440442
// Create NodeID and ChildID from station id and device serial
441443

442-
int NodeID = hash(sStationId);
443-
int ChildID = hash(sDeviceSerial);
444+
uint32_t NodeID = hash(sStationId);
445+
uint32_t ChildID = hash(sDeviceSerial);
444446

445-
// reserve childid below 10 for the station
446-
if (ChildID < 10)
447-
ChildID =+ 10;
447+
// reserve childIDs 0 - 10 for the station
448+
if (ChildID <= 10) {
449+
ChildID = ChildID + 10;
450+
}
448451

449452
SendKwhMeter(NodeID, ChildID, 255, currentPowerW, totalEnergyKWh, sStationName + " " + sDeviceSerial + " Return");
450453
SendTextSensor(NodeID, ChildID + 1 , 255, sStatus, sStationName + " " + sDeviceSerial + " status");

hardware/GoodweAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GoodweAPI : public CDomoticzHardwareBase
1818
void Init();
1919
bool StartHardware();
2020
bool StopHardware();
21-
int hash(const std::string str);
21+
uint32_t hash(const std::string str);
2222
int getSunRiseSunSetMinutes(const bool bGetSunRise);
2323
float getPowerWatt(const std::string str);
2424
float getEnergyWh(const std::string str);

0 commit comments

Comments
 (0)