dummylabs / thewatchman

Home Assistant custom integration to keep track of missing entities and actions in your config files
MIT License
481 stars 20 forks source link

Entities in templates not picked-up #73

Closed andriej closed 1 year ago

andriej commented 1 year ago

Watchman seems to not pick-up entities that are used in templates/automations like:

states.sensor.entity_id.state

Maybe regex with states.* could help.

Anyway, thanks for awesome integration!

dummylabs commented 1 year ago

Hey @andriej, Watchman 0.6 should capture entities referenced by states.*, it was fixed in #32. Could you please add more details:

andriej commented 1 year ago

I did a lot of fixing since that time and may not have the code anymore, but some more examples:

  1. watchman reports 'camera.split' missing:

    - variables:
      file: /media/snapshots/{{ now().strftime('%Y_%m') }}/{{ camera.split('.')[1]
        }}_{{ now().strftime('%d_%H%M%S') }}.jpg
    - service: camera.snapshot
    data:
      entity_id: camera.{{ camera.split('.')[1] }}
      filename: '{{ file }}'
  2. same for esphome:

    | switch.is_on                   | missing | esphome/domofon.yaml:73,100                                  |
    | switch.template                | missing | esphome/domofon.yaml:127,131                                 |

    example of line:

    on_press:
      then:
        if:
          condition:
            switch.is_on: auto_open
          then:
            - delay: 1s
            - switch.turn_on: unlock

    also other custom components are picked up:

    | camera.generic_stream          | missing | custom_components/webrtc/services.yaml:20,66                 |
    | media_player.mibox4            | missing | custom_components/webrtc/services.yaml:51                    |
    | camera.living_room_camera      | missing | custom_components/yi_hack/services.yaml:9,47,71              |

maybe it's worth adding 'ignore' on esphome and custom_components or just leave it like that :-) I wanted to have clean report tho so make sure no mistakes are here after those few years with HA.

I do not have the faulty code anymore, but will try to reproduce when have some more time

dummylabs commented 1 year ago

Thanks for the feedback. For ESPHome folder it is recommended to add it to ignored folders list in Watchman configuration. May be a good idea to add it as default to Watchman configuration later. For various complex templates - it seems like quite a challenge to parse them with a regular expression, the only way so far is to put these false positives to the ignored entities list. Feel free to reopen the ticket if you manage to reproduce a bug with states.* entities.