Skip to content

Commit

Permalink
Merge pull request #74 from gtdiehl/battery_status
Browse files Browse the repository at this point in the history
Add Battery storage data
  • Loading branch information
gtdiehl authored Apr 23, 2021
2 parents 76c90e9 + 7e1c898 commit d4c7ce5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions envoy_reader/envoy_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class EnvoyReader: # pylint: disable=too-many-instance-attributes
# P for production data only (ie. Envoy model C, s/w >= R3.9)
# PC for production and consumption data (ie. Envoy model S)

message_battery_not_available = (
"Battery storage data not available for your Envoy device."
)

message_consumption_not_available = (
"Consumption data not available for your Envoy device."
)
Expand Down Expand Up @@ -443,6 +447,27 @@ async def inverters_production(self):

return response_dict

async def battery_storage(self):
"""Return battery data from Envoys that support and have batteries installed"""
if (
self.endpoint_type == ENVOY_MODEL_LEGACY
or self.endpoint_type == ENVOY_MODEL_C
):
return self.message_battery_not_available

try:
raw_json = self.endpoint_production_json_results.json()
except (JSONDecodeError):
return None

"""For Envoys that support batteries but do not have them installed the"""
"""percentFull will not be available in the JSON results. The API will"""
"""only return battery data if batteries are installed."""
if "percentFull" not in raw_json["storage"][0].keys():
return self.message_battery_not_available

return raw_json["storage"][0]

def run_in_console(self):
"""If running this module directly, print all the values in the console."""
print("Reading...")
Expand All @@ -463,6 +488,7 @@ def run_in_console(self):
self.lifetime_production(),
self.lifetime_consumption(),
self.inverters_production(),
self.battery_storage(),
return_exceptions=True,
)
)
Expand All @@ -485,6 +511,7 @@ def run_in_console(self):
)
else:
print("inverters_production: {}".format(results[8]))
print("battery_storage: {}".format(results[9]))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

setuptools.setup(
name="envoy_reader",
version="0.18.5",
version="0.19.0",
author="Jesse Rizzo",
author_email="[email protected]",
description="A program to read from an Enphase Envoy on the local network",
Expand Down

0 comments on commit d4c7ce5

Please sign in to comment.