diff --git a/madvr/madvr.py b/madvr/madvr.py index 64cb813..9d8c59e 100644 --- a/madvr/madvr.py +++ b/madvr/madvr.py @@ -360,12 +360,19 @@ async def read_notifications(self) -> None: "Connection reset by peer. Attempting to reconnect..." ) await self._reconnect() - except (AttributeError, asyncio.TimeoutError, OSError) as err: + except asyncio.TimeoutError as err: + # if no new notifications, just keep going + self.logger.debug("No new notifications to read: %s", err) + except AttributeError as err: + self.logger.error("Attribute error with notifications: %s", err) + await self._reconnect() + continue + except OSError as err: self.logger.error("Reading notifications failed or timed out: %s", err) continue if not msg: - await asyncio.sleep(1) + await asyncio.sleep(0.1) continue await self._process_notifications(msg.decode("utf-8")) @@ -377,14 +384,17 @@ async def _process_notifications(self, msg: str) -> None: # for each /r/n split it by title, then the rest are values for notification in notifications: title, *signal_info = notification.split(" ") + + if "NoSignal" in title: + self.msg_dict["is_signal"] = False + # dont process empty values if not signal_info: continue # at least madvr sends attributes in a consistent order # could use zip here but why? this works and is simple - if "NoSignal" in title: - self.msg_dict["is_signal"] = False - elif "IncomingSignalInfo" in title: + + if "IncomingSignalInfo" in title: self.msg_dict["is_signal"] = True self.msg_dict["incoming_res"] = signal_info[0] self.msg_dict["incoming_frame_rate"] = signal_info[1] diff --git a/setup.py b/setup.py index c9b484d..0dea918 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="py_madvr2", - version="1.4.91", + version="1.4.92", author="iloveicedgreentea2", description="A package to control MadVR Envy over IP", long_description=long_description, diff --git a/tests/testMadVR.py b/tests/testMadVR.py index 1f58c34..62475af 100644 --- a/tests/testMadVR.py +++ b/tests/testMadVR.py @@ -26,6 +26,7 @@ async def test_process_info(self): "incoming_frame_rate": "60p", "incoming_color_space": "444", "incoming_bit_depth": "12bit", + "is_signal": True, "hdr_flag": True, "incoming_colorimetry": "2020", "incoming_black_levels": "TV", @@ -43,3 +44,10 @@ async def test_process_info(self): "outgoing_black_levels": "TV", }, ) + async def test_send_command(self): + """Verify the send command func works""" + await madvr.send_command(["GetIncomingSignalInfo"]) + await madvr.read_notifications() + # s = await madvr.send_command(["GetAspectRatio"]) + + print(madvr.msg_dict)