smartcar / python-sdk Goto Github PK
View Code? Open in Web Editor NEWSmartcar Python SDK
License: MIT License
Smartcar Python SDK
License: MIT License
in smartcar/vehicle.py
-def hazard_light(self):
+def hazard_lights(self):
According to Smartcar’s API reference, disconnect
should return a value (dict with key status
): https://smartcar.com/docs/api?language=Python#delete-disconnect
Obviously there is no return value:
python-sdk/smartcar/vehicle.py
Line 100 in 3d84b89
The documentation is out of date and also needs some fixes.
export SMARTCAR_CLIENT_ID='<your client id>'
export SMARTCAR_CLIENT_ID='<your client secret>'
export SMARTCAR_CLIENT_ID='<your redirect URI>'
vehicles = smartcar.get_vehicle_ids(<access_token>)
method should be replaced by get_vehicles
.Since this is a FOSS project, I propose adding Codecov integration (free). This will give developers who use this package a higher level of confidence when shipping code.
This can easily achieved by creating a workflow using GitHub actions adding codecov
to after_success
step in .travis.yml
, which will run a coverage branch analysis on each PR. We can easily add a badge to the README and give full visibility of the project code coverage.
I can open up a PR
Note: this repo will need to be enabled via codecov dashboard
OAuth uses x-www-form-urlencoded
encoding for the body parameters. But both methods are using params
, which put the options into the url instead of the body. They should be using data
instead to send form data.
In addition, it does not seem as though the Basic Authentication headers are being sent with the client_id
/client_secret
either.
The message
property is not returned on some errors. OAuth errors, for example use error
and error_description
properties. In L3 of exceptions.py
we have:
self.message = response.json()['message']
// A safer .get() might be better
self.message = response.json().get('message')
Instead, we should handle for OAuth exceptions as well, and have a default message, should the other keys not exist.
There is no equivalent of the Smartcar.prototype.expired
method on the python-sdk. (I think this is missing from the java sdk as well)
This would be necessary to know whether or not to refresh a token. This also requires the creation of a created_at
field on the access.
Hello,
the current smartcar
module scope is missing the is_expired
attribute. If I read the reference correctly, it should be present there. It is also used in the integration guide.
Readme travis badge is broken, switch to https://travis-ci.com/smartcar/python-sdk.svg?token=FcsopC3DdDmqUpnZsrwg&branch=master
README should contain instructions on installation, testing, and, usage.
Python 2.7 will no longer be supported after January 1st, 2020 [1] and Python 3.4 has been unsupported since March of this year. [2]
[1]: https://devguide.python.org/#status-of-python-branches
[2]: https://www.python.org/dev/peps/pep-0429/#release-schedule
[3]: https://en.wikipedia.org/wiki/History_of_Python
Upon calling flash_headlight
with most recent python sdk as of 12/16/16:
File "/mnt/c/Users/robinjayaswal/Documents/GitHub/iotUIClient/iot-lambda-function/smartcar/vehicle.py", line
157, in flash_headlight
return self.api.action("lights/headlight", "FLASH")
File "/mnt/c/Users/robinjayaswal/Documents/GitHub/iotUIClient/iot-lambda-function/smartcar/api.py", line 27,
in action
return requester.call('POST', url, json=json, headers=self.auth)
File "/mnt/c/Users/robinjayaswal/Documents/GitHub/iotUIClient/iot-lambda-function/smartcar/requester.py", lin
e 20, in call
raise E.ResourceNotFoundException(response)
smartcar.exceptions.ResourceNotFoundException: The requested resource was not found.
Please keep a changelog summarizing user-facing issues so upgrades are easy to understand: https://keepachangelog.com/en/1.0.0/
Thanks :)
I found a bug in the get_connections
code where it is not using the cursor from the paging object passed in. Instead the code is checking that the cursor exists on the paging object and then tries to get it from the filter object.
This should be a quick fix and has a work around where you add cursor to both the paging and filter object.
relevant code here.
https://github.com/smartcar/python-sdk/blob/master/smartcar/smartcar.py#L294-L301
Refactor the charge limit methods:
- enable_charge_limit()
- disable_charge_limit()
+ set_charge_limit()
api-schema doc: https://github.com/smartcar/api-schema/blob/master/src/paths/charge.limit.yaml
Travis CI is now enabled for this repository, you should be able to setup a .travis.yml
file. Make sure to test against all versions of python we care about.
Response units can be set using the unit-system
header
Add turn_on_headlights()
and turn_off_headlights()
methods.
api-schema doc: https://github.com/smartcar/api-schema/blob/master/src/paths/lights.headlights.yaml
open_sunroof
should have an optional percentage
parameter.
By default the backend will open the sunroof fully.
api-schema doc: https://github.com/smartcar/api-schema/blob/master/src/paths/sunroof.yaml
Probably one of the most useful features aside from lock/unlock would be start/stop. Anecdotally, these are the two features I find the most useful in-app and it would be very helpful to have remote start available via the API.
- tilt_sideview_mirrors
+ tilt_side_view_mirrors
I am using smartcar==6.10.1 python package.
When calling the batch
function passing a list of endpoints, if a rate limit smartcar.exceptions.SmartcarException
occurs, the exception is always missing the retry_after
key, which is supposed to be taken from the Retry-After header.
Below is one example where I made a request which gets rate limited and returns a Retry-After header, but the exception does not have the retry_after
key. The request id is: 58ae060d-0a03-40a4-a628-3b699b479cd7
I figured out why the problem is happenning, I am happy to open a PR for the fix if I am on the right track here:
When the batch
function is called, each passed endpoint's response is checked whether it has a HTTP status different than 200. Of course the endpoint with the request-id given above has a status of 429 (rate limit), and the batch function invokes the exception factory, constructs the exception and assigns it to be raised when that specific attribute is later called on the batch result object. The problem is in the batch
function (which is found in vehicle.py:400), when it invokes exception_factory
, it passes the headers of the batch request itself, not the headers of the individual endpoint that failed. I can actually see in code that here (vehicle.py:457):
sc_exception = sce.exception_factory(code, headers, body)
headers
are missing the Retry-After header, but res_dict.get("headers")
actually is {'Retry-After': 80}
res_dict
is the individual response for each of the invoked endpoint within the batch, not the batch's response (which is always 200)
So I tested when I change vehicle:457 from:
sc_exception = sce.exception_factory(code, headers, body)
to:
sc_exception = sce.exception_factory(code, {**headers, "Retry-After": res_dict.get("headers").get("Retry-After")}, body)
My smartcar.exceptions.SmartcarException
object has a present retry_after
attribute.
vehicle = smartcar.Vehicle(vehicle_id, access_token)
odometer = vehicle.odometer()['data']['odometer']
Errors with:
KeyError: 'odometer'
Hello,
this is not an issue per se but rather a question about something I couldn't find in the docs. They describe in much detail how an app gets authenticated when the user logs in via a web page or mobile app, and then "user’s browser is redirected to a specified redirect_uri." This doesn't work for me though. I'm developing a fully autonomous back-end app that won't have a front-end and which must work without the user who would manually log in and without a browser or another UI object. I wasn't able to find docs that would describe how to proceed in such a situation. Here's where I am now: I created a client and obtained auth_url as described in the docs:
client = smartcar.AuthClient(client_ID, client_secret, client_secret, redirect_uri, scope)
auth_url = client.get_auth_url()
My redirect_uri
points to an URL at my server at which my app is listening and will parse a request when received. What should I do now to ask smartcar to send that request to my redirect_uri
? I tried r = requests.get(auth_url)
but I've got <Response [400]> / Bad request
. No request was sent to redirect_uri
. Please advise.
Thank you,
Greg (dev ID 8f272ab7-e2ae-428b-83cc-bdfb6c44edce)
On September 10th, 2020 between 7 p.m. and 8 p.m. CEST we faced issues when using Smartcar’s API to communicate with Tesla vehicles. After five minutes a simplejson.errors.JSONDecodeError
exception was thrown.
Wouldn’t it be nicer to have that exception wrapped in a SmartcarException
with additional information about what caused the error?
File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/smartcar/vehicle.py", line 311, in batch
response = self.api.batch(requests)
File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/smartcar/api.py", line 79, in batch
return requester.call('POST', url, json=json, headers=headers)
File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/smartcar/requester.py", line 31, in call
body = response.json()
File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/simplejson/__init__.py", line 525, in loads
return _default_decoder.decode(s)
File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.