add brightness step transition configuration for smoother adjustments
This commit is contained in:
@@ -17,6 +17,10 @@ from ad_toolbox.eventhandler import EventHandler
|
|||||||
# brightness_pct_step: <int> # optional, default 5
|
# brightness_pct_step: <int> # optional, default 5
|
||||||
# Step size (% of full brightness) used by increase/decrease events.
|
# Step size (% of full brightness) used by increase/decrease events.
|
||||||
#
|
#
|
||||||
|
# brightness_step_transition: <seconds> # optional, default 0.5
|
||||||
|
# Transition duration applied to each increase/decrease brightness
|
||||||
|
# step. Smooths out the brightness change instead of jumping.
|
||||||
|
#
|
||||||
# increase_brightness_events: # optional
|
# increase_brightness_events: # optional
|
||||||
# <EventHandler events_block>
|
# <EventHandler events_block>
|
||||||
# HA events that increase brightness by brightness_pct_step.
|
# HA events that increase brightness by brightness_pct_step.
|
||||||
@@ -69,6 +73,7 @@ from ad_toolbox.eventhandler import EventHandler
|
|||||||
# entity: light.living_room
|
# entity: light.living_room
|
||||||
#
|
#
|
||||||
# brightness_pct_step: 10
|
# brightness_pct_step: 10
|
||||||
|
# brightness_step_transition: 0.5
|
||||||
#
|
#
|
||||||
# increase_brightness_events:
|
# increase_brightness_events:
|
||||||
# btn_up:
|
# btn_up:
|
||||||
@@ -126,6 +131,8 @@ class SmartLight(SmartSwitch):
|
|||||||
self.brightness_pct_step = self.args["brightness_pct_step"]
|
self.brightness_pct_step = self.args["brightness_pct_step"]
|
||||||
else: self.brightness_pct_step = 5
|
else: self.brightness_pct_step = 5
|
||||||
|
|
||||||
|
self.brightness_step_transition = self.args.get("brightness_step_transition", 0.8)
|
||||||
|
|
||||||
# on_events_with_transition: one EventHandler per labelled transition
|
# on_events_with_transition: one EventHandler per labelled transition
|
||||||
if "on_events_with_transition" in self.args:
|
if "on_events_with_transition" in self.args:
|
||||||
for key in self.args["on_events_with_transition"]:
|
for key in self.args["on_events_with_transition"]:
|
||||||
@@ -166,12 +173,12 @@ class SmartLight(SmartSwitch):
|
|||||||
# Increase brightness by brightness_pct_step while the light is on.
|
# Increase brightness by brightness_pct_step while the light is on.
|
||||||
def on_increase_brightness_event(self, event_name, data, kwargs):
|
def on_increase_brightness_event(self, event_name, data, kwargs):
|
||||||
if self.get_state(self.entity_id) != 'off':
|
if self.get_state(self.entity_id) != 'off':
|
||||||
self.call_service("light/turn_on", entity_id = self.entity_id, brightness_step_pct = self.brightness_pct_step)
|
self.call_service("light/turn_on", entity_id = self.entity_id, brightness_step_pct = self.brightness_pct_step, transition = self.brightness_step_transition)
|
||||||
|
|
||||||
# Decrease brightness by brightness_pct_step while the light is on.
|
# Decrease brightness by brightness_pct_step while the light is on.
|
||||||
def on_decrease_brightness_event(self, event_name, data, kwargs):
|
def on_decrease_brightness_event(self, event_name, data, kwargs):
|
||||||
if self.get_state(self.entity_id) != 'off':
|
if self.get_state(self.entity_id) != 'off':
|
||||||
self.call_service("light/turn_on", entity_id = self.entity_id, brightness_step_pct = -self.brightness_pct_step)
|
self.call_service("light/turn_on", entity_id = self.entity_id, brightness_step_pct = -self.brightness_pct_step, transition = self.brightness_step_transition)
|
||||||
|
|
||||||
# EventHandler callback for on_events_with_transition. Jumps to 1 %
|
# EventHandler callback for on_events_with_transition. Jumps to 1 %
|
||||||
# first so the ramp always starts from a known low level, then
|
# first so the ramp always starts from a known low level, then
|
||||||
|
|||||||
Reference in New Issue
Block a user