JaccoR / hass-entso-e

Integration for Home Assistant to fetch day ahead energy prices from European countries via ENTSO-e Transparency Platform
159 stars 25 forks source link

Original entity id's were based on the entity name #49

Closed sfstar closed 1 year ago

sfstar commented 1 year ago

The 0.1.0 release changes the entity id from it's description.name to the description.key value. Thereby, causing issues for keeping the original entity names (and history) In order to achieve (what i believe you wanted to achieve) you should set _attr_unique_id to the original description.key value and self.entity_id to description.name. Since before my PR (for supporting multiple integrations) the entity_id property was not set by the integration. Thereby, causing HA to infer the description.name value as the entity id.

Anybody upgrading now will not have working dashboards / history afterwards due to the key property != the name property.

sfstar commented 1 year ago

take for example the following description: EntsoeEntityDescription( key="current_price", name="Current electricity market price", native_unit_of_measurement=f"{CURRENCY_EURO}/{ENERGY_KILO_WATT_HOUR}", value_fn=lambda data: data["current_price"], state_class="measurement" ),

this will currently cause the entity_id used by end-user to be either: sensor.current_price or sensor.<name>_current_price While originally it was: sensor.current_electricity_market_price

By approving #50 you would change this back to: sensor.current_electricity_market_price or sensor.<name>_current_electricity_market_price

JaccoR commented 1 year ago

You're right. I merged it now. Thanks!

Reason for using key in there was because the ID name gave an error when using a value with spaces in there. But this works!

sfstar commented 1 year ago

Great, thank you for the quick review. Regarding the entity naming, the entity helper file in core seems to have an generate entity_id function that converts and checks the entity name to a pre-defined format (regex). You could consider using this function when determining the entity_id value (would make it a safer integration if input is checked/automatically converted to ha standards.