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

New API that is much more usable and does not need a key #32

Open
alekslyse opened this issue Feb 24, 2019 · 3 comments
Open

New API that is much more usable and does not need a key #32

alekslyse opened this issue Feb 24, 2019 · 3 comments

Comments

@alekslyse
Copy link

alekslyse commented Feb 24, 2019

Dont know how interessting this is or @JrtPec you want a pull request on this, but added a fork that is based on the smappee pro and app api that supports their smarthome system, appliance finder etc. Should not interfere with the existing integrations as I added it to a new class. This version does NOT require an API key, just use the app login credentials

I was thinking about making the MQTT option too as a forth option of this API, but the realtime mqtt is spamming the mqtt server so much its borderline useless, but it exist a websocket mqtt that could be a better choice.

https://github.com/alekslyse/smappy/blob/app-api/smappy/smappy.py

@JrtPec
Copy link
Contributor

JrtPec commented Feb 26, 2019

Hi @alekslyse, sounds great!

Feel free to open a pull request, and I will definitely have a look at it. I had a brief look at your code, and see you are duplicating a lot of methods from the original class, so maybe inheritance is an option?

Having MQTT support would also be nice, but of course only on the condition that it is somewhat useful.

@alekslyse
Copy link
Author

Im not a super python expert, the most changes is authenticate, reauth and api endpoints plus some responses - a lot of your existing methods could be used.

Could you give me an example on how you think I use inheritance.

So you think bringing in a MQTT client into the code or use their native websocket mqtt would be the best option?

@JrtPec
Copy link
Contributor

JrtPec commented Mar 6, 2019

Using inheritance, your code would look something like this:

class AppSmappee(Smappee):
	def authenticate(self, username, password):
        """
        Uses a Smappee username and password to request an access token,
        refresh token and expiry date.
        Parameters
        ----------
        username : str
        password : str
        Returns
        -------
        requests.Response
            access token is saved in self.access_token
            refresh token is saved in self.refresh_token
            expiration time is set in self.token_expiration_time as
            datetime.datetime
        """
        url = URLS['applogin']
        data = {
            "language": "en",
            "userName": username,
            "password": password,
            "refresh": 1,
        }
        r = requests.post(url, data=data)
        r.raise_for_status()
        j = r.json()
        self.access_token = j['token']
        self.refresh_token = j['refreshToken']
        self._set_token_expiration_time(86400)
        return r

    ...

Your new class starts off as exactly the same as the parent class Smappee, and you only have to override the methods that are different. You don't have to re-define the methods that already exist in Smappee and that you have not changed.

Python has some great MQTT-clients, so you could probably use one of those to do some stuff, without having to write too much code. I don't know about MQTT over websocket though... Do you have any documentation about that?

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