-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add catch for HomeAssistantError when adding entities
- Loading branch information
Showing
4 changed files
with
42 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
Helper functions for Alexa Media Player. | ||
For more details about this platform, please refer to the documentation at | ||
https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639 | ||
""" | ||
|
||
import logging | ||
from typing import List | ||
from homeassistant.exceptions import HomeAssistantError | ||
from homeassistant.helpers.entity_component import EntityComponent | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def add_devices(devices: List[EntityComponent], | ||
add_devices_callback: callable) -> bool: | ||
"""Add devices using add_devices_callback.""" | ||
_LOGGER.debug("Adding %s", devices) | ||
if devices: | ||
try: | ||
await add_devices_callback(devices, True) | ||
return True | ||
except HomeAssistantError as exception_: | ||
message = exception_.message # type: str | ||
if message.startswith("Entity id already exists"): | ||
_LOGGER.debug("Device already added: %s", | ||
message) | ||
else: | ||
_LOGGER.debug("Unable to add devices: %s : %s", | ||
devices, | ||
message) | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters