diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2023-07-09 19:37:37 +0200 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2023-07-09 19:37:37 +0200 |
commit | b966f6e4705a813dad13b242e9592e699566d9c9 (patch) | |
tree | fba1a57bf3ed01b7826487c98f000ae9f111cf20 /examples | |
download | ShellyPy-b966f6e4705a813dad13b242e9592e699566d9c9.tar.gz ShellyPy-b966f6e4705a813dad13b242e9592e699566d9c9.zip |
Squash rewriterewrite
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gen.py | 10 | ||||
-rw-r--r-- | examples/light.py | 27 | ||||
-rw-r--r-- | examples/relay.py | 15 | ||||
-rw-r--r-- | examples/roller.py | 18 |
4 files changed, 70 insertions, 0 deletions
diff --git a/examples/gen.py b/examples/gen.py new file mode 100644 index 0000000..84c5316 --- /dev/null +++ b/examples/gen.py @@ -0,0 +1,10 @@ +import ShellyPy + +# Automatically detect device generation and return the right class +device = ShellyPy.api.Device.connect("192.0.0.20") + +# Explicitly connect a Generation 1 Device +device_gen1 = ShellyPy.api.gen1.Device.connect("192.0.0.21") + +# Explicitly connect a Generation 2 Device +device_gen2 = ShellyPy.api.gen2.Device.connect("192.0.0.22") diff --git a/examples/light.py b/examples/light.py new file mode 100644 index 0000000..3b679ab --- /dev/null +++ b/examples/light.py @@ -0,0 +1,27 @@ +import ShellyPy + +device = ShellyPy.api.Device.connect("192.0.0.20") + +# turn all lights off +device.lights.off() + +# turn all lights on +device.lights.on() + +# toggle all lights +device.lights.toggle() + +# return light 0 on +device.lights[0].on() + +# Set Brightness in percent +device.lights[0].brightness = 50 # 50% + +# Set RGB colors (Gen 1 only) +device.lights[0].rgb = (255, 255, 255) + +# Set RGBW colors (Gen 1 only) +device.lights[0].rgbw = (128, 128, 128, 0) + +# Set only one color (Gen 1 only) +device.lights[0].red = 64 diff --git a/examples/relay.py b/examples/relay.py new file mode 100644 index 0000000..36bbe45 --- /dev/null +++ b/examples/relay.py @@ -0,0 +1,15 @@ +import ShellyPy + +device = ShellyPy.api.Device.connect("192.0.0.20") + +# turn all relays off +device.relays.off() + +# turn all relays on +device.relays.on() + +# toggle all relays +device.relays.toggle() + +# return relay 0 on +device.relays[0].on() diff --git a/examples/roller.py b/examples/roller.py new file mode 100644 index 0000000..70a6446 --- /dev/null +++ b/examples/roller.py @@ -0,0 +1,18 @@ +import ShellyPy + +device = ShellyPy.api.Device.connect("192.0.0.20") + +# open all rollers +device.rollers.open() + +# close all rollers +device.rollers.close() + +# stop all rollers +device.rollers.stop() + +# set roller 1 position to 50% (requires calibration) +device.rollers[1].pos = 50 # 50% + +# calibrate roller 1 (will find new min and max position) +device.rollers[1].calibrate() |