sdague / mychevy

Python module to interact with my.chevy website for collecting charge data for chevy bolt
Other
50 stars 8 forks source link

Difficulty dockerizing myChevy #4

Closed Sanfam closed 5 years ago

Sanfam commented 6 years ago

Description

Largely for the sake of education, I'm creating a docker image of HASS compatible with myChevy. While I believe everything necessary for it to function is in place I've continued to be unable to successfully use the mychevy component, though I'm not certain if this is now due to a bug with my.chevrolet.com or how I have configured my instance. As of right now, their website displays an error instead of efficiency metrics.

Error: image

Is what I'm seeing in the logs below the expected output of what my.chevrolet is giving me above?

What I Did

Error received during startup:

54726:2018-04-14 19:21:44 ERROR (Thread-3) [homeassistant.components.mychevy] Error updating mychevy data. This probably means the OnStar link is down again
54886-Traceback (most recent call last):
54921:  File "/usr/src/app/homeassistant/components/mychevy.py", line 122, in run
54997-    self.update()
55015-  File "/usr/src/app/homeassistant/util/__init__.py", line 319, in wrapper
55090-    result = method(*args, **kwargs)
55127:  File "/usr/src/app/homeassistant/components/mychevy.py", line 112, in update
55206-    self.car = self._client.data()
55241:  File "/usr/local/lib/python3.6/site-packages/mychevy/mychevy.py", line 125, in data
55327-    chrome_options=chrome_options)
55362-  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
55471-    desired_capabilities=desired_capabilities)
--
56197-selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
56310-  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.14.16-unRAID x86_64)
56432-

Dockerfile:

FROM homeassistant/home-assistant:latest
LABEL maintainer="Andrew Sanjanwala <sanfam@gmail.com>"

# Install Chrome for Selenium
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | tee -a /etc/apt/sources.list && \                      
    curl -sS https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \                                    
    apt-get update && \                                                                                                    
    apt-get -y --no-install-recommends install unzip libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 && \                   
    apt-get -y --no-install-recommends install google-chrome-stable && \
    rm -rf /var/lib/apt/lists/*

# Install Selenium Chromedriver
RUN CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P /tmp
RUN unzip /tmp/chromedriver_linux64.zip -d /tmp
RUN install -m 0755 -o root /tmp/chromedriver /usr/local/bin/chromedriver

# Install myChevy python module
RUN pip install mychevy

image available under sanfamite/home-assistant-mychevy. Feedback is welcome!

sdague commented 6 years ago

Thanks for this! That looks really good.

The my.chevy website hasn't worked for me for the last month or two. I've got some other onstar things to figure out that need a customer service call, so I was going to complain about the website at the same time. So it's not just you, it's just that their website seems completely broken.

Sanfam commented 6 years ago

@sdague I suppose that's good, then. It's a shame their service basically sucks anywhere it isn't absolutely necessary not to.

I was thinking about alternatives and noticed that while both the OnStar and my.chevrolet.com websites fail to return data, that both of their android apps (OnStar Remotelink and MyChevrolet) do seem to reliably fetch and pull data.

Is there any potential worth in tracing the API calls used by these apps and refactoring your calls around them? So long as they aren't obfuscated too heavily, this seems like a good branching-off point may exist.

Sanfam commented 6 years ago

As a bit of a follow-up, I've hit a wall at attempting to sniff out the http requests being generated by the app. Following the instructions here, I've set up a proxy app and confirmed it makes calls to two URLs, https://gmmobileservices.gm.com and https://api.gm.com, but I'm unable to analyze their content since Android Nougat changed how apps define which root CAs they trust. This prevents a connection from being negotiated successfully when middleman certs for Fiddler and Charles Proxy are installed ("Failure | Client SSL handshake failed: An unknown issue occurred processing the certificate (certificate_unknown)").

I'm stuck at not being sure how to add/force trust of the proxy certificate in a way that complies with Android 7's changes to default trust sources.

sdague commented 6 years ago

I believe what that means is the APP uses the official gm api, which they don't make available easily. For the my.chevy website that official API is hidden in a backend service, which constantly seems to fall over, then there is a web UI that pushes against it. It's good that they are encrypting that traffic, but it also means there are probably API keys embedded in the app that you'd need to make any of those calls.

It does explain why the reliability is so different between the two systems.

sdague commented 5 years ago

So, this should end up fixed with the 1.0.1 release. We no longer are using selenium. Will update home assistant code to use this soon.