@@ -51,6 +51,10 @@ class EnvoyReader: # pylint: disable=too-many-instance-attributes
51
51
# P for production data only (ie. Envoy model C, s/w >= R3.9)
52
52
# PC for production and consumption data (ie. Envoy model S)
53
53
54
+ message_battery_not_available = (
55
+ "Battery storage data not available for your Envoy device."
56
+ )
57
+
54
58
message_consumption_not_available = (
55
59
"Consumption data not available for your Envoy device."
56
60
)
@@ -443,6 +447,27 @@ async def inverters_production(self):
443
447
444
448
return response_dict
445
449
450
+ async def battery_storage (self ):
451
+ """Return battery data from Envoys that support and have batteries installed"""
452
+ if (
453
+ self .endpoint_type == ENVOY_MODEL_LEGACY
454
+ or self .endpoint_type == ENVOY_MODEL_C
455
+ ):
456
+ return self .message_battery_not_available
457
+
458
+ try :
459
+ raw_json = self .endpoint_production_json_results .json ()
460
+ except (JSONDecodeError ):
461
+ return None
462
+
463
+ """For Envoys that support batteries but do not have them installed the"""
464
+ """percentFull will not be available in the JSON results. The API will"""
465
+ """only return battery data if batteries are installed."""
466
+ if "percentFull" not in raw_json ["storage" ][0 ].keys ():
467
+ return self .message_battery_not_available
468
+
469
+ return raw_json ["storage" ][0 ]
470
+
446
471
def run_in_console (self ):
447
472
"""If running this module directly, print all the values in the console."""
448
473
print ("Reading..." )
@@ -463,6 +488,7 @@ def run_in_console(self):
463
488
self .lifetime_production (),
464
489
self .lifetime_consumption (),
465
490
self .inverters_production (),
491
+ self .battery_storage (),
466
492
return_exceptions = True ,
467
493
)
468
494
)
@@ -485,6 +511,7 @@ def run_in_console(self):
485
511
)
486
512
else :
487
513
print ("inverters_production: {}" .format (results [8 ]))
514
+ print ("battery_storage: {}" .format (results [9 ]))
488
515
489
516
490
517
if __name__ == "__main__" :
0 commit comments