From 9d31cc4fdf948cde62bd1ef6ac3e8bb94c125f7e Mon Sep 17 00:00:00 2001 From: Mohana Date: Sat, 2 Dec 2023 16:17:01 +0330 Subject: [PATCH] Add example for controlling a fan with step mode --- examples/example_fan_step_mode.py | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/example_fan_step_mode.py diff --git a/examples/example_fan_step_mode.py b/examples/example_fan_step_mode.py new file mode 100644 index 000000000..3df535d0b --- /dev/null +++ b/examples/example_fan_step_mode.py @@ -0,0 +1,33 @@ +"""Example for Fan device.""" +import asyncio +from xknx import XKNX +from xknx.devices import Fan, FanSpeedMode + +async def main(): + """Connect to KNX/IP bus, control a fan, and turn it off afterwards.""" + xknx = XKNX() + await xknx.start() + + fan = Fan( + xknx, + name="TestFan", + group_address_switch="1/0/12", + group_address_speed="1/0/14", + max_step=3, + ) + + # Turn on the fan + await fan.turn_on() + + # Set fan speed in steps + for step in range(1, fan.max_step + 1): + await fan.set_speed(step) + await asyncio.sleep(1) + + # Turn off the fan + await fan.turn_off() + + await xknx.stop() + +asyncio.run(main()) +