Skip to content

Commit

Permalink
Merge pull request #18 from muxa/dev
Browse files Browse the repository at this point in the history
1.0.0-rc.8
  • Loading branch information
muxa authored Nov 13, 2021
2 parents 15baa05 + 19b97b3 commit 31aa61e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ binary_sensor:
* **transitions** (**Required**, list): The list of allowed transitions. Short form is `FROM_STATE -> TO_STATE`, or advanced configuration:
* **from** (**Required**, string): Source state that this input is allowed on.
* **to** (**Required**, string): Target state that this input transitions to.
* **action** (*Optional*, [Automation](https://esphome.io/guides/automations.html#automation)): An automation to perform when transition is performed.
* **action** (*Optional*, [Automation](https://esphome.io/guides/automations.html#automation)): An automation to perform when transition is done by this input. This action is performed after transition-specific action.
* **action** (*Optional*, [Automation](https://esphome.io/guides/automations.html#automation)): An automation to perform when transition is performed. This action is performed before state's `on_leave` action is called.
* **action** (*Optional*, [Automation](https://esphome.io/guides/automations.html#automation)): An automation to perform when transition is done by this input. This action is performed after transition-specific action and before state's `on_leave` action is called.

* **diagram** (*Optional*, boolean): If true, then a diagram of the state machine will be ouput to the console during validation/compilation of YAML. See **Diagrams** section below for more details. Defaults to `false`.
* **diagram** (*Optional*, boolean): If true, then a diagram of the state machine will be output to the console during validation/compilation of YAML. See **Diagrams** section below for more details. Defaults to `false`.

> ### Note:
>
Expand Down
44 changes: 22 additions & 22 deletions components/state_machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async def to_code(config):
if CONF_NAME in config:
cg.add(var.set_name(config[CONF_NAME]))

# setup on_set automations first
# setup on_set automations
for state in config[CONF_STATES_KEY]:

if CONF_STATE_ON_LEAVE_KEY in state:
Expand All @@ -246,26 +246,7 @@ async def to_code(config):
)
await automation.build_automation(trigger, [], action)

# then setup on_leave automations (to ensure they are executed before on_enter)
for state in config[CONF_STATES_KEY]:

if CONF_STATE_ON_LEAVE_KEY in state:
for action in state.get(CONF_STATE_ON_LEAVE_KEY, []):
trigger = cg.new_Pvariable(
action[CONF_TRIGGER_ID], var, state[CONF_NAME]
)
await automation.build_automation(trigger, [], action)

# setup on_enter automations after on_leave
for state in config[CONF_STATES_KEY]:

if CONF_STATE_ON_ENTER_KEY in state:
for action in state.get(CONF_STATE_ON_ENTER_KEY, []):
trigger = cg.new_Pvariable(
action[CONF_TRIGGER_ID], var, state[CONF_NAME]
)
await automation.build_automation(trigger, [], action)

# 1. setup transition/input automations (they should run first)
for input in config[CONF_INPUTS_KEY]:
if CONF_INPUT_TRANSITIONS_KEY in input:
for transition in input[CONF_INPUT_TRANSITIONS_KEY]:
Expand All @@ -289,7 +270,26 @@ async def to_code(config):
action[CONF_TRIGGER_ID], var, input[CONF_NAME]
)
await automation.build_automation(trigger, [], action)


# 2. setup on_leave automations (to ensure they are executed before on_enter)
for state in config[CONF_STATES_KEY]:

if CONF_STATE_ON_LEAVE_KEY in state:
for action in state.get(CONF_STATE_ON_LEAVE_KEY, []):
trigger = cg.new_Pvariable(
action[CONF_TRIGGER_ID], var, state[CONF_NAME]
)
await automation.build_automation(trigger, [], action)

# 3. setup on_enter automations after on_leave
for state in config[CONF_STATES_KEY]:

if CONF_STATE_ON_ENTER_KEY in state:
for action in state.get(CONF_STATE_ON_ENTER_KEY, []):
trigger = cg.new_Pvariable(
action[CONF_TRIGGER_ID], var, state[CONF_NAME]
)
await automation.build_automation(trigger, [], action)

await cg.register_component(var, config)

Expand Down

0 comments on commit 31aa61e

Please sign in to comment.