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

add home by bridge api to my tado #134

Merged
merged 5 commits into from
Dec 28, 2024

Conversation

wmalgadey
Copy link
Owner

@wmalgadey wmalgadey commented Dec 28, 2024

Description

Added the requests to homeByBridge endpoint of my.tado.com API and included tests.

Some changes are not related to this feature, but I changed it too, because it iritated me while testing:

  • simplified and removed duplicated code in http.py::_configure_url
  • added logging to all http requests. Logging was not implemented for general requests... why?

Related Issues


Type of Changes

Mark the type of changes included in this pull request:

  • Bugfix
  • New Feature
  • Documentation Update
  • Refactor
  • Other (please specify):

Checklist

  • I have tested the changes locally and they work as expected.
  • I have added/updated necessary documentation (if applicable).
  • I have followed the code style and guidelines of the project.
  • I have searched for and linked any related issues.

Additional Notes

Add any additional comments, screenshots, or context for the reviewer(s).


Thank you for your contribution to PyTado! 🎉

- added logging to all http requests
@wmalgadey wmalgadey self-assigned this Dec 28, 2024
@LarsStegman
Copy link

LarsStegman commented Dec 28, 2024

Hi, I tested this and it works properly. Is it also possible to change the max temperature?

@wmalgadey
Copy link
Owner Author

Hi, I tested this and it works properly. Is it also possible to change the max temperature?

If you give me an example how the website did it, sure.

@LarsStegman
Copy link

It's the first request. It's a PUT request.

@wmalgadey
Copy link
Owner Author

It's the first request. It's a PUT request.

ohh! did the get_boiler_max_output_temperature-method work? I did miss that :D part of the log

@LarsStegman
Copy link

Yes, that worked as well.

- with proper testing
@wmalgadey
Copy link
Owner Author

@LarsStegman added the set method too

@LarsStegman
Copy link

The method kind of works. The setpoint is actually changed, but the response is always empty, so calling response.json() on the response fails. Also, it i possible to send a float instead of an int as the setpoint.

@wmalgadey
Copy link
Owner Author

I changed the param to float. The response should only execute .json() if the response contains some content! is there an error you get?

@LarsStegman
Copy link

This is the error I get:

/Users/larsstegman/Developer/PyTado/venv/bin/python /Users/larsstegman/Developer/PyTado/main.py 
Traceback (most recent call last):
  File "/Users/larsstegman/Developer/PyTado/venv/lib/python3.12/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/decoder.py", line 338, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/json/decoder.py", line 356, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/larsstegman/Developer/PyTado/main.py", line 17, in <module>
    main()
  File "/Users/larsstegman/Developer/PyTado/main.py", line 11, in main
    set_response = t.set_boiler_max_output_temperature(bridge_id, auth_key, 51)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/larsstegman/Developer/PyTado/PyTado/interface/api/my_tado.py", line 653, in set_boiler_max_output_temperature
    return self._http.request(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/larsstegman/Developer/PyTado/PyTado/http.py", line 191, in request
    response = self._session.send(prepped)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/larsstegman/Developer/PyTado/venv/lib/python3.12/site-packages/requests/sessions.py", line 710, in send
    r = dispatch_hook("response", hooks, r, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/larsstegman/Developer/PyTado/venv/lib/python3.12/site-packages/requests/hooks.py", line 30, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/larsstegman/Developer/PyTado/PyTado/http.py", line 172, in _log_response
    f"\n\tData: {response.json()}"
                 ^^^^^^^^^^^^^^^
  File "/Users/larsstegman/Developer/PyTado/venv/lib/python3.12/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Process finished with exit code 1

The problem is the _log_response function.

@wmalgadey
Copy link
Owner Author

Ok, should be fixed. The error was inside debug logging!

Copy link

Code Coverage

Package Line Rate Complexity Health
. 74% 0
interface 71% 0
interface.api 40% 0
zone 93% 0
Summary 64% (658 / 1031) 0

Minimum allowed line rate is 60%

@LarsStegman
Copy link

Seems to work properly now!

@wmalgadey wmalgadey merged commit eaec632 into master Dec 28, 2024
9 checks passed
@wmalgadey wmalgadey deleted the 131-feature-read-current-supply-temperature branch December 28, 2024 20:08
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

Successfully merging this pull request may close these issues.

[Feature]: read current supply temperature
3 participants