Skip to content

Commit d4c7ce5

Browse files
authored
Merge pull request #74 from gtdiehl/battery_status
Add Battery storage data
2 parents 76c90e9 + 7e1c898 commit d4c7ce5

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

envoy_reader/envoy_reader.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class EnvoyReader: # pylint: disable=too-many-instance-attributes
5151
# P for production data only (ie. Envoy model C, s/w >= R3.9)
5252
# PC for production and consumption data (ie. Envoy model S)
5353

54+
message_battery_not_available = (
55+
"Battery storage data not available for your Envoy device."
56+
)
57+
5458
message_consumption_not_available = (
5559
"Consumption data not available for your Envoy device."
5660
)
@@ -443,6 +447,27 @@ async def inverters_production(self):
443447

444448
return response_dict
445449

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+
446471
def run_in_console(self):
447472
"""If running this module directly, print all the values in the console."""
448473
print("Reading...")
@@ -463,6 +488,7 @@ def run_in_console(self):
463488
self.lifetime_production(),
464489
self.lifetime_consumption(),
465490
self.inverters_production(),
491+
self.battery_storage(),
466492
return_exceptions=True,
467493
)
468494
)
@@ -485,6 +511,7 @@ def run_in_console(self):
485511
)
486512
else:
487513
print("inverters_production: {}".format(results[8]))
514+
print("battery_storage: {}".format(results[9]))
488515

489516

490517
if __name__ == "__main__":

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
setuptools.setup(
5252
name="envoy_reader",
53-
version="0.18.5",
53+
version="0.19.0",
5454
author="Jesse Rizzo",
5555
author_email="[email protected]",
5656
description="A program to read from an Enphase Envoy on the local network",

0 commit comments

Comments
 (0)