diff --git a/.gitignore b/.gitignore index dbce267..ecd44d9 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,12 @@ instance/ # Sphinx documentation docs/_build/ +# Ruff cache +.ruff_cache + +# Example dev +/examples/example_dev.py + # PyBuilder .pybuilder/ target/ diff --git a/PyTado/interface/api/hops_tado.py b/PyTado/interface/api/hops_tado.py index 7251369..252eaf1 100644 --- a/PyTado/interface/api/hops_tado.py +++ b/PyTado/interface/api/hops_tado.py @@ -324,3 +324,15 @@ def set_temp_offset(self, device_id, offset=0, measure="celsius"): request.payload = {"temperatureOffset": offset} return self._http.request(request) + + def set_child_lock(self, device_id, child_lock): + """ " + Set and toggle the child lock on the device. + """ + + request = TadoXRequest() + request.command = f"roomsAndDevices/devices/{device_id}" + request.action = Action.CHANGE + request.payload = {"childLockEnabled": child_lock} + + self._http.request(request) diff --git a/PyTado/interface/api/my_tado.py b/PyTado/interface/api/my_tado.py index 091549c..baed7ee 100644 --- a/PyTado/interface/api/my_tado.py +++ b/PyTado/interface/api/my_tado.py @@ -400,6 +400,20 @@ def change_presence(self, presence: Presence) -> None: self._http.request(request) + def set_child_lock(self, device_id, child_lock) -> None: + """ + Sets the child lock on a device + """ + + request = TadoRequest() + request.command = "childLock" + request.action = Action.CHANGE + request.device = device_id + request.domain = Domain.DEVICES + request.payload = {"childLockEnabled": child_lock} + + self._http.request(request) + def set_auto(self) -> None: """ Sets HomeState to AUTO diff --git a/PyTado/interface/interface.py b/PyTado/interface/interface.py index 52c3f53..d2079f0 100644 --- a/PyTado/interface/interface.py +++ b/PyTado/interface/interface.py @@ -77,6 +77,11 @@ def getZones(self): """Gets zones information. (deprecated)""" return self.get_zones() + @deprecated("set_child_lock") + def setChildLock(self, device_id, enabled): + """Set the child lock for a device""" + return self.set_child_lock(device_id, enabled) + @deprecated("get_zone_state") def getZoneState(self, zone): """Gets current state of Zone as a TadoZone object. (deprecated)""" diff --git a/README.md b/README.md index 2ef025a..83fc92d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,25 @@ cause discomfort and inconvenience to others. >>> t = Tado('my@username.com', 'mypassword') >>> climate = t.get_climate(zone=1) +## Usage +```python +"""Example client for PyTado""" + +from PyTado.interface.interface import Tado + + +def main() -> None: + """Retrieve all zones, once successfully logged in""" + tado = Tado(username="mail@email.com", password="password") # nosec + zones = tado.get_zones() + print(zones) + + +if __name__ == "__main__": + main() +``` +Note: for developers, you can create an `example_dev.py` file in the root of the project to test your changes. This file will be ignored by the `.gitignore` file. + ## Contributing We are very open to the community's contributions - be it a quick fix of a typo, or a completely new feature! diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 0000000..d054ccc --- /dev/null +++ b/examples/__init__.py @@ -0,0 +1 @@ +"""Example(s) for PyTado""" diff --git a/examples/example.py b/examples/example.py new file mode 100644 index 0000000..f4f2e66 --- /dev/null +++ b/examples/example.py @@ -0,0 +1,14 @@ +"""Example client for PyTado""" + +from PyTado.interface.interface import Tado + + +def main() -> None: + """Retrieve all zones, once successfully logged in""" + tado = Tado(username="mail@email.com", password="password") # nosec + zones = tado.get_zones() + print(zones) + + +if __name__ == "__main__": + main()