From c57a66f160271b767bc44db930d13bd2f9114abf Mon Sep 17 00:00:00 2001 From: kongo09 Date: Mon, 1 Jan 2024 17:22:59 +0100 Subject: [PATCH] catch self discovery exception in simulation --- examples.py | 3 +-- pixoo/__init__.py | 27 ++++++++++++++++++++------- setup.py | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/examples.py b/examples.py index 5c39079..7b4f90c 100644 --- a/examples.py +++ b/examples.py @@ -1,5 +1,4 @@ -from pixoo import Channel, ImageResampleMode, Pixoo -from pixoo.font import Font +from pixoo import Channel, ImageResampleMode, Pixoo, Font ''' Create a connection to a Pixoo diff --git a/pixoo/__init__.py b/pixoo/__init__.py index 041302c..4cd6db2 100644 --- a/pixoo/__init__.py +++ b/pixoo/__init__.py @@ -6,6 +6,7 @@ from pixoo.config import PixooConfig from pixoo._colors import Palette +from pixoo.exceptions import NoPixooDevicesFound from pixoo.font import Font from pixoo.simulator import Simulator, SimulatorConfig from pixoo.api import PixooBaseApi @@ -85,24 +86,36 @@ class Pixoo(PixooBaseApi): def __init__( self, - pixoo_config=PixooConfig(), + pixoo_config=None, debug=False, simulated=False, simulation_config=SimulatorConfig(), ): - self.refresh_connection_automatically = ( - pixoo_config.refresh_connection_automatically - ) - super().__init__(pixoo_config.address) self.debug = debug - self.size = pixoo_config.size self.simulated = simulated + _pixoo_config = pixoo_config + if _pixoo_config == None and self.simulated: + _pixoo_config = PixooConfig(address="simulated", size=64) + elif _pixoo_config == None: + try: + _pixoo_config = PixooConfig() + except NoPixooDevicesFound: + if self.debug: + print(f"No Pixoo device found") + return + + self.refresh_connection_automatically = ( + _pixoo_config.refresh_connection_automatically + ) + super().__init__(_pixoo_config.address) + self.size = _pixoo_config.size + # Total number of pixels self.pixel_count = self.size * self.size # Generate URL - self.__url = f"http://{pixoo_config.address}/post" + self.__url = f"http://{_pixoo_config.address}/post" # Prefill the buffer self.fill() diff --git a/setup.py b/setup.py index 8aa701c..303c0aa 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="pixoo", - version="0.8.1", + version="0.8.2", author="Ron Talman, kongo09", description=( "A library to easily communicate with the Divoom Pixoo 64",