app changes, including initial tap dial
This commit is contained in:
47
apps/tap_dial.py
Normal file
47
apps/tap_dial.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import re
|
||||
|
||||
from appdaemon.entity import Entity
|
||||
from appdaemon.plugins.hass.hassapi import Hass
|
||||
|
||||
|
||||
BUTTON_PRESS = re.compile(r'button_(\d)_press_release')
|
||||
|
||||
|
||||
|
||||
class TapDial(Hass):
|
||||
active_entity: Entity
|
||||
|
||||
def initialize(self):
|
||||
self.log(f"Action entity: {self.tap_dial_entity.friendly_name}")
|
||||
self.tap_dial_entity.listen_state(self.my_callback)
|
||||
|
||||
@property
|
||||
def tap_dial_entity(self) -> Entity:
|
||||
return self.get_entity(self.args["entity"])
|
||||
|
||||
@property
|
||||
def step_size(self) -> int:
|
||||
return int(self.args.get("step_size", 25))
|
||||
|
||||
def my_callback(self, entity: str, attribute: str, old: str, new: str, **kwargs):
|
||||
# self.log(f'{new}')
|
||||
if new:
|
||||
if m := BUTTON_PRESS.match(new):
|
||||
pressed_button = int(m.group(1))
|
||||
self.log(f'Pressed button {pressed_button}')
|
||||
|
||||
if associated_light := self.args.get(f'button{pressed_button}'):
|
||||
light_entity = self.get_entity(associated_light)
|
||||
self.active_entity = light_entity
|
||||
self.log(f'Setting active entity to {self.active_entity.friendly_name}')
|
||||
self.active_entity.toggle()
|
||||
|
||||
match new:
|
||||
case "dial_rotate_right_step":
|
||||
b = self.active_entity.attributes['brightness']
|
||||
self.active_entity.turn_on(brightness=b+self.step_size)
|
||||
case "dial_rotate_left_step":
|
||||
b = self.active_entity.attributes['brightness']
|
||||
self.active_entity.turn_on(brightness=b-self.step_size)
|
||||
# case _:
|
||||
# self.log(f'Unhandled action: {new}')
|
||||
Reference in New Issue
Block a user