Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion PyStageLinQ/Network.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations
import asyncio
import logging
from . import EngineServices
from .DataClasses import (
StageLinQServiceAnnouncementData,
Expand All @@ -15,6 +16,8 @@
from . import Token
from typing import Callable, Tuple, List, Any

logger = logging.getLogger("PyStageLinQ")


class StageLinQService:
_loopcondition = True
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions PyStageLinQ/PyStageLinQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import socket
import time
import asyncio
import logging
from typing import Callable

from . import Device
Expand All @@ -16,6 +17,8 @@
from .Network import StageLinQService
from . import EngineServices

logger = logging.getLogger("PyStageLinQ")


class PyStageLinQ:
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
)
Expand All @@ -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)

Expand Down
10 changes: 6 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down