Skip to content

Commit d5b59ed

Browse files
committed
fix: bug when running supervised without addon
1 parent 52d782d commit d5b59ed

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

custom_components/tesla_custom/config_flow.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ def _async_schema(self, api_proxy_enable: bool):
146146
}
147147
)
148148

149+
api_proxy_cert = api_proxy_url = client_id = None
149150
if api_proxy_enable:
150151
# autofill fields if HTTP Proxy is running as addon
151152
if "SUPERVISOR_TOKEN" in os.environ:
152-
api_proxy_cert = "/share/tesla/selfsigned.pem"
153-
153+
_LOGGER.debug("Running in supervised environment")
154154
# find out if addon is running from normal repo or local
155155
req = httpx.get(
156156
"http://supervisor/addons",
@@ -162,21 +162,21 @@ def _async_schema(self, api_proxy_enable: bool):
162162
if addon["name"] == "Tesla HTTP Proxy":
163163
addon_slug = addon["slug"]
164164
break
165-
if not addon_slug:
166-
_LOGGER.warning("Unable to communicate with Tesla HTTP Proxy addon")
167-
168-
# read Client ID from addon
169-
req = httpx.get(
170-
f"http://supervisor/addons/{addon_slug}/info",
171-
headers={
172-
"Authorization": f"Bearer {os.environ['SUPERVISOR_TOKEN']}"
173-
},
174-
)
175-
client_id = req.json()["data"]["options"]["client_id"]
176-
api_proxy_url = "https://" + req.json()["data"]["hostname"]
177165

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

181181
schema = schema.extend(
182182
{

0 commit comments

Comments
 (0)