mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Move Alexa entity id generation into abstract config class (#115593)
This makes it possible to change the id schema in implementations.
This commit is contained in:
parent
269429aa0c
commit
e08301f362
@ -13,6 +13,7 @@ from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.helpers.storage import Store
|
||||
|
||||
from .const import DOMAIN
|
||||
from .entities import TRANSLATION_TABLE
|
||||
from .state_report import async_enable_proactive_mode
|
||||
|
||||
STORE_AUTHORIZED = "authorized"
|
||||
@ -101,6 +102,10 @@ class AbstractConfig(ABC):
|
||||
"""If an entity should be exposed."""
|
||||
return False
|
||||
|
||||
def generate_alexa_id(self, entity_id: str) -> str:
|
||||
"""Return the alexa ID for an entity ID."""
|
||||
return entity_id.replace(".", "#").translate(TRANSLATION_TABLE)
|
||||
|
||||
@callback
|
||||
def async_invalidate_access_token(self) -> None:
|
||||
"""Invalidate access token."""
|
||||
|
@ -259,11 +259,6 @@ class DisplayCategory:
|
||||
WEARABLE = "WEARABLE"
|
||||
|
||||
|
||||
def generate_alexa_id(entity_id: str) -> str:
|
||||
"""Return the alexa ID for an entity ID."""
|
||||
return entity_id.replace(".", "#").translate(TRANSLATION_TABLE)
|
||||
|
||||
|
||||
class AlexaEntity:
|
||||
"""An adaptation of an entity, expressed in Alexa's terms.
|
||||
|
||||
@ -298,7 +293,7 @@ class AlexaEntity:
|
||||
|
||||
def alexa_id(self) -> str:
|
||||
"""Return the Alexa API entity id."""
|
||||
return generate_alexa_id(self.entity.entity_id)
|
||||
return self.config.generate_alexa_id(self.entity.entity_id)
|
||||
|
||||
def display_categories(self) -> list[str] | None:
|
||||
"""Return a list of display categories."""
|
||||
|
@ -41,7 +41,7 @@ from .const import (
|
||||
Cause,
|
||||
)
|
||||
from .diagnostics import async_redact_auth_data
|
||||
from .entities import ENTITY_ADAPTERS, AlexaEntity, generate_alexa_id
|
||||
from .entities import ENTITY_ADAPTERS, AlexaEntity
|
||||
from .errors import AlexaInvalidEndpointError, NoTokenAvailable, RequireRelink
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -492,7 +492,7 @@ async def async_send_delete_message(
|
||||
if domain not in ENTITY_ADAPTERS:
|
||||
continue
|
||||
|
||||
endpoints.append({"endpointId": generate_alexa_id(entity_id)})
|
||||
endpoints.append({"endpointId": config.generate_alexa_id(entity_id)})
|
||||
|
||||
payload: dict[str, Any] = {
|
||||
"endpoints": endpoints,
|
||||
|
Loading…
x
Reference in New Issue
Block a user