Fix teslacharge module (#809)

Tesla made changes to their API, which broke some pip modules. As such,
we need to switch to a new module and update some calls to properly
track the changes in module behaviour.

Signed-off-by: David Wahlstrom <david.wahlstrom@gmail.com>
This commit is contained in:
David Wahlstrom 2021-11-22 06:51:59 -07:00 committed by GitHub
parent bb78124b89
commit fadd3167fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View File

@ -68,7 +68,7 @@ MOCK_MODULES = [
"requests.adapters", "requests.adapters",
"exchangelib", "exchangelib",
"soco", "soco",
"tesla_api", "teslapy"
"yfinance" "yfinance"
] ]

View File

@ -1,4 +1,4 @@
from tesla_api import TeslaApiClient import teslapy
from i3pystatus import IntervalModule from i3pystatus import IntervalModule
@ -7,7 +7,7 @@ class TeslaCharge(IntervalModule):
Displays the current charge/range of your Tesla vehicle. There is a ton of Displays the current charge/range of your Tesla vehicle. There is a ton of
data that could be displayed, so read this module to see the full list of data that could be displayed, so read this module to see the full list of
datapoints that can be displayed. datapoints that can be displayed.
Requires: tesla_api Requires: teslapy
""" """
settings = ( settings = (
@ -32,21 +32,21 @@ class TeslaCharge(IntervalModule):
def run(self): def run(self):
# Setup Tesla API client # Setup Tesla API client
tclient = TeslaApiClient(self.email, self.password) tclient = teslapy.Tesla(self.email, self.password)
vehicles = tclient.list_vehicles() vehicles = tclient.vehicle_list()
# Currently, only one vehicle is supported. It would be nice to be # Currently, only one vehicle is supported. It would be nice to be
# able to click through multipe vehicles. # able to click through multipe vehicles.
thisvehicle = vehicles[0] thisvehicle = vehicles[0]
display_name = thisvehicle.display_name display_name = thisvehicle['display_name']
# If vehicle is offline, do not bother grabbing info # If vehicle is offline, do not bother grabbing info
if thisvehicle.state != 'online': if thisvehicle['state'] != 'online':
self.output = { self.output = {
"full_text": "%s: %s" % (display_name, thisvehicle.state), "full_text": "%s: %s" % (display_name, thisvehicle['state']),
"color": self.offline_color "color": self.offline_color
} }
else: else:
charge_info = vehicles[0].charge.get_state() charge_info = vehicles[0].get_vehicle_data()['charge_state']
# Miles or meters? # Miles or meters?
if self.units != "miles": if self.units != "miles":