mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-12 10:28:01 +00:00
Update docs with more howto examples (#968)
Co-authored-by: Teemu R. <tpr@iki.fi>
This commit is contained in:
@@ -1,4 +1,72 @@
|
||||
"""Module for LightPreset base class."""
|
||||
"""Interact with TPLink Light Presets.
|
||||
|
||||
>>> from kasa import Discover, Module, LightState
|
||||
>>>
|
||||
>>> dev = await Discover.discover_single(
|
||||
>>> "127.0.0.3",
|
||||
>>> username="user@example.com",
|
||||
>>> password="great_password"
|
||||
>>> )
|
||||
>>> await dev.update()
|
||||
>>> print(dev.alias)
|
||||
Living Room Bulb
|
||||
|
||||
Light presets are accessed via the LightPreset module. To list available presets
|
||||
|
||||
>>> light_preset = dev.modules[Module.LightPreset]
|
||||
>>> light_preset.preset_list
|
||||
['Not set', 'Light preset 1', 'Light preset 2', 'Light preset 3',\
|
||||
'Light preset 4', 'Light preset 5', 'Light preset 6', 'Light preset 7']
|
||||
|
||||
To view the currently selected preset:
|
||||
|
||||
>>> light_preset.preset
|
||||
Not set
|
||||
|
||||
To view the actual light state for the presets:
|
||||
|
||||
>>> len(light_preset.preset_states_list)
|
||||
7
|
||||
|
||||
>>> light_preset.preset_states_list[0]
|
||||
LightState(light_on=None, brightness=50, hue=0,\
|
||||
saturation=100, color_temp=2700, transition=None)
|
||||
|
||||
To set a preset as active:
|
||||
|
||||
>>> dev.modules[Module.Light].state # This is only needed to show the example working
|
||||
LightState(light_on=True, brightness=100, hue=0,\
|
||||
saturation=100, color_temp=2700, transition=None)
|
||||
>>> await light_preset.set_preset("Light preset 1")
|
||||
>>> await dev.update()
|
||||
>>> light_preset.preset
|
||||
Light preset 1
|
||||
>>> dev.modules[Module.Light].state # This is only needed to show the example working
|
||||
LightState(light_on=True, brightness=50, hue=0,\
|
||||
saturation=100, color_temp=2700, transition=None)
|
||||
|
||||
You can save a new preset state if the device supports it:
|
||||
|
||||
>>> if light_preset.has_save_preset:
|
||||
>>> new_preset_state = LightState(light_on=True, brightness=75, hue=0,\
|
||||
saturation=100, color_temp=2700, transition=None)
|
||||
>>> await light_preset.save_preset("Light preset 1", new_preset_state)
|
||||
>>> await dev.update()
|
||||
>>> light_preset.preset # Saving updates the preset state for the preset, it does not \
|
||||
set the preset
|
||||
Not set
|
||||
>>> light_preset.preset_states_list[0]
|
||||
LightState(light_on=None, brightness=75, hue=0,\
|
||||
saturation=100, color_temp=2700, transition=None)
|
||||
|
||||
If you manually set the light state to a preset state it will show that preset as \
|
||||
active:
|
||||
|
||||
>>> await dev.modules[Module.Light].set_brightness(75)
|
||||
>>> await dev.update()
|
||||
>>> light_preset.preset
|
||||
Light preset 1
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
Reference in New Issue
Block a user