Skip to content

Commit

Permalink
fix: client
Browse files Browse the repository at this point in the history
  • Loading branch information
acesyde committed Dec 3, 2023
1 parent a8ba9da commit a7f4c49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions custom_components/eau_agur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .api import AgurApiClient
from .const import DOMAIN, PLATFORMS, COORDINATOR
from .const import CONF_PROVIDER, DOMAIN, PLATFORMS, COORDINATOR, PROVIDERS
from .coordinator import EauAgurDataUpdateCoordinator


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up EAU par Agur from a config entry."""
session = async_get_clientsession(hass)

config_provider = PROVIDERS.get(entry.data[CONF_PROVIDER], None)
if config_provider is None:
raise Exception("Provider not found")

client = AgurApiClient(
host=config_provider["base_url"],
base_path=config_provider.get("base_path", None),
timeout=config_provider.get("default_timeout", None),
conversation_id=config_provider["conversation_id"],
client_id=config_provider["client_id"],
access_key=config_provider["access_key"],
session=session,
)

Expand All @@ -29,9 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Handle removal of an entry."""
if unloaded := await hass.config_entries.async_unload_platforms(
entry, PLATFORMS
):
if unloaded := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)
return unloaded

Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_agur_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def test_post_login(aresponses: ResponsesMockServer):
},
)
async with aiohttp.ClientSession() as session:
client = AgurApiClient(host=HOST_PATTERN, session=session)
client = AgurApiClient(HOST_PATTERN, session=session)
await client.login("dupond.toto@mycompany.com", "myP@ssw0rd!")


Expand Down

0 comments on commit a7f4c49

Please sign in to comment.