@@ -146,11 +146,11 @@ def _async_schema(self, api_proxy_enable: bool):
146
146
}
147
147
)
148
148
149
+ api_proxy_cert = api_proxy_url = client_id = None
149
150
if api_proxy_enable :
150
151
# autofill fields if HTTP Proxy is running as addon
151
152
if "SUPERVISOR_TOKEN" in os .environ :
152
- api_proxy_cert = "/share/tesla/selfsigned.pem"
153
-
153
+ _LOGGER .debug ("Running in supervised environment" )
154
154
# find out if addon is running from normal repo or local
155
155
req = httpx .get (
156
156
"http://supervisor/addons" ,
@@ -162,21 +162,21 @@ def _async_schema(self, api_proxy_enable: bool):
162
162
if addon ["name" ] == "Tesla HTTP Proxy" :
163
163
addon_slug = addon ["slug" ]
164
164
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" ]
177
165
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" )
180
180
181
181
schema = schema .extend (
182
182
{
0 commit comments