Skip to content

Commit

Permalink
Merge pull request #583 from ngardiner/powerwall_fleet
Browse files Browse the repository at this point in the history
Fleet API in Powerwall module
  • Loading branch information
MikeBishop committed May 16, 2024
2 parents 2a6a914 + 78d11ff commit 5c619a2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/TWCManager/EMS/TeslaPowerwall2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 = [
Expand All @@ -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)
Expand Down

0 comments on commit 5c619a2

Please sign in to comment.