Update YAML style guide to new syntax (#2350)

This commit is contained in:
Bram Kragten 2024-10-02 14:53:55 +02:00 committed by GitHub
parent 7256c34950
commit 8757dcb948
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -227,14 +227,14 @@ list `[]` by default.
```yaml ```yaml
# Good # Good
- alias: "Test" - alias: "Test"
trigger: triggers:
- platform: state - trigger: state
entity_id: binary_sensor.motion entity_id: binary_sensor.motion
# Bad # Bad
- alias: "Test" - alias: "Test"
trigger: triggers:
- platform: state - trigger: state
entity_id: binary_sensor.motion entity_id: binary_sensor.motion
condition: [] condition: []
``` ```
@ -251,8 +251,8 @@ as is makes our examples more readable:
- Area IDs - Area IDs
- Platform types (e.g., `light`, `switch`) - Platform types (e.g., `light`, `switch`)
- Condition types (e.g., `numeric_state`, `state`) - Condition types (e.g., `numeric_state`, `state`)
- Trigger platforms (e.g., `state`, `time`) - Trigger types (e.g., `state`, `time`)
- Service action names (e.g., `light.turn_on`) - Action names (e.g., `light.turn_on`)
- Device classes (e.g., `problem`, `motion`) - Device classes (e.g., `problem`, `motion`)
- Event names - Event names
- Values that accept a limited set of possible, hardcoded values. - Values that accept a limited set of possible, hardcoded values.
@ -260,11 +260,11 @@ as is makes our examples more readable:
```yaml ```yaml
# Good # Good
action: actions:
- service: notify.frenck - action: notify.frenck
data: data:
message: "Hi there!" message: "Hi there!"
- service: light.turn_on - action: light.turn_on
target: target:
entity_id: light.office_desk entity_id: light.office_desk
area_id: living_room area_id: living_room
@ -272,8 +272,8 @@ action:
transition: 10 transition: 10
# Bad # Bad
action: actions:
- service: "notify.frenck" - action: "notify.frenck"
data: data:
message: Hi there! message: Hi there!
``` ```
@ -293,24 +293,24 @@ most flexible of the options available and is the one that should be used.
```yaml ```yaml
# Good # Good
action: actions:
- service: light.turn_on - action: light.turn_on
target: target:
entity_id: light.living_room entity_id: light.living_room
- service: light.turn_on - action: light.turn_on
target: target:
area_id: light.living_room area_id: light.living_room
- service: light.turn_on - action: light.turn_on
target: target:
area_id: living_room area_id: living_room
entity_id: light.office_desk entity_id: light.office_desk
device_id: 21349287492398472398 device_id: 21349287492398472398
# Bad # Bad
action: actions:
- service: light.turn_on - action: light.turn_on
entity_id: light.living_room entity_id: light.living_room
- service: light.turn_on - action: light.turn_on
data: data:
entity_id: light.living_room entity_id: light.living_room
``` ```
@ -357,14 +357,14 @@ copy and paste a single item into your own code.
```yaml ```yaml
# Good # Good
action: actions:
- service: light.turn_on - action: light.turn_on
target: target:
entity_id: light.living_room entity_id: light.living_room
# Bad # Bad
action: actions:
service: light.turn_on action: light.turn_on
target: target:
entity_id: light.living_room entity_id: light.living_room
``` ```
@ -381,14 +381,14 @@ Avoiding templates in general removes the need of additional escaping.
```yaml ```yaml
# Good # Good
condition: conditions:
- condition: numeric_state - condition: numeric_state
entity_id: sun.sun entity_id: sun.sun
attribute: elevation attribute: elevation
below: 4 below: 4
# Bad # Bad
condition: conditions:
- condition: template - condition: template
value_template: "{{ state_attr('sun.sun', 'elevation') < 4 }}" value_template: "{{ state_attr('sun.sun', 'elevation') < 4 }}"
``` ```
@ -434,10 +434,10 @@ cleaner syntax.
```yaml ```yaml
# Good # Good
condition: "{{ some_value == some_other_value }}" conditions: "{{ some_value == some_other_value }}"
# Bad # Bad
condition: conditions:
- condition: template - condition: template
value_template: "{{ some_value == some_other_value }}" value_template: "{{ some_value == some_other_value }}"
``` ```
@ -449,12 +449,12 @@ readability unclear, the use of additional parentheses is recommended.
```yaml ```yaml
# Good # Good
condition: conditions:
- "{{ some_value | float }}" - "{{ some_value | float }}"
- "{{ some_value == (some_other_value | some_filter) }}" - "{{ some_value == (some_other_value | some_filter) }}"
# Bad # Bad
condition: conditions:
- "{{ some_value == some_other_value|some_filter }}" - "{{ some_value == some_other_value|some_filter }}"
- "{{ some_value == (some_other_value|some_filter) }}" - "{{ some_value == (some_other_value|some_filter) }}"
``` ```