mirror of
https://github.com/home-assistant/core.git
synced 2025-11-12 04:20:17 +00:00
* Added smarla integration * Apply suggested changes * Bump pysmarlaapi version and reevaluate quality scale * Focus on switch platform * Bump pysmarlaapi version * Change default name of device * Code refactoring * Removed obsolete reload function * Code refactoring and clean up * Bump pysmarlaapi version * Refactoring and changed access token format * Fix tests for smarla config_flow * Update quality_scale * Major rework of tests and refactoring * Bump pysmarlaapi version * Use object equality operator when applicable * Refactoring * Patch both connection objects * Refactor tests * Fix leaking tests * Implemented full test coverage * Bump pysmarlaapi version * Fix tests * Improve tests --------- Co-authored-by: Joostlek <joostlek@outlook.com>
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""The Swing2Sleep Smarla integration."""
|
|
|
|
from pysmarlaapi import Connection, Federwiege
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
|
|
|
from .const import HOST, PLATFORMS
|
|
|
|
type FederwiegeConfigEntry = ConfigEntry[Federwiege]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: FederwiegeConfigEntry) -> bool:
|
|
"""Set up this integration using UI."""
|
|
connection = Connection(HOST, token_b64=entry.data[CONF_ACCESS_TOKEN])
|
|
|
|
# Check if token still has access
|
|
if not await connection.refresh_token():
|
|
raise ConfigEntryAuthFailed("Invalid authentication")
|
|
|
|
federwiege = Federwiege(hass.loop, connection)
|
|
federwiege.register()
|
|
federwiege.connect()
|
|
|
|
entry.runtime_data = federwiege
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: FederwiegeConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
|
entry.runtime_data.disconnect()
|
|
|
|
return unload_ok
|