Skip to content

Commit

Permalink
Manual trigger entity fix name influence entity_id (home-assistant#97398
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gjohansson-ST authored Jul 30, 2023
1 parent 2b4387f commit 1f11ce6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion homeassistant/components/scrape/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions homeassistant/components/sql/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/helpers/template_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1f11ce6

Please sign in to comment.