Skip to content

Commit

Permalink
fix: handle missing email from config
Browse files Browse the repository at this point in the history
fixes #1889
fixes #1929
  • Loading branch information
alandtse committed May 7, 2023
1 parent ed0c028 commit 358fd5c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
7 changes: 6 additions & 1 deletion custom_components/alexa_media/alarm_control_panel.py
Expand Up @@ -50,7 +50,12 @@ async def async_setup_platform(
) -> bool:
"""Set up the Alexa alarm control panel platform."""
devices = [] # type: List[AlexaAlarmControlPanel]
account = config[CONF_EMAIL] if config else discovery_info["config"][CONF_EMAIL]
if config:
account = config.get(CONF_EMAIL)
if account is None and discovery_info:
account = discovery_info.get("config", {}).get(CONF_EMAIL)
if account is None:
raise ConfigEntryNotReady
include_filter = config.get(CONF_INCLUDE_DEVICES, [])
exclude_filter = config.get(CONF_EXCLUDE_DEVICES, [])
account_dict = hass.data[DATA_ALEXAMEDIA]["accounts"][account]
Expand Down
8 changes: 7 additions & 1 deletion custom_components/alexa_media/binary_sensor.py
Expand Up @@ -14,6 +14,7 @@
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from . import (
Expand All @@ -33,7 +34,12 @@
async def async_setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Set up the Alexa sensor platform."""
devices: list[BinarySensorEntity] = []
account = config[CONF_EMAIL] if config else discovery_info["config"][CONF_EMAIL]
if config:
account = config.get(CONF_EMAIL)
if account is None and discovery_info:
account = discovery_info.get("config", {}).get(CONF_EMAIL)
if account is None:
raise ConfigEntryNotReady
account_dict = hass.data[DATA_ALEXAMEDIA]["accounts"][account]
include_filter = config.get(CONF_INCLUDE_DEVICES, [])
exclude_filter = config.get(CONF_EXCLUDE_DEVICES, [])
Expand Down
8 changes: 7 additions & 1 deletion custom_components/alexa_media/light.py
Expand Up @@ -21,6 +21,7 @@
SUPPORT_COLOR_TEMP,
LightEntity,
)
from homeassistant.exceptions import ConfigEntryNotReady

try:
from homeassistant.components.light import (
Expand Down Expand Up @@ -69,7 +70,12 @@
async def async_setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Set up the Alexa sensor platform."""
devices: list[LightEntity] = []
account = config[CONF_EMAIL] if config else discovery_info["config"][CONF_EMAIL]
if config:
account = config.get(CONF_EMAIL)
if account is None and discovery_info:
account = discovery_info.get("config", {}).get(CONF_EMAIL)
if account is None:
raise ConfigEntryNotReady
account_dict = hass.data[DATA_ALEXAMEDIA]["accounts"][account]
include_filter = config.get(CONF_INCLUDE_DEVICES, [])
exclude_filter = config.get(CONF_EXCLUDE_DEVICES, [])
Expand Down
7 changes: 6 additions & 1 deletion custom_components/alexa_media/media_player.py
Expand Up @@ -91,7 +91,12 @@
async def async_setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Set up the Alexa media player platform."""
devices = [] # type: List[AlexaClient]
account = config[CONF_EMAIL] if config else discovery_info["config"][CONF_EMAIL]
if config:
account = config.get(CONF_EMAIL)
if account is None and discovery_info:
account = discovery_info.get("config", {}).get(CONF_EMAIL)
if account is None:
raise ConfigEntryNotReady
account_dict = hass.data[DATA_ALEXAMEDIA]["accounts"][account]
entry_setup = len(account_dict["entities"]["media_player"])
alexa_client = None
Expand Down
7 changes: 6 additions & 1 deletion custom_components/alexa_media/sensor.py
Expand Up @@ -64,7 +64,12 @@ async def async_setup_platform(hass, config, add_devices_callback, discovery_inf
"Timer": TimerSensor,
"Reminder": ReminderSensor,
}
account = config[CONF_EMAIL] if config else discovery_info["config"][CONF_EMAIL]
if config:
account = config.get(CONF_EMAIL)
if account is None and discovery_info:
account = discovery_info.get("config", {}).get(CONF_EMAIL)
if account is None:
raise ConfigEntryNotReady
include_filter = config.get(CONF_INCLUDE_DEVICES, [])
exclude_filter = config.get(CONF_EXCLUDE_DEVICES, [])
account_dict = hass.data[DATA_ALEXAMEDIA]["accounts"][account]
Expand Down
7 changes: 6 additions & 1 deletion custom_components/alexa_media/switch.py
Expand Up @@ -41,7 +41,12 @@ async def async_setup_platform(hass, config, add_devices_callback, discovery_inf
("shuffle", ShuffleSwitch),
("repeat", RepeatSwitch),
]
account = config[CONF_EMAIL] if config else discovery_info["config"][CONF_EMAIL]
if config:
account = config.get(CONF_EMAIL)
if account is None and discovery_info:
account = discovery_info.get("config", {}).get(CONF_EMAIL)
if account is None:
raise ConfigEntryNotReady
include_filter = config.get(CONF_INCLUDE_DEVICES, [])
exclude_filter = config.get(CONF_EXCLUDE_DEVICES, [])
account_dict = hass.data[DATA_ALEXAMEDIA]["accounts"][account]
Expand Down

0 comments on commit 358fd5c

Please sign in to comment.