Update Alexa discovery description (#26933)

* Update Alexa discovery description

* Update description

* Fix test

* Filter special chars
This commit is contained in:
Bram Kragten 2019-09-27 21:51:46 +02:00 committed by GitHub
parent eeffd090a3
commit 80bc15e24b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 13 deletions

View file

@ -52,6 +52,8 @@ from .capabilities import (
ENTITY_ADAPTERS = Registry()
TRANSLATION_TABLE = dict.fromkeys(map(ord, r"}{\/|\"()[]+~!><*%"), None)
class DisplayCategory:
"""Possible display categories for Discovery response.
@ -134,15 +136,18 @@ class AlexaEntity:
def friendly_name(self):
"""Return the Alexa API friendly name."""
return self.entity_conf.get(CONF_NAME, self.entity.name)
return self.entity_conf.get(CONF_NAME, self.entity.name).translate(
TRANSLATION_TABLE
)
def description(self):
"""Return the Alexa API description."""
return self.entity_conf.get(CONF_DESCRIPTION, self.entity.entity_id)
description = self.entity_conf.get(CONF_DESCRIPTION) or self.entity_id
return f"{description} via Home Assistant".translate(TRANSLATION_TABLE)
def alexa_id(self):
"""Return the Alexa API entity id."""
return self.entity.entity_id.replace(".", "#")
return self.entity.entity_id.replace(".", "#").translate(TRANSLATION_TABLE)
def display_categories(self):
"""Return a list of display categories."""
@ -389,10 +394,11 @@ class SceneCapabilities(AlexaEntity):
"""Class to represent Scene capabilities."""
def description(self):
"""Return the description of the entity."""
# Required description as per Amazon Scene docs
scene_fmt = "{} (Scene connected via Home Assistant)"
return scene_fmt.format(AlexaEntity.description(self))
"""Return the Alexa API description."""
description = AlexaEntity.description(self)
if "scene" not in description.casefold():
return f"{description} (Scene)"
return description
def default_display_categories(self):
"""Return the display categories for this entity."""