Skip to content

Commit

Permalink
Merge pull request #59 from gtdiehl/master
Browse files Browse the repository at this point in the history
Add retries when gathering Inverter data
  • Loading branch information
gtdiehl authored Dec 28, 2020
2 parents a0a3d8c + 95ee71b commit e993bd7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
48 changes: 26 additions & 22 deletions envoy_reader/envoy_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,34 @@ async def getData(self):
await self.detect_model()

if(self.get_inverters):
"""If a password was not given as an argument when instantiating
the EnvoyReader object than use the last six numbers of the serial
number as the password. Otherwise use the password argument value."""
if self.password == "":
if self.serial_number_last_six == "":
for i in range(0,3):
while True:
"""If a password was not given as an argument when instantiating
the EnvoyReader object than use the last six numbers of the serial
number as the password. Otherwise use the password argument value."""
if self.password == "":
if self.serial_number_last_six == "":
try:
await self.get_serial_number()
except httpx.HTTPError:
raise
self.password = self.serial_number_last_six
try:
await self.get_serial_number()
async with httpx.AsyncClient() as client:
response = await client.get(ENDPOINT_URL_PRODUCTION_INVERTERS.format(self.host),
timeout=30, auth=httpx.DigestAuth(self.username, self.password))
if response is not None and response.status_code != 401:
self.endpoint_production_inverters = response
else:
response.raise_for_status()
except (httpcore.RemoteProtocolError, httpx.RemoteProtocolError) as err:
continue
except httpx.HTTPError:
raise
self.password = self.serial_number_last_six
try:
async with httpx.AsyncClient() as client:
response = await client.get(ENDPOINT_URL_PRODUCTION_INVERTERS.format(self.host),
timeout=30, auth=httpx.DigestAuth(self.username, self.password))
if response is not None and response.status_code != 401:
self.endpoint_production_inverters = response
else:
response.raise_for_status()
except (httpx.RemoteProtocolError):
raise
except (httpcore.RemoteProtocolError, httpx.RemoteProtocolError):
await response.close()
except httpx.HTTPError:
response.raise_for_status()
response.raise_for_status()
break
break
if(i == 2):
raise httpx.RemoteProtocolError(message='Malformed request. Failed after 3 retries.', request=None)

async def detect_model(self):
"""Method to determine if the Envoy supports consumption values or
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="envoy_reader",
version="0.18.1",
version="0.18.2",
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 e993bd7

Please sign in to comment.