diff --git a/lib/TWCManager/EMS/TeslaPowerwall2.py b/lib/TWCManager/EMS/TeslaPowerwall2.py index e29eb1c3..dff89e63 100644 --- a/lib/TWCManager/EMS/TeslaPowerwall2.py +++ b/lib/TWCManager/EMS/TeslaPowerwall2.py @@ -238,6 +238,7 @@ def getStormWatch(self): carapi = self.master.getModuleByName("TeslaAPI") token = carapi.getCarApiBearerToken() expiry = carapi.getCarApiTokenExpireTime() + baseURL = carapi.getCarApiBaseURL() now = time.time() key = "CLOUD/live_status" @@ -252,12 +253,12 @@ def getStormWatch(self): "Content-Type": "application/json", } if not self.cloudID: - url = "https://owner-api.teslamotors.com/api/1/products" + url = baseURL.replace("vehicles", "products") bodyjson = None products = list() try: - r = self.httpSession.get(url, headers=headers) + r = self.httpSession.get(url, headers=headers, verify=carapi.verifyCert) r.raise_for_status() bodyjson = r.json() products = [ @@ -282,16 +283,18 @@ def getStormWatch(self): logger.info("Couldn't find a Powerwall on your Tesla account.") if self.cloudID: - url = f"https://owner-api.teslamotors.com/api/1/energy_sites/{self.cloudID}/live_status" + url = baseURL.replace("vehicles", "energy_sites") + url = f"{url}/{self.cloudID}/live_status" bodyjson = None - result = dict() try: - r = self.httpSession.get(url, headers=headers) + r = self.httpSession.get(url, headers=headers, verify=carapi.verifyCert) r.raise_for_status() bodyjson = r.json() lastData = bodyjson["response"] except: + if r.status_code is 403: + logger.warn("Error fetching Powerwall cloud data; does your API token have energy_device_data scope?") pass self.lastFetch[key] = (now, lastData)