diff --git a/PyStageLinQ/Network.py b/PyStageLinQ/Network.py index 91e7795..149065c 100644 --- a/PyStageLinQ/Network.py +++ b/PyStageLinQ/Network.py @@ -5,6 +5,7 @@ from __future__ import annotations import asyncio +import logging from . import EngineServices from .DataClasses import ( StageLinQServiceAnnouncementData, @@ -15,6 +16,8 @@ from . import Token from typing import Callable, Tuple, List, Any +logger = logging.getLogger("PyStageLinQ") + class StageLinQService: _loopcondition = True @@ -142,7 +145,7 @@ async def _receive_frames( frames, self.remaining_data = self.decode_multiframe(response) if frames is None: # Something went wrong during decoding, lets throw away the frame and hope it doesn't happen again - print(f"Error while decoding the frame") + logger.debug(f"Error while decoding the frame") return False self.last_frame = response return frames diff --git a/PyStageLinQ/PyStageLinQ.py b/PyStageLinQ/PyStageLinQ.py index d9dd953..1d9c1eb 100644 --- a/PyStageLinQ/PyStageLinQ.py +++ b/PyStageLinQ/PyStageLinQ.py @@ -7,6 +7,7 @@ import socket import time import asyncio +import logging from typing import Callable from . import Device @@ -16,6 +17,8 @@ from .Network import StageLinQService from . import EngineServices +logger = logging.getLogger("PyStageLinQ") + class PyStageLinQ: """ @@ -190,7 +193,7 @@ async def _discover_stagelinq_device(self, host_ip, timeout=10): # No devices found within timeout return PyStageLinQError.DISCOVERYTIMEOUT - print(f"No discovery frames found on {host_ip} last {timeout} seconds.") + logger.info(f"No discovery frames found on {host_ip} last {timeout} seconds.") async def _register_new_device(self, discovery_frame, ip): stagelinq_device = StageLinQService(ip, discovery_frame, self.OwnToken, None) @@ -267,10 +270,12 @@ async def _periodic_announcement(self): async def _py_stagelinq_strapper(self): strapper_tasks = set() - print(f"Looking for discovery frames on {len(self.ip)} IP local IP addresses:") + logger.info( + f"Looking for discovery frames on {len(self.ip)} IP local IP addresses:" + ) for ip in self.ip: - print(f"{ip}") + logger.info(f"{ip}") strapper_tasks.add( asyncio.create_task(self._discover_stagelinq_device(ip, timeout=2)) ) @@ -284,7 +289,7 @@ async def _py_stagelinq_strapper(self): raise task.exception() if all_tasks_done: - print("Timeout occurred on all interfaces.") + logger.debug("Timeout occurred on all interfaces.") return await asyncio.sleep(1) diff --git a/changelog.md b/changelog.md index 1a33ee4..381af19 100644 --- a/changelog.md +++ b/changelog.md @@ -16,12 +16,14 @@ Code now uses classes instead of raw data in several places. ### Added PyStageLinQ can now send announcement messages and look for StageLinQ devices on all network interfaces. -To send on only one interface use `PyStageLinQ.__init__(..., ip=169.254.13.37, ...)` +To send on only one interface use `PyStageLinQ.__int__(..., ip=169.254.13.37, ...)` Unit tests, code coverage is now 100%. Also added a lot to the CI builds to support this. + +PyStageLinQ now uses logging instead of print to report status and info. ### Removed -Remove announcement_ip from `PyStageLinQ.__init__` as this can be derived from chosen ip. e.g. if 169.254.13.37 is chosen -announcement ip will be at 169.254.255.255. +Remove announcement_ip from `PyStageLinQ.__init__` as this can be derived from chosen IP address. e.g. if 169.254.13.37 is chosen +announcement IP address will be at 169.254.255.255. ## [0.1.2] - Documentation update again A lot of small fixes and additions now makes the readthedocs.org link to actually work. @@ -35,7 +37,7 @@ tag added to git and all release work is done. ## [0.1.1] - Documentation update Added documentation ### Added -docs/folder with documentation, run `make html` to create documentation. It is also available at h +docs/folder with documentation, run `make html` to create documentation. It is also available at https://pystagelinq.readthedocs.io/en/latest/ ### Changes diff --git a/tests/Main.py b/tests/Main.py index 07e599c..681ff68 100644 --- a/tests/Main.py +++ b/tests/Main.py @@ -3,8 +3,11 @@ This code is licensed under MIT license (see LICENSE for details) """ +import logging from PyStageLinQ import EngineServices, PyStageLinQ +logger = logging.getLogger(__name__) + """ Processes needed for StageLinQ: 1. Announce: Send discovery frame every 1 s @@ -44,6 +47,7 @@ def state_map_data_print(data): def main(): + logging.basicConfig(level=logging.INFO) global PrimeGo """PrimeGo = PyStageLinQ.PyStageLinQ( new_device_found_callback, name="Jaxcie StageLinQ", ip="169.254.13.37"