Handle Alexa entity removed (#39569)

This commit is contained in:
Paulus Schoutsen 2020-09-02 11:30:37 +02:00 committed by GitHub
parent 4486251382
commit d5bcafaefd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -201,6 +201,11 @@ 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.
@ -232,7 +237,7 @@ class AlexaEntity:
def alexa_id(self): def alexa_id(self):
"""Return the Alexa API entity id.""" """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): def display_categories(self):
"""Return a list of display categories.""" """Return a list of display categories."""

View File

@ -10,7 +10,7 @@ from homeassistant.const import MATCH_ALL, STATE_ON
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from .const import API_CHANGE, Cause from .const import API_CHANGE, Cause
from .entities import ENTITY_ADAPTERS from .entities import ENTITY_ADAPTERS, generate_alexa_id
from .messages import AlexaResponse from .messages import AlexaResponse
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -181,8 +181,7 @@ async def async_send_delete_message(hass, config, entity_ids):
if domain not in ENTITY_ADAPTERS: if domain not in ENTITY_ADAPTERS:
continue continue
alexa_entity = ENTITY_ADAPTERS[domain](hass, config, hass.states.get(entity_id)) endpoints.append({"endpointId": generate_alexa_id(entity_id)})
endpoints.append({"endpointId": alexa_entity.alexa_id()})
payload = {"endpoints": endpoints, "scope": {"type": "BearerToken", "token": token}} payload = {"endpoints": endpoints, "scope": {"type": "BearerToken", "token": token}}