Skip to content

Commit dff3f86

Browse files
authored
Merge pull request #1833 from trandbert37/add-rssi-netatmo-support
Add rssi support for Netatmo devices
2 parents 4cd3d58 + f304323 commit dff3f86

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

hardware/Netatmo.cpp

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ int CNetatmo::GetBatteryLevel(const std::string &ModuleType, const int battery_p
386386
return batValue;
387387
}
388388

389-
bool CNetatmo::ParseDashboard(const Json::Value &root, const int DevIdx, const int ID, const std::string &name, const std::string &ModuleType, const int battery_percent)
389+
bool CNetatmo::ParseDashboard(const Json::Value &root, const int DevIdx, const int ID, const std::string &name, const std::string &ModuleType, const int battery_percent, const int rssiLevel)
390390
{
391391
bool bHaveTemp = false;
392392
bool bHaveHum = false;
@@ -508,15 +508,15 @@ bool CNetatmo::ParseDashboard(const Json::Value &root, const int DevIdx, const i
508508
else if (pressure >= 1029)
509509
nforecast = wsbaroforcast_sunny;
510510
}
511-
SendTempHumBaroSensorFloat(ID, batValue, temp, hum, baro, nforecast, name);
511+
SendTempHumBaroSensorFloat(ID, batValue, temp, hum, baro, nforecast, name, rssiLevel);
512512
}
513513
else if (bHaveTemp && bHaveHum)
514514
{
515-
SendTempHumSensor(ID, batValue, temp, hum, name);
515+
SendTempHumSensor(ID, batValue, temp, hum, name, rssiLevel);
516516
}
517517
else if (bHaveTemp)
518518
{
519-
SendTempSensor(ID, batValue, temp, name);
519+
SendTempSensor(ID, batValue, temp, name, rssiLevel);
520520
}
521521

522522
if (bHaveSetpoint)
@@ -551,7 +551,7 @@ bool CNetatmo::ParseDashboard(const Json::Value &root, const int DevIdx, const i
551551
m_RainOffset[ID] += m_OldRainCounter[ID];
552552
}
553553
m_OldRainCounter[ID] = rain;
554-
SendRainSensor(ID, batValue, m_RainOffset[ID] + m_OldRainCounter[ID], name);
554+
SendRainSensor(ID, batValue, m_RainOffset[ID] + m_OldRainCounter[ID], name, rssiLevel);
555555
}
556556

557557
if (bHaveCO2)
@@ -566,7 +566,7 @@ bool CNetatmo::ParseDashboard(const Json::Value &root, const int DevIdx, const i
566566

567567
if (bHaveWind)
568568
{
569-
SendWind(ID, batValue, wind_angle, wind_strength, wind_gust, 0, 0, false, name);
569+
SendWind(ID, batValue, wind_angle, wind_strength, wind_gust, 0, 0, false, name, rssiLevel);
570570
}
571571
return true;
572572
}
@@ -809,18 +809,27 @@ bool CNetatmo::ParseNetatmoGetResponse(const std::string &sResult, const bool bI
809809
if (mname.empty())
810810
mname = nDevice.ModuleName;
811811
int mbattery_percent = 0;
812-
if (module["battery_percent"].empty() == false)
812+
if (!module["battery_percent"].empty())
813813
{
814814
mbattery_percent = module["battery_percent"].asInt();
815815
}
816+
int mrf_status = 0;
817+
if (!module["rf_status"].empty())
818+
{
819+
// 90=low, 60=highest
820+
mrf_status = ( 90 - module["rf_status"].asInt())/3;
821+
if (mrf_status > 10){
822+
mrf_status = 10;
823+
}
824+
}
816825
int crcId = Crc32(0, (const unsigned char *)mid.c_str(), mid.length());
817826
if (!module["dashboard_data"].empty())
818827
{
819-
ParseDashboard(module["dashboard_data"], iDevIndex, crcId, mname, mtype, mbattery_percent);
828+
ParseDashboard(module["dashboard_data"], iDevIndex, crcId, mname, mtype, mbattery_percent, mrf_status);
820829
}
821830
else if (!module["measured"].empty())
822831
{
823-
ParseDashboard(module["measured"], iDevIndex, crcId, mname, mtype, mbattery_percent);
832+
ParseDashboard(module["measured"], iDevIndex, crcId, mname, mtype, mbattery_percent, mrf_status);
824833
if (mtype == "NATherm1")
825834
{
826835
m_thermostatDeviceID[iDevIndex] = nDevice.ID;
@@ -838,7 +847,7 @@ bool CNetatmo::ParseNetatmoGetResponse(const std::string &sResult, const bool bI
838847
//Check if setpoint was just set, and if yes, overrule the previous setpoint
839848
if (!module["setpoint"]["setpoint_temp"].empty())
840849
{
841-
ParseDashboard(module["setpoint"], iDevIndex, crcId, mname, mtype, mbattery_percent);
850+
ParseDashboard(module["setpoint"], iDevIndex, crcId, mname, mtype, mbattery_percent, mrf_status);
842851
}
843852
}
844853
}
@@ -852,14 +861,23 @@ bool CNetatmo::ParseNetatmoGetResponse(const std::string &sResult, const bool bI
852861
_netatmo_devices.push_back(nDevice);
853862

854863
int battery_percent = 0;
855-
if (device["battery_percent"].empty() == false)
864+
if (!device["battery_percent"].empty())
856865
{
857866
battery_percent = device["battery_percent"].asInt();
858867
}
868+
int wifi_status = 0;
869+
if (!device["wifi_status"].empty())
870+
{
871+
// 86=bad, 56=good
872+
wifi_status = ( 86 - device["wifi_status"].asInt())/3;
873+
if (wifi_status > 10){
874+
wifi_status = 10;
875+
}
876+
}
859877
int crcId = Crc32(0, (const unsigned char *)id.c_str(), id.length());
860878
if (!device["dashboard_data"].empty())
861879
{
862-
ParseDashboard(device["dashboard_data"], iDevIndex, crcId, name, type, battery_percent);
880+
ParseDashboard(device["dashboard_data"], iDevIndex, crcId, name, type, battery_percent, wifi_status);
863881
}
864882
}
865883
iDevIndex++;
@@ -931,6 +949,15 @@ bool CNetatmo::ParseNetatmoGetResponse(const std::string &sResult, const bool bI
931949
{
932950
battery_percent = module["battery_percent"].asInt();
933951
}
952+
int rf_status = 0;
953+
if (!module["rf_status"].empty())
954+
{
955+
// 90=low, 60=highest
956+
rf_status = ( 90 - module["rf_status"].asInt())/3;
957+
if (rf_status > 10){
958+
rf_status = 10;
959+
}
960+
}
934961
stdreplace(name, "'", " ");
935962

936963
//std::set<std::string> dataTypes;
@@ -941,7 +968,7 @@ bool CNetatmo::ParseNetatmoGetResponse(const std::string &sResult, const bool bI
941968
int crcId = Crc32(0, (const unsigned char *)id.c_str(), id.length());
942969
if (!module["dashboard_data"].empty())
943970
{
944-
ParseDashboard(module["dashboard_data"], iDevIndex, crcId, name, type, battery_percent);
971+
ParseDashboard(module["dashboard_data"], iDevIndex, crcId, name, type, battery_percent, rf_status);
945972
}
946973
}
947974
return (!_netatmo_devices.empty());

hardware/Netatmo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class CNetatmo : public CDomoticzHardwareBase
5858
bool m_bForceLogin;
5959
bool m_bIsHomeCoach;
6060

61-
int GetBatteryLevel(const std::string &ModuleType, const int battery_vp);
62-
bool ParseDashboard(const Json::Value &root, const int DevIdx, const int ID, const std::string &name, const std::string &ModuleType, const int battery_vp);
61+
int GetBatteryLevel(const std::string &ModuleType, const int battery_percent);
62+
bool ParseDashboard(const Json::Value &root, const int DevIdx, const int ID, const std::string &name, const std::string &ModuleType, const int battery_percent, const int rf_status);
6363
};
6464

0 commit comments

Comments
 (0)