@@ -348,7 +348,7 @@ void CNest::GetMeterDetails()
348
348
{
349
349
std::string sResult ;
350
350
#ifdef DEBUG_NextThermostatR
351
- sResult = ReadFile (" E:\\ nest .json" );
351
+ sResult = ReadFile (" E:\\ Nest_DoubleTherm .json" );
352
352
#else
353
353
if (m_UserName.size ()==0 )
354
354
return ;
@@ -528,29 +528,64 @@ void CNest::GetMeterDetails()
528
528
return ;
529
529
}
530
530
531
- Json::Value::Members members;
532
-
533
531
size_t iThermostat = 0 ;
534
- for (Json::Value::iterator itShared = root[" shared " ].begin (); itShared != root[" shared " ].end (); ++itShared )
532
+ for (Json::Value::iterator ittStructure = root[" structure " ].begin (); ittStructure != root[" structure " ].end (); ++ittStructure )
535
533
{
536
- Json::Value nshared = *itShared;
537
- if (nshared.isObject ())
534
+ Json::Value nstructure = *ittStructure;
535
+ if (!nstructure.isObject ())
536
+ continue ;
537
+ std::string StructureID = ittStructure.key ().asString ();
538
+ std::string StructureName = nstructure[" name" ].asString ();
539
+
540
+ for (Json::Value::iterator ittDevice = nstructure[" devices" ].begin (); ittDevice != nstructure[" devices" ].end (); ++ittDevice)
538
541
{
539
- std::string Serial = itShared.key ().asString ();
540
- members = root[" structure" ].getMemberNames ();
541
- if (iThermostat>=members.size ())
542
+ std::string devID = (*ittDevice).asString ();
543
+ if (devID.find (" device." )==std::string::npos)
544
+ continue ;
545
+ std::string Serial = devID.substr (7 );
546
+ if (root[" device" ].empty ())
542
547
continue ;
543
- std::string StructureID = *(members.begin ()+iThermostat);
544
- if (root[" structure" ][StructureID].empty ())
548
+ if (root[" device" ][Serial].empty ())
549
+ continue ; // not found !?
550
+ if (root[" shared" ][Serial].empty ())
551
+ continue ; // Nothing shared?
552
+
553
+
554
+ Json::Value ndevice = root[" device" ][Serial];
555
+ if (!ndevice.isObject ())
545
556
continue ;
546
- std::string Name = root[" structure" ][StructureID][" name" ].asString ();
557
+
558
+ std::string Name = " Thermostat" ;
559
+ if (!ndevice[" where_id" ].empty ())
560
+ {
561
+ // Lookup our 'where' (for the Name of the thermostat)
562
+ std::string where_id = ndevice[" where_id" ].asString ();
563
+
564
+ if (!root[" where" ].empty ())
565
+ {
566
+ if (!root[" where" ][StructureID].empty ())
567
+ {
568
+ for (Json::Value::iterator ittWheres = root[" where" ][StructureID][" wheres" ].begin (); ittWheres != root[" where" ][StructureID][" wheres" ].end (); ++ittWheres)
569
+ {
570
+ Json::Value nwheres = *ittWheres;
571
+ if (nwheres[" where_id" ] == where_id)
572
+ {
573
+ Name = StructureName + " " + nwheres[" name" ].asString ();
574
+ break ;
575
+ }
576
+ }
577
+ }
578
+ }
579
+ }
547
580
548
581
_tNestThemostat ntherm;
549
582
ntherm.Serial = Serial;
550
583
ntherm.StructureID = StructureID;
551
584
ntherm.Name = Name;
552
585
m_thermostats[iThermostat] = ntherm;
553
586
587
+ Json::Value nshared = root[" shared" ][Serial];
588
+
554
589
// Setpoint
555
590
if (!nshared[" target_temperature" ].empty ())
556
591
{
@@ -569,20 +604,20 @@ void CNest::GetMeterDetails()
569
604
if (nshared[" can_heat" ].asBool () && !nshared[" hvac_heater_state" ].empty ())
570
605
{
571
606
bool bIsHeating = nshared[" hvac_heater_state" ].asBool ();
572
- UpdateSwitch (113 ,bIsHeating," HeatingOn" );
607
+ UpdateSwitch (113 , bIsHeating, " HeatingOn" );
573
608
}
574
609
575
610
// Check if thermostat is currently Cooling
576
611
if (nshared[" can_cool" ].asBool () && !nshared[" hvac_ac_state" ].empty ())
577
612
{
578
613
bool bIsCooling = nshared[" hvac_ac_state" ].asBool ();
579
- UpdateSwitch (114 ,bIsCooling," CoolingOn" );
614
+ UpdateSwitch (114 , bIsCooling, " CoolingOn" );
580
615
}
581
616
582
617
// Away
583
- if (!root[ " structure " ][StructureID] [" away" ].empty ())
618
+ if (!nstructure [" away" ].empty ())
584
619
{
585
- bool bIsAway = root[ " structure " ][StructureID] [" away" ].asBool ();
620
+ bool bIsAway = nstructure [" away" ].asBool ();
586
621
SendSwitch ((iThermostat * 3 ) + 3 , 1 , 255 , bIsAway, 0 , Name + " Away" );
587
622
}
588
623
iThermostat++;
0 commit comments