Skip to content

Commit

Permalink
live data
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanbhosale committed May 19, 2024
1 parent a72d1ff commit 3c0e28f
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions quartz_solar_forecast/inverters/enphase.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,32 @@ def get_enphase_access_token():


def get_enphase_data(enphase_system_id: str) -> float:
"""
"""
Get live PV generation data from Enphase API v4
:param enphase_system_id: System ID for Enphase API
:return: Live PV generation in Watt-hours, assumes to be a floating-point number
"""
api_key = os.getenv('ENPHASE_API_KEY')
access_token = get_enphase_access_token()

print("ACCESS TOKEN: ", access_token)
print("API KEY: ", api_key)
# print("ACCESS TOKEN: ", access_token)
# print("API KEY: ", api_key)

conn = http.client.HTTPSConnection("api.enphaseenergy.com")
headers = {
"Authorization": f"Bearer {access_token}",
"key": api_key
"Authorization": f"Bearer {str(access_token)}",
"key": str(api_key)
}
conn.request("GET", f"/api/v4/systems/{enphase_system_id}/live_data", headers=headers)

# Add the system_id and duration parameters to the URL
url = f"/api/v4/systems/{enphase_system_id}/live_data?system_id={enphase_system_id}"
conn.request("GET", url, headers=headers)

# Printing the GET request
print(f"Request: GET {url}")
print("Headers:")
for header, value in headers.items():
print(f"{header}: {value}")

res = conn.getresponse()
data = res.read()

Expand All @@ -129,10 +137,8 @@ def get_enphase_data(enphase_system_id: str) -> float:

# Convert the decoded data into JSON format
data_json = json.loads(decoded_data)

print("LIVE DATA: ", data_json)

# Extracting live generation data assuming it's in Watt-hours
live_generation_wh = data_json['current_power']['power']

return live_generation_wh
return live_generation_wh

0 comments on commit 3c0e28f

Please sign in to comment.