From 1f11ce63fcc84988cb934ffe524185b95ae20993 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 30 Jul 2023 18:47:34 +0200 Subject: [PATCH] Manual trigger entity fix name influence entity_id (#97398) --- homeassistant/components/scrape/sensor.py | 1 - homeassistant/components/sql/sensor.py | 9 ++++----- homeassistant/helpers/template_entity.py | 5 +++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/scrape/sensor.py b/homeassistant/components/scrape/sensor.py index a68083856f72b..cc4cd269606cf 100644 --- a/homeassistant/components/scrape/sensor.py +++ b/homeassistant/components/scrape/sensor.py @@ -157,7 +157,6 @@ def __init__( """Initialize a web scrape sensor.""" CoordinatorEntity.__init__(self, coordinator) ManualTriggerEntity.__init__(self, hass, trigger_entity_config) - self._attr_name = trigger_entity_config[CONF_NAME].template self._attr_native_unit_of_measurement = unit_of_measurement self._attr_state_class = state_class self._select = select diff --git a/homeassistant/components/sql/sensor.py b/homeassistant/components/sql/sensor.py index 0c8e90b8895a1..aecc34d70091e 100644 --- a/homeassistant/components/sql/sensor.py +++ b/homeassistant/components/sql/sensor.py @@ -344,16 +344,15 @@ def __init__( self._attr_extra_state_attributes = {} self._use_database_executor = use_database_executor self._lambda_stmt = _generate_lambda_stmt(query) - self._attr_name = ( - None if not yaml else trigger_entity_config[CONF_NAME].template - ) - self._attr_has_entity_name = not yaml + if not yaml: + self._attr_name = None + self._attr_has_entity_name = True if not yaml and trigger_entity_config.get(CONF_UNIQUE_ID): self._attr_device_info = DeviceInfo( entry_type=DeviceEntryType.SERVICE, identifiers={(DOMAIN, trigger_entity_config[CONF_UNIQUE_ID])}, manufacturer="SQL", - name=trigger_entity_config[CONF_NAME].template, + name=self.name, ) async def async_added_to_hass(self) -> None: diff --git a/homeassistant/helpers/template_entity.py b/homeassistant/helpers/template_entity.py index b7be7c2c9a628..2e5cebf8571aa 100644 --- a/homeassistant/helpers/template_entity.py +++ b/homeassistant/helpers/template_entity.py @@ -626,6 +626,11 @@ def __init__( ) -> None: """Initialize the entity.""" TriggerBaseEntity.__init__(self, hass, config) + # Need initial rendering on `name` as it influence the `entity_id` + self._rendered[CONF_NAME] = config[CONF_NAME].async_render( + {}, + parse_result=CONF_NAME in self._parse_result, + ) @callback def _process_manual_data(self, value: Any | None = None) -> None: