Ejemplo n.º 1
0
    async def async_migrate_task(
        entity_id: str, conf: dict[str, str], key: str
    ) -> None:
        _LOGGER.debug("Migrating webOS Smart TV entity %s unique_id", entity_id)
        client = WebOsClient(conf[CONF_HOST], key)
        tries = 0
        while not client.is_connected():
            try:
                await client.connect()
            except WEBOSTV_EXCEPTIONS:
                if tries == 0:
                    _LOGGER.warning(
                        "Please make sure webOS TV %s is turned on to complete "
                        "the migration of configuration.yaml to the UI",
                        entity_id,
                    )
                wait_time = 2 ** min(tries, 4) * 5
                tries += 1
                await asyncio.sleep(wait_time)
            except WebOsTvPairError:
                return
            else:
                break

        ent_reg = entity_registry.async_get(hass)
        if not (
            new_entity_id := ent_reg.async_get_entity_id(
                Platform.MEDIA_PLAYER, DOMAIN, key
            )
        ):
            _LOGGER.debug(
                "Not updating webOSTV Smart TV entity %s unique_id, entity missing",
                entity_id,
            )
            return
Ejemplo n.º 2
0
async def async_control_connect(host: str, key: str | None) -> WebOsClient:
    """LG Connection."""
    client = WebOsClient(host, key)
    try:
        await client.connect()
    except WebOsTvPairError:
        _LOGGER.warning("Connected to LG webOS TV %s but not paired", host)
        raise

    return client
Ejemplo n.º 3
0
class WebOsClientWrapper:
    """Wrapper for a WebOS TV client with Home Assistant specific functions."""
    def __init__(self, host: str, client_key: str) -> None:
        """Set up the client."""
        self.host = host
        self.client_key = client_key
        self.turn_on = PluggableAction()
        self.client: WebOsClient | None = None

    async def connect(self) -> None:
        """Attempt a connection, but fail gracefully if tv is off for example."""
        self.client = WebOsClient(self.host, self.client_key)
        with suppress(*WEBOSTV_EXCEPTIONS, WebOsTvPairError):
            await self.client.connect()

    async def shutdown(self) -> None:
        """Unregister callbacks and disconnect."""
        assert self.client
        self.client.clear_state_update_callbacks()
        await self.client.disconnect()
Ejemplo n.º 4
0
 async def connect(self) -> None:
     """Attempt a connection, but fail gracefully if tv is off for example."""
     self.client = WebOsClient(self.host, self.client_key)
     with suppress(*WEBOSTV_EXCEPTIONS, WebOsTvPairError):
         await self.client.connect()