4 from asyncio
import timeout
8 from arcam.fmj
import ConnectionFailed
9 from arcam.fmj.client
import Client
17 DEFAULT_SCAN_INTERVAL,
19 SIGNAL_CLIENT_STARTED,
20 SIGNAL_CLIENT_STOPPED,
23 type ArcamFmjConfigEntry = ConfigEntry[Client]
25 _LOGGER = logging.getLogger(__name__)
28 PLATFORMS = [Platform.MEDIA_PLAYER]
32 """Set up config entry."""
33 entry.runtime_data = Client(entry.data[CONF_HOST], entry.data[CONF_PORT])
35 entry.async_create_background_task(
36 hass,
_run_client(hass, entry.runtime_data, DEFAULT_SCAN_INTERVAL),
"arcam_fmj"
39 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
44 """Cleanup before removing config entry."""
45 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
48 async
def _run_client(hass: HomeAssistant, client: Client, interval: float) ->
None:
49 def _listen(_: Any) ->
None:
54 async
with timeout(interval):
57 _LOGGER.debug(
"Client connected %s", client.host)
61 with client.listen(_listen):
62 await client.process()
66 _LOGGER.debug(
"Client disconnected %s", client.host)
69 except ConnectionFailed:
70 await asyncio.sleep(interval)
74 _LOGGER.exception(
"Unexpected exception, aborting arcam client")
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
None _run_client(HomeAssistant hass, Client client, float interval)
bool async_setup_entry(HomeAssistant hass, ArcamFmjConfigEntry entry)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)