Leggin / dirigera

This repository provides an unofficial Python client for controlling the IKEA Dirigera Smart Home Hub.
MIT License
105 stars 20 forks source link

Lights set_light_level asserts incorrect value range #20

Closed benteg closed 1 year ago

benteg commented 1 year ago
>>> import dirigera
>>> hub = dirigera.Hub(token="...", ip_address="xxx.xxx.xxx.xxx")
>>> light = hub.get_light_by_name("...")

Negative values raise an AssertionError as expected:

>>> light.set_light_level(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.11/site-packages/dirigera/devices/light.py", line 73, in set_light_level
    raise AssertionError("light_level must be a value between 0 and 100")
AssertionError: light_level must be a value between 0 and 100

https://github.com/Leggin/dirigera/blob/192a8483051e821ba3514e53e1b1715c6bf1239b/src/dirigera/devices/light.py#L72-L73

Zero should be ok according to the error message but raises an HTTPError:

>>> light.set_light_level(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.11/site-packages/dirigera/devices/light.py", line 76, in set_light_level
    self.dirigera_client.patch(route=f"/devices/{self.device_id}", data=data)
  File "/home/user/.local/lib/python3.11/site-packages/dirigera/hub/hub.py", line 78, in patch
    response.raise_for_status()
  File "/home/user/.local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://xxx.xxx.xxx.xxx:8443/v1/devices/...

One and above work as expected:

>>> light.set_light_level(1)
>>>