mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Stabilize alexa discovery (#108787)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user