Skip to content

Commit

Permalink
testing 8
Browse files Browse the repository at this point in the history
  • Loading branch information
asucrews authored Jul 3, 2024
1 parent 9329710 commit f9b8ddd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ action:
entity_id: !input left_open_timer_helper

mode: single
max_exceeded: silent
max_exceeded: silent
20 changes: 13 additions & 7 deletions scripts/yaml_to_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import sys
import os

# Define a constructor to handle the '!input' tag
def input_constructor(loader, node):
return node.value
# Define a custom constructor to handle unknown tags
def construct_ignore(loader, node):
return None

# Add the constructor to the SafeLoader
yaml.SafeLoader.add_constructor('!input', input_constructor)
# Register the custom constructor for the '!input' tag
yaml.add_constructor('!input', construct_ignore, Loader=yaml.SafeLoader)

def yaml_to_markdown(yaml_file, markdown_file):
with open(yaml_file, 'r') as f:
Expand Down Expand Up @@ -45,13 +45,19 @@ def yaml_to_markdown(yaml_file, markdown_file):

f.write("\n## Triggers\n")
for trigger in data['trigger']:
f.write(f"- **{trigger['id']}**: Triggered when the {trigger['platform']} changes from `{trigger['from']}` to `{trigger['to']}`.\n")
trigger_id = trigger.get('id', 'Unknown')
platform = trigger.get('platform', 'Unknown')
from_state = trigger.get('from', 'Unknown')
to_state = trigger.get('to', 'Unknown')
f.write(f"- **{trigger_id}**: Triggered when the {platform} changes from `{from_state}` to `{to_state}`.\n")

f.write("\n## Actions\n")
for action in data['action']:
f.write(f"### {action['choose']['conditions'][0]['id']}\n")
for step in action['sequence']:
f.write(f"- **{step['service']}**: {step['data']}\n")
service = step.get('service', 'Unknown service')
data = step.get('data', 'No data')
f.write(f"- **{service}**: {data}\n")

f.write("\n## Mode\n")
f.write(f"- **Mode**: {data['mode']}\n")
Expand Down

0 comments on commit f9b8ddd

Please sign in to comment.