Olen / homeassistant-plant

Alternative Plant component of home assistant
352 stars 23 forks source link

Renaming Plant Device doesn't change Source for DLI/mol #64

Open trankillity opened 1 year ago

trankillity commented 1 year ago

If you rename a plant device and accept the rename of the entities associated with it, the source attribute of the DLI/mol sensors does not update - resulting in broken sensors.

Running the service to reassign the sensors also doesn't appear to work for these entity types as I believe that's updating the external_sensor attribute for other sensors.

The DLI sensor
The DLI sensor
The mol sensors
The mol sensors that should be attached
Knobiwahn commented 1 year ago

Same here

Olen commented 1 year ago

I'll look into this. I am not sure the integration gets any notification when the entities changes, but I might be able to run a periodic job to make sure the surce for the DLI is correct.

danceoversun commented 1 year ago

Same here

hermanops commented 1 year ago

me too

Olen commented 1 year ago

Me-toos does not help. You may subscribe to the issue, or even better - create a PR.

ScottG489 commented 5 months ago

I was curious so I looked up how to do this. I think rather than storing the entity ID as provided by the user, you could look up the entity by entity_id and then get and store unique information about it to look up later. Here's a quick example that goes full circle:

er = entity_registry.async_get(hass)
entity = er.async_get('sensor.foobar')
entity_id = ent_reg.async_get_entity_id(entity.domain, entity.platform, entity.unique_id)

So you'd want to look up the entity object via the entity_id supplied by the user and then store domain, platform, and unique_id of the entity. Then when updating the sensor you'd use those 3 values to get the entity_id and then look up the state using that.