Skip to content

Commit

Permalink
fix: UnboundLocalError when supervised without addon (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
llamafilm committed Mar 14, 2024
1 parent 52d782d commit 57259d9
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions custom_components/tesla_custom/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ def _async_schema(self, api_proxy_enable: bool):
}
)

api_proxy_cert = api_proxy_url = client_id = None
if api_proxy_enable:
# autofill fields if HTTP Proxy is running as addon
if "SUPERVISOR_TOKEN" in os.environ:
api_proxy_cert = "/share/tesla/selfsigned.pem"

_LOGGER.debug("Running in supervised environment")
# find out if addon is running from normal repo or local
req = httpx.get(
"http://supervisor/addons",
Expand All @@ -162,21 +162,21 @@ def _async_schema(self, api_proxy_enable: bool):
if addon["name"] == "Tesla HTTP Proxy":
addon_slug = addon["slug"]
break
if not addon_slug:
_LOGGER.warning("Unable to communicate with Tesla HTTP Proxy addon")

# read Client ID from addon
req = httpx.get(
f"http://supervisor/addons/{addon_slug}/info",
headers={
"Authorization": f"Bearer {os.environ['SUPERVISOR_TOKEN']}"
},
)
client_id = req.json()["data"]["options"]["client_id"]
api_proxy_url = "https://" + req.json()["data"]["hostname"]

else:
api_proxy_url = client_id = api_proxy_cert = None
try:
# read Client ID from addon
req = httpx.get(
f"http://supervisor/addons/{addon_slug}/info",
headers={
"Authorization": f"Bearer {os.environ['SUPERVISOR_TOKEN']}"
},
)
client_id = req.json()["data"]["options"]["client_id"]
api_proxy_url = "https://" + req.json()["data"]["hostname"]
api_proxy_cert = "/share/tesla/selfsigned.pem"
_LOGGER.debug("Found addon: %s", addon_slug)
except NameError:
_LOGGER.warning("Unable to communicate with Tesla HTTP Proxy addon")

schema = schema.extend(
{
Expand Down

0 comments on commit 57259d9

Please sign in to comment.