1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-17 23:53:49 +01:00
Files
core/homeassistant/components/igloohome/__init__.py
Keith ff622af888 Add locking and unlocking feature to igloohome integration (#136002)
* - Added lock platform
- Added creation of IgloohomeLockEntity when bridge devices are included.

* - Migrated retrieval of linked_bridge utility to utils module.
- Added ability for lock to update it's own linked bridge automatically

* - Added mock bridge device to test fixture

* - Added snapshot test for lock module

* - Added bridge with no linked devices
- Added test for util.get_linked_bridge

* - Added handling of errors from API call

* - Bump igloohome-api to v0.1.0

* - Minor change

* - Removed async update for locks. Focus on MVP

* - Removed need for update on entity creation

* - Updated snapshot test

* - Updated snapshot

* - Updated to use walrus during lock entity creation
- Updated callback class for async_setup_entry based on lint suggestion

* - Set _attr_name as None
- Updated snapshot test

* Update homeassistant/components/igloohome/lock.py

* Update homeassistant/components/igloohome/lock.py

---------

Co-authored-by: Josef Zweck <josef@zweck.dev>
2025-03-09 20:47:13 +01:00

61 lines
1.8 KiB
Python

"""The igloohome integration."""
from __future__ import annotations
from dataclasses import dataclass
from aiohttp import ClientError
from igloohome_api import (
Api as IgloohomeApi,
ApiException,
Auth as IgloohomeAuth,
AuthException,
GetDeviceInfoResponse,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
PLATFORMS: list[Platform] = [Platform.LOCK, Platform.SENSOR]
@dataclass
class IgloohomeRuntimeData:
"""Holding class for runtime data."""
api: IgloohomeApi
devices: list[GetDeviceInfoResponse]
type IgloohomeConfigEntry = ConfigEntry[IgloohomeRuntimeData]
async def async_setup_entry(hass: HomeAssistant, entry: IgloohomeConfigEntry) -> bool:
"""Set up igloohome from a config entry."""
authentication = IgloohomeAuth(
session=async_get_clientsession(hass),
client_id=entry.data[CONF_CLIENT_ID],
client_secret=entry.data[CONF_CLIENT_SECRET],
)
api = IgloohomeApi(auth=authentication)
try:
devices = (await api.get_devices()).payload
except AuthException as e:
raise ConfigEntryError from e
except (ApiException, ClientError) as e:
raise ConfigEntryNotReady from e
entry.runtime_data = IgloohomeRuntimeData(api, devices)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: IgloohomeConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)