Skip to content

Commit

Permalink
Don't load integration if core integration is configured (#734)
Browse files Browse the repository at this point in the history
* Block if custom component is used

* Update custom_components/tahoma/__init__.py

Co-authored-by: Thibaut <[email protected]>

Co-authored-by: Thibaut <[email protected]>
  • Loading branch information
iMicknl and tetienne authored Jan 26, 2022
1 parent 719aad1 commit 364b62e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions custom_components/tahoma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
password = entry.data[CONF_PASSWORD]
server = SUPPORTED_SERVERS[entry.data[CONF_HUB]]

if await _block_if_core_is_configured(hass, entry):
raise ConfigEntryNotReady(
"You cannot use Overkiz from core and custom component at the same time."
)

# To allow users with multiple accounts/hubs, we create a new session so they have separate cookies
session = async_create_clientsession(hass)
client = OverkizClient(
Expand Down Expand Up @@ -203,3 +208,16 @@ async def write_execution_history_to_log(client: OverkizClient):
def log_device(message: str, device: Device) -> None:
"""Log device information."""
_LOGGER.debug("%s (%s)", message, device)


async def _block_if_core_is_configured(hass: HomeAssistant, entry: ConfigEntry) -> bool:
overkiz_config_entries = hass.config_entries.async_entries("overkiz")

for overkiz_entry in overkiz_config_entries:
if (
entry.data[CONF_USERNAME] == overkiz_entry.data[CONF_USERNAME]
and entry.data[CONF_HUB] == overkiz_entry.data[CONF_HUB]
):
return True

return False

0 comments on commit 364b62e

Please sign in to comment.