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",
"exchangelib",
"soco",
"tesla_api",
"teslapy"
"yfinance"
]

View File

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