rgc99 / irrigation_unlimited

♒Irrigation controller for Home Assistant
MIT License
332 stars 49 forks source link

Occasional startup error when reloading with `rename_entities: true` #184

Open jamesshannon opened 2 months ago

jamesshannon commented 2 months ago

Describe the bug I'm using rename_entities. About 20% of the time that I start up (via reloading the YAML) I get an error that prevents the startup and makes the entities unavailable. Reloading a second time (without making any changes) fixes the issue.

I'm not doing anything edge-casey with the entity names. I set the entity IDs before my first-ever startup of IU and haven't renamed them.

To Reproduce Steps to reproduce the behavior:

  1. Create a config with rename_entities. (See my config file below.)
  2. Startup IU
  3. Reload the IU YAML ~10 times, looking at the logs / entities after each start.
  4. On one of the reloads, you're likely to get an error log entry and entities will be Unavailable in dev tools.
  5. Reload again. IU should start up normally. No error log entries.

Expected behavior Should start up consistently each time.

Additional Info I note that the log message reference c1_z1 and c1_m, which seems like the non-renamed entity names. I don't know where these IDs would have come from.

I checked for entities named c1 (by filtering in Dev Tools Current Entities screen for [c1_]) and there are no entities that are returned.

Config YAML:

controllers:
  - name: "Front Yard Flowers SWV"
    controller_id: frontyard_flowers_swv
    zones:
      - name: "Front Yard Flowers"
        zone_id: flower_pots
        entity_id: "switch.flowers_swv_switch"
        schedules:
          - time:
              sun: "sunrise"
            duration: "00:03:30"
          - time: "15:00"
            duration: "00:03:00"

rename_entities: true

Irrigation Unlimited log file I'm currently logging level INFO, so there are no debug logs from successful startup.

2024-08-30 10:51:53.190 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform irrigation_unlimited does not generate unique IDs. ID c1_m is already used by binary_sensor.irrigation_unlimited_frontyard_flowers_swv - ignoring binary_sensor.irrigation_unlimited_frontyard_flowers_swv
2024-08-30 10:51:53.190 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform irrigation_unlimited does not generate unique IDs. ID c1_z1 is already used by binary_sensor.irrigation_unlimited_frontyard_flowers_swv_flower_pots - ignoring binary_sensor.irrigation_unlimited_frontyard_flowers_swv_flower_pots
rgc99 commented 2 months ago

It appears the old entities haven't finished deleting before the new ones are created. By swapping the order it seems to fix this.