Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for OpenEVSE WiFi v4 API #29

Open
drobtravels opened this issue Oct 29, 2021 · 1 comment
Open

Updates for OpenEVSE WiFi v4 API #29

drobtravels opened this issue Oct 29, 2021 · 1 comment

Comments

@drobtravels
Copy link

I'm working on an updated Home Assistant integration. Per OpenEVSE docs the HTTP API is now the recommended way to send commands to OpenEVSE, so this may require significant changes to this library as it currently uses RAPI.

I wanted to check in if you prefer I make a PR to this library, or create a new library?

@omriasta
Copy link

omriasta commented Nov 4, 2021

Hey, I had the same thing in mind and it looks like there are a lot of things broken with this library, wasn't sure if it was just me.
I noticed that when the Openevse is "Sleeping" this library errors out as it gets "fe" returned instead of the expected "254".
I started working on some changes to try and fix the existing from the issues that I encountered. I pasted some of it below.
This works on my install which is still at 2.9.1 (I ordered the newer wifi module but haven't received yet). The only issue with completely relying on the new API is that it won't work for all the people that have the older module. I think maybe it would be best to run a version check and then have options for both 2.x and newer 4.x.
I have previously worked on another integration to setup the config_flow portion if you need help I'll be glad to assist where I can :)

class Charger:
    def __init__(self, host: str, json: bool = False, username: str = None, password: str = None):
        """A connection to an OpenEVSE charging station equipped with the wifi kit."""
        if json:
            self._url = 'http://' + host + '/r?json=1&'
            self._parseResult = json_parser
        else:
            self._url = 'http://' + host + '/r?'
            self._parseResult = xml_parser
        self._username = username
        self._password = password
        self._host = host

    def _send_command(self, command: str) -> List[str]:
        """Sends a command through the web interface of the charger and parses the response"""
        data = {'rapi': command}
        if self._username and self._password:
            content = requests.post(self._url, data=data, auth=HTTPDigestAuth(self._username, self._password))
        else:
            content = requests.post(self._url, data=data)
        if content.status_code == 401:
            raise InvalidAuthentication
        else:
            return self._parseResult(content.text)

    @property
    def status(self) -> str:
        """Returns the charger's charge status, as a string"""
        status = requests.get('http://' + self._host + '/status', auth=HTTPDigestAuth(self._username, self._password))
        return states[status.json()["state"]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants