mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +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 homeassistant.helpers.storage import Store
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .entities import TRANSLATION_TABLE
|
||||||
from .state_report import async_enable_proactive_mode
|
from .state_report import async_enable_proactive_mode
|
||||||
|
|
||||||
STORE_AUTHORIZED = "authorized"
|
STORE_AUTHORIZED = "authorized"
|
||||||
@ -101,6 +102,10 @@ class AbstractConfig(ABC):
|
|||||||
"""If an entity should be exposed."""
|
"""If an entity should be exposed."""
|
||||||
return False
|
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
|
@callback
|
||||||
def async_invalidate_access_token(self) -> None:
|
def async_invalidate_access_token(self) -> None:
|
||||||
"""Invalidate access token."""
|
"""Invalidate access token."""
|
||||||
|
@ -259,11 +259,6 @@ class DisplayCategory:
|
|||||||
WEARABLE = "WEARABLE"
|
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:
|
class AlexaEntity:
|
||||||
"""An adaptation of an entity, expressed in Alexa's terms.
|
"""An adaptation of an entity, expressed in Alexa's terms.
|
||||||
|
|
||||||
@ -298,7 +293,7 @@ class AlexaEntity:
|
|||||||
|
|
||||||
def alexa_id(self) -> str:
|
def alexa_id(self) -> str:
|
||||||
"""Return the Alexa API entity id."""
|
"""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:
|
def display_categories(self) -> list[str] | None:
|
||||||
"""Return a list of display categories."""
|
"""Return a list of display categories."""
|
||||||
|
@ -41,7 +41,7 @@ from .const import (
|
|||||||
Cause,
|
Cause,
|
||||||
)
|
)
|
||||||
from .diagnostics import async_redact_auth_data
|
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
|
from .errors import AlexaInvalidEndpointError, NoTokenAvailable, RequireRelink
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -492,7 +492,7 @@ async def async_send_delete_message(
|
|||||||
if domain not in ENTITY_ADAPTERS:
|
if domain not in ENTITY_ADAPTERS:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
endpoints.append({"endpointId": generate_alexa_id(entity_id)})
|
endpoints.append({"endpointId": config.generate_alexa_id(entity_id)})
|
||||||
|
|
||||||
payload: dict[str, Any] = {
|
payload: dict[str, Any] = {
|
||||||
"endpoints": endpoints,
|
"endpoints": endpoints,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user