-
I used to have function split "by functionality" (a module for lights, another one for the roller shutters, ...) and I am now reorganizing them "by room". More code but also more readable. I have therefore several functions such as the one below where I am iterating through several "rooms" (in the example below - just one - @time_trigger("once(09:00)")
def volets_matin_partiel():
partial_height = 40
for who in ['parents']:
if state.get(f"input_boolean.volets_{who}") == 'on':
if state.getattr(f"cover.{who}_volets")['current_position'] < partial_height:
cover.set_cover_position(entity_id=f"cover.{who}_volets", position=partial_height)
else:
log.info(f"volets {who} déjà ouverts") I could duplicate them across the "rooms" but that would be repeated code and I would prefer to keep one function (say, in a module How should I approach this? In other words, I would like something in room "michael" (in file @time_trigger("once(09:00)")
volets_partiel(room=michael, partiel=40) This is not the correct code because the decorator is for function definition (and not function call), I am not sure if there is a way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I use the modules/volets_helpers.py
scripts/michael.py
|
Beta Was this translation helpful? Give feedback.
I use the
modules
directory for this, and pyscript has some stuff builtin to help.modules/volets_helpers.py
scripts/michael.py