1 """The Kaleidescape integration."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from typing
import TYPE_CHECKING
9 from kaleidescape
import Device
as KaleidescapeDevice, KaleidescapeError
14 from .const
import DOMAIN
20 _LOGGER = logging.getLogger(__name__)
22 PLATFORMS = [Platform.MEDIA_PLAYER, Platform.REMOTE, Platform.SENSOR]
26 """Set up Kaleidescape from a config entry."""
27 device = KaleidescapeDevice(
28 entry.data[CONF_HOST], timeout=5, reconnect=
True, reconnect_delay=5
32 await device.connect()
33 except (KaleidescapeError, ConnectionError)
as err:
34 await device.disconnect()
36 f
"Unable to connect to {entry.data[CONF_HOST]}: {err}"
39 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = device
41 async
def disconnect(event: Event) ->
None:
42 await device.disconnect()
44 entry.async_on_unload(
45 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, disconnect)
48 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
54 """Unload config entry."""
55 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
56 await hass.data[DOMAIN][entry.entry_id].disconnect()
57 hass.data[DOMAIN].pop(entry.entry_id)
63 """Metadata for a Kaleidescape device."""
73 """Error for unsupported device types."""
77 """Validate device host."""
78 device = KaleidescapeDevice(host)
81 await device.connect()
82 except (KaleidescapeError, ConnectionError):
83 await device.disconnect()
86 info = KaleidescapeDeviceInfo(
88 serial=device.system.serial_number,
89 name=device.system.friendly_name,
90 model=device.system.type,
91 server_only=device.is_server_only,
94 await device.disconnect()
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
KaleidescapeDeviceInfo validate_host(str host)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)