Leggin / dirigera

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

feat: Add methods to get light, outlet and controller by id #34

Closed IvarMatstoms closed 8 months ago

IvarMatstoms commented 8 months ago

Added methods to get light, outlet and controller by id (i.e. for small script to turn a specific light on/off). Due to how the DIRIGERA api is designed fetching a device by its id does not require fetching all light and filtering out the wanted devices unlike fetching device by name.

To keep the codebase DRY a private method is used to fetch device data (the json returned by the DIRIGERA hub)

To keep users of the library from having to deal with the internal implementation http errors caught and transformed into a ValueError if the error is a 404 (the device does not exist) otherwise reraised

Also a value error is raised if the device is not of expected type (a device id for a outlet is provided to get_light_by_id)

I can add methods for other devices (blinds etc) but I do not own any other device type so i will not be able to test

Methods added

Hub._get_device_data_by_id(id_: str) -> Dict
Hub.get_light_by_id(id_: str) -> Light
Hub.get_outlet_by_id(id_: str) -> Outlet
Hub.get_controller_by_id(id_: str) -> Controller