From 379720082534953794dbd6529bf365d31149c396 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sat, 22 Feb 2025 00:44:29 +0100 Subject: [PATCH 1/2] Fix adding devices --- src/iSponsorBlockTV/config_setup.py | 13 +++++++------ src/iSponsorBlockTV/main.py | 2 +- src/iSponsorBlockTV/setup_wizard.py | 3 ++- src/iSponsorBlockTV/ytlounge.py | 3 +-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py index a46015e..fa369cd 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -44,10 +44,13 @@ def get_yn_input(prompt): return choice.lower() print("Invalid input. Please enter 'y' or 'n'.") +async def create_web_session(): + return aiohttp.ClientSession() -async def pair_device(): +async def pair_device(web_session: aiohttp.ClientSession): try: - lounge_controller = ytlounge.YtLoungeApi("iSponsorBlockTV") + lounge_controller = ytlounge.YtLoungeApi() + await lounge_controller.change_web_session(web_session) pairing_code = input(PAIRING_CODE_PROMPT) pairing_code = int( pairing_code.replace("-", "").replace(" ", "") @@ -71,7 +74,7 @@ async def pair_device(): def main(config, debug: bool) -> None: print("Welcome to the iSponsorBlockTV cli setup wizard") loop = asyncio.get_event_loop_policy().get_event_loop() - web_session = aiohttp.ClientSession() + web_session = loop.run_until_complete(create_web_session()) if debug: loop.set_debug(True) asyncio.set_event_loop(loop) @@ -88,9 +91,7 @@ def main(config, debug: bool) -> None: devices = config.devices choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices))) while choice == "y": - task = loop.create_task(pair_device()) - loop.run_until_complete(task) - device = task.result() + device = loop.run_until_complete(pair_device(web_session)) if device: devices.append(device) choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices))) diff --git a/src/iSponsorBlockTV/main.py b/src/iSponsorBlockTV/main.py index 50312fe..223227b 100644 --- a/src/iSponsorBlockTV/main.py +++ b/src/iSponsorBlockTV/main.py @@ -29,7 +29,7 @@ class DeviceListener: self.logger.addHandler(sh) self.logger.info("Starting device") self.lounge_controller = ytlounge.YtLoungeApi( - device.screen_id, config, api_helper, self.logger, self.web_session + device.screen_id, config, api_helper, self.logger ) # Ensures that we have a valid auth token diff --git a/src/iSponsorBlockTV/setup_wizard.py b/src/iSponsorBlockTV/setup_wizard.py index de5cd21..7ada229 100644 --- a/src/iSponsorBlockTV/setup_wizard.py +++ b/src/iSponsorBlockTV/setup_wizard.py @@ -340,8 +340,9 @@ class AddDevice(ModalWithClickExit): async def handle_add_device_pin(self) -> None: self.query_one("#add-device-pin-add-button").disabled = True lounge_controller = ytlounge.YtLoungeApi( - "iSponsorBlockTV", web_session=self.web_session + "iSponsorBlockTV", ) + await lounge_controller.change_web_session(self.web_session) pairing_code = self.query_one("#pairing-code-input").value pairing_code = int( pairing_code.replace("-", "").replace(" ", "") diff --git a/src/iSponsorBlockTV/ytlounge.py b/src/iSponsorBlockTV/ytlounge.py index 4f7e4cd..02825e7 100644 --- a/src/iSponsorBlockTV/ytlounge.py +++ b/src/iSponsorBlockTV/ytlounge.py @@ -13,11 +13,10 @@ create_task = asyncio.create_task class YtLoungeApi(pyytlounge.YtLoungeApi): def __init__( self, - screen_id, + screen_id=None, config=None, api_helper=None, logger=None, - web_session: ClientSession = None, ): super().__init__( config.join_name if config else "iSponsorBlockTV", logger=logger From 114326e34cd77b53558a3213734d3ac225cecffc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 23:45:26 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/iSponsorBlockTV/config_setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py index fa369cd..ab5fb03 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -44,9 +44,11 @@ def get_yn_input(prompt): return choice.lower() print("Invalid input. Please enter 'y' or 'n'.") + async def create_web_session(): return aiohttp.ClientSession() + async def pair_device(web_session: aiohttp.ClientSession): try: lounge_controller = ytlounge.YtLoungeApi()