Stabilize alexa discovery (#108787)

This commit is contained in:
Jan Bouwhuis
2024-01-24 18:56:21 +01:00
committed by GitHub
parent 5467fe8ff1
commit a90d8b6a0c
3 changed files with 126 additions and 49 deletions

View File

@@ -380,12 +380,17 @@ def async_get_entities(
if state.domain not in ENTITY_ADAPTERS:
continue
alexa_entity = ENTITY_ADAPTERS[state.domain](hass, config, state)
if not list(alexa_entity.interfaces()):
continue
entities.append(alexa_entity)
try:
alexa_entity = ENTITY_ADAPTERS[state.domain](hass, config, state)
interfaces = list(alexa_entity.interfaces())
except Exception as exc: # pylint: disable=broad-except
_LOGGER.exception(
"Unable to serialize %s for discovery: %s", state.entity_id, exc
)
else:
if not interfaces:
continue
entities.append(alexa_entity)
return entities
@@ -406,13 +411,11 @@ class GenericCapabilities(AlexaEntity):
return [DisplayCategory.OTHER]
def interfaces(self) -> list[AlexaCapability]:
def interfaces(self) -> Generator[AlexaCapability, None, None]:
"""Yield the supported interfaces."""
return [
AlexaPowerController(self.entity),
AlexaEndpointHealth(self.hass, self.entity),
Alexa(self.entity),
]
yield AlexaPowerController(self.entity)
yield AlexaEndpointHealth(self.hass, self.entity)
yield Alexa(self.entity)
@ENTITY_ADAPTERS.register(input_boolean.DOMAIN)
@@ -431,14 +434,12 @@ class SwitchCapabilities(AlexaEntity):
return [DisplayCategory.SWITCH]
def interfaces(self) -> list[AlexaCapability]:
def interfaces(self) -> Generator[AlexaCapability, None, None]:
"""Yield the supported interfaces."""
return [
AlexaPowerController(self.entity),
AlexaContactSensor(self.hass, self.entity),
AlexaEndpointHealth(self.hass, self.entity),
Alexa(self.entity),
]
yield AlexaPowerController(self.entity)
yield AlexaContactSensor(self.hass, self.entity)
yield AlexaEndpointHealth(self.hass, self.entity)
yield Alexa(self.entity)
@ENTITY_ADAPTERS.register(button.DOMAIN)
@@ -450,14 +451,12 @@ class ButtonCapabilities(AlexaEntity):
"""Return the display categories for this entity."""
return [DisplayCategory.ACTIVITY_TRIGGER]
def interfaces(self) -> list[AlexaCapability]:
def interfaces(self) -> Generator[AlexaCapability, None, None]:
"""Yield the supported interfaces."""
return [
AlexaSceneController(self.entity, supports_deactivation=False),
AlexaEventDetectionSensor(self.hass, self.entity),
AlexaEndpointHealth(self.hass, self.entity),
Alexa(self.entity),
]
yield AlexaSceneController(self.entity, supports_deactivation=False)
yield AlexaEventDetectionSensor(self.hass, self.entity)
yield AlexaEndpointHealth(self.hass, self.entity)
yield Alexa(self.entity)
@ENTITY_ADAPTERS.register(climate.DOMAIN)
@@ -676,13 +675,11 @@ class LockCapabilities(AlexaEntity):
"""Return the display categories for this entity."""
return [DisplayCategory.SMARTLOCK]
def interfaces(self) -> list[AlexaCapability]:
def interfaces(self) -> Generator[AlexaCapability, None, None]:
"""Yield the supported interfaces."""
return [
AlexaLockController(self.entity),
AlexaEndpointHealth(self.hass, self.entity),
Alexa(self.entity),
]
yield AlexaLockController(self.entity)
yield AlexaEndpointHealth(self.hass, self.entity)
yield Alexa(self.entity)
@ENTITY_ADAPTERS.register(media_player.const.DOMAIN)
@@ -767,12 +764,10 @@ class SceneCapabilities(AlexaEntity):
"""Return the display categories for this entity."""
return [DisplayCategory.SCENE_TRIGGER]
def interfaces(self) -> list[AlexaCapability]:
def interfaces(self) -> Generator[AlexaCapability, None, None]:
"""Yield the supported interfaces."""
return [
AlexaSceneController(self.entity, supports_deactivation=False),
Alexa(self.entity),
]
yield AlexaSceneController(self.entity, supports_deactivation=False)
yield Alexa(self.entity)
@ENTITY_ADAPTERS.register(script.DOMAIN)
@@ -783,12 +778,10 @@ class ScriptCapabilities(AlexaEntity):
"""Return the display categories for this entity."""
return [DisplayCategory.ACTIVITY_TRIGGER]
def interfaces(self) -> list[AlexaCapability]:
def interfaces(self) -> Generator[AlexaCapability, None, None]:
"""Yield the supported interfaces."""
return [
AlexaSceneController(self.entity, supports_deactivation=True),
Alexa(self.entity),
]
yield AlexaSceneController(self.entity, supports_deactivation=True)
yield Alexa(self.entity)
@ENTITY_ADAPTERS.register(sensor.DOMAIN)