Skip to content

Commit

Permalink
fix: log warn in case of multiple integration entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Assermark authored and argoyle committed Dec 19, 2022
1 parent ea82a4b commit d600559
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions custom_components/ferroamp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ async def async_unload_entry(hass, entry):


async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
# Make sure MQTT is available and the entry is loaded
if not hass.config_entries.async_entries(
mqtt.DOMAIN
) or not await hass.config_entries.async_wait_component(
hass.config_entries.async_entries(mqtt.DOMAIN)[0]
):
# Make sure MQTT is available and the entry component is loaded
entries = hass.config_entries.async_entries(mqtt.DOMAIN)
if len(entries) == 0:
_LOGGER.error("MQTT integration is not available")
return False
if not await hass.config_entries.async_wait_component(entries[0]):
if len(entries) > 1:
_LOGGER.warn("Multiple MQTT integrations entries available, please check your configuration")
_LOGGER.error("MQTT integration component is not loaded")
return False

_LOGGER.debug("Setting up ferroamp battery service calls")
hass.data.setdefault(DOMAIN, {})
Expand All @@ -69,7 +71,7 @@ async def control_request(cmd_name, target, power=None):
prefix = list(hass.data[DOMAIN][DATA_PREFIXES].values())[0]
if len(hass.data[DOMAIN][DATA_PREFIXES]) > 1:
if len(target) == 0:
raise Exception(f"Target needs to be specified since more than one instance of Ferroamp is available")
raise Exception("Target needs to be specified since more than one instance of Ferroamp is available")
_LOGGER.info(f"Looking up prefix for device with id {target}")
device = device_registry.async_get(target)
if device is None:
Expand Down

0 comments on commit d600559

Please sign in to comment.