keesschollaart81 / vscode-home-assistant

Visual Studio Code Extension for Home Assistant. ⭐ if you think this is cool!
530 stars 112 forks source link

Incorrect type error when `!include_dir_named` is used in `configuration.yaml` #2801

Open ChrisBaker97 opened 11 months ago

ChrisBaker97 commented 11 months ago

Parsing configuration.yaml produces errors when template entities are included using !include_dir_named:

Incorrect type. Expected "object".

All works fine, and the configuration passes Home Assistant's YAML validation.

Please include the related YAML code:

sensor:
  - platform: template
    sensors: !include_dir_named template_sensors/

binary_sensor:
  - platform: template
    sensors: !include_dir_named template_binary_sensors/

switch:
  - platform: template
    switches: !include_dir_named template_switches/

A representative file, template_sensors/illumination.yaml:

friendly_name: "Illumination"
unique_id: sensor.illumination
attribute_templates:
  angle: "{{ state_attr('sun.sun','elevation') | float(0.0) }}"
  effective_angle: "{{ state_attr('sun.sun','elevation')|float(0.0) - states('input_number.sun_angle_bias')|float(0.0) }}"
value_template: >-
  {% set elevation = state_attr('sun.sun','elevation') | float(0.0) %}
  {% if elevation > 0.0 %} Day
  {% elif elevation > -6.0 %} Civil Twilight
  {% elif elevation > -12.0 %} Nautical Twilight
  {% elif elevation > -18.0 %} Astronomical Twilight
  {% else %} Night
  {% endif %}
icon_template: >-
  {% set elevation = state_attr('sun.sun','elevation') | float(0.0) %}
  {% if elevation > 0.0 %} mdi:weather-sunny
  {% elif elevation > -18.0 %} mdi:weather-sunset
  {% else %} mdi:weather-night
  {% endif %}

Extension runs in:

I'm running VS Code on:

I'm accessing my files:

frenck commented 11 months ago

Yup this may happen and is actually ok to ignore.

Essentially, this statement can be put everywhere. The extension has some logical places to shallow those, but setting them on every single parameter would not make sense either. So, this is a balance game without a solution at this point.

../Frenck

ChrisBaker97 commented 11 months ago

I suppose there's no easy way to borrow HA's code to actually assemble and parse those as if they were part of the configuration.yaml file itself before linting it?

frenck commented 11 months ago

nope