diff --git a/homeassistant/components/alexa/entities.py b/homeassistant/components/alexa/entities.py index e70da218e47..bd68e4ad926 100644 --- a/homeassistant/components/alexa/entities.py +++ b/homeassistant/components/alexa/entities.py @@ -201,6 +201,11 @@ 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. @@ -232,7 +237,7 @@ class AlexaEntity: def alexa_id(self): """Return the Alexa API entity id.""" - return self.entity.entity_id.replace(".", "#").translate(TRANSLATION_TABLE) + return generate_alexa_id(self.entity.entity_id) def display_categories(self): """Return a list of display categories.""" diff --git a/homeassistant/components/alexa/state_report.py b/homeassistant/components/alexa/state_report.py index 6c9b9ac5180..a61dfc02d10 100644 --- a/homeassistant/components/alexa/state_report.py +++ b/homeassistant/components/alexa/state_report.py @@ -10,7 +10,7 @@ from homeassistant.const import MATCH_ALL, STATE_ON import homeassistant.util.dt as dt_util from .const import API_CHANGE, Cause -from .entities import ENTITY_ADAPTERS +from .entities import ENTITY_ADAPTERS, generate_alexa_id from .messages import AlexaResponse _LOGGER = logging.getLogger(__name__) @@ -181,8 +181,7 @@ async def async_send_delete_message(hass, config, entity_ids): if domain not in ENTITY_ADAPTERS: continue - alexa_entity = ENTITY_ADAPTERS[domain](hass, config, hass.states.get(entity_id)) - endpoints.append({"endpointId": alexa_entity.alexa_id()}) + endpoints.append({"endpointId": generate_alexa_id(entity_id)}) payload = {"endpoints": endpoints, "scope": {"type": "BearerToken", "token": token}}