@@ -152,7 +152,8 @@ int GoodweAPI::getSunRiseSunSetMinutes(const bool bGetSunRise)
152
152
return 0 ;
153
153
}
154
154
155
- int GoodweAPI::hash (std::string str)
155
+
156
+ uint32_t GoodweAPI::hash (std::string str)
156
157
{
157
158
/*
158
159
* We need a way to generate the NoddeId from the stationID
@@ -165,14 +166,15 @@ int GoodweAPI::hash(std::string str)
165
166
*/
166
167
167
168
long hash = 5381 ;
168
- int i = 0 ;
169
+ size_t i = 0 ;
169
170
int c;
170
171
171
- while (c = str[ i++] )
172
+ for (i = 0 ; i < str. size (); i++)
172
173
{
174
+ c = str[i++];
173
175
hash = ((hash << 5 ) + hash) + c;
174
176
}
175
- return (int )hash;
177
+ return (uint32_t )hash;
176
178
}
177
179
178
180
float GoodweAPI::getPowerWatt (const std::string str)
@@ -347,7 +349,7 @@ void GoodweAPI::ParseStation(const std::string sStationId, const std::string sSt
347
349
348
350
// Calcullate NodeID from stationId
349
351
350
- int NodeID = hash (sStationId );
352
+ uint32_t NodeID = hash (sStationId );
351
353
352
354
// Use the station name from the Goodwe website as defaultname
353
355
@@ -439,12 +441,13 @@ void GoodweAPI::ParseDevice(Json::Value device, std::string sStationId, std::str
439
441
440
442
// Create NodeID and ChildID from station id and device serial
441
443
442
- int NodeID = hash (sStationId );
443
- int ChildID = hash (sDeviceSerial );
444
+ uint32_t NodeID = hash (sStationId );
445
+ uint32_t ChildID = hash (sDeviceSerial );
444
446
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
+ }
448
451
449
452
SendKwhMeter (NodeID, ChildID, 255 , currentPowerW, totalEnergyKWh, sStationName + " " + sDeviceSerial + " Return" );
450
453
SendTextSensor (NodeID, ChildID + 1 , 255 , sStatus , sStationName + " " + sDeviceSerial + " status" );
0 commit comments