diff --git a/custom_components/alexa_media/alarm_control_panel.py b/custom_components/alexa_media/alarm_control_panel.py index a1b0262e..49e5d4bc 100644 --- a/custom_components/alexa_media/alarm_control_panel.py +++ b/custom_components/alexa_media/alarm_control_panel.py @@ -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] diff --git a/custom_components/alexa_media/binary_sensor.py b/custom_components/alexa_media/binary_sensor.py index b9cca0b3..17030332 100644 --- a/custom_components/alexa_media/binary_sensor.py +++ b/custom_components/alexa_media/binary_sensor.py @@ -14,6 +14,7 @@ BinarySensorDeviceClass, BinarySensorEntity, ) +from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import ( @@ -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, []) diff --git a/custom_components/alexa_media/light.py b/custom_components/alexa_media/light.py index d996a5a6..8686148e 100644 --- a/custom_components/alexa_media/light.py +++ b/custom_components/alexa_media/light.py @@ -21,6 +21,7 @@ SUPPORT_COLOR_TEMP, LightEntity, ) +from homeassistant.exceptions import ConfigEntryNotReady try: from homeassistant.components.light import ( @@ -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, []) diff --git a/custom_components/alexa_media/media_player.py b/custom_components/alexa_media/media_player.py index ebaf40ba..8ad9fbec 100644 --- a/custom_components/alexa_media/media_player.py +++ b/custom_components/alexa_media/media_player.py @@ -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 diff --git a/custom_components/alexa_media/sensor.py b/custom_components/alexa_media/sensor.py index f83b3c68..f331ee65 100644 --- a/custom_components/alexa_media/sensor.py +++ b/custom_components/alexa_media/sensor.py @@ -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] diff --git a/custom_components/alexa_media/switch.py b/custom_components/alexa_media/switch.py index ba62d7cd..a514a51a 100644 --- a/custom_components/alexa_media/switch.py +++ b/custom_components/alexa_media/switch.py @@ -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]