#Sensor and/or helper YAML definition: list vs dict - why?

1 messages · Page 1 of 1 (latest)

solid marsh
#

I am trying to learn HA in more details, hopefully being able to contribute to the source code one day. Now spending more time to learn YAML for the configuration purposes.

What I came across is that it seems HA uses 2 different mods of defining some types. For example, input_number helper is defined as set of dictionaries

# Example configuration.yaml entry
input_number:
  slider1: //One slide
    name: Slider
    initial: 30
    min: -20
    max: 35
    step: 1
  box1: //Second slider
    name: Numeric Input Box
    initial: 30
    min: -20
    max: 35
    step: 1
    mode: box

While for example a new min_max sensor is defined as an array of sensors:

# Example configuration.yaml entry
sensor:
  //Defined as list entry, without key
  - platform: min_max //This is sensor 1
    entity_ids:
      - sensor.kitchen_temperature
      - sensor.living_room_temperature
      - sensor.office_temperature

Therefore why isn't input_number also defined as:

input_number:
  // Slider 1
  - name: Slider
    initial: 30
    min: -20
    max: 35
    step: 1
  // Number 2
  - name: Numeric Input Box
    initial: 30
    min: -20
    max: 35
    step: 1
    mode: box

Or sensorlike this:

# Example configuration.yaml entry
sensor:
  //Defined as list entry, without key
  sensor1:
    platform: min_max //This is sensor 1
    entity_ids:
      - sensor.kitchen_temperature
      - sensor.living_room_temperature
      - sensor.office_temperature

Why are there 2 different ways of defining objects?

hollow kite
#

The form that uses platform: xxx is generally going away in favor of the using the integration as the key, as you see with input_boolean

#

Then, in general the individual entities are moving in the direction of being defined in a list rather than a set of dicts. The only reason for the differing styles is that the best practice has changed over time

solid marsh
#

Understand it is a matter of evalution. I see the same in the scripts too.

The new direction to me is less convenient because in the past you could set all the sensors at the same place in yaml, if they are linked together, now you have to define them at different locations -

hollow kite
#

I would argue that configuring a bunch of unrelated sensors together is less intuitive than configuring the entities for an integration together, but it's a matter of preference