diff --git a/install.bat b/install.bat index 30a9527..7903884 100644 --- a/install.bat +++ b/install.bat @@ -2,5 +2,4 @@ rmdir dist /s /q python ./setup.py sdist # Get filename of the tar.gz file for /f "delims=" %%a in ('dir /b dist\*.tar.gz') do set filename=%%a -pip3 install dist/%filename% -python -m PyInstaller --onefile --noconsole --icon=src/espmega_lightshow/icon.ico --name="ESPMega Lightshow (Portable)" src/espmega_lightshow/__main__.py \ No newline at end of file +pip3 install dist/%filename% \ No newline at end of file diff --git a/setup.py b/setup.py index 72e83ea..4339d5b 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ def readme(): setup( name='espmega_lightshow', - version='4.8', + version='4.9', license='Apache 2.0', author="Siwat Sirichai", author_email='siwat@siwatinc.com', diff --git a/src/espmega_lightshow.egg-info/PKG-INFO b/src/espmega_lightshow.egg-info/PKG-INFO index 5514aac..fb3c578 100644 --- a/src/espmega_lightshow.egg-info/PKG-INFO +++ b/src/espmega_lightshow.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: espmega-lightshow -Version: 4.8 +Version: 4.9 Home-page: https://github.com/SiwatINC/espmega-lightshow Author: Siwat Sirichai Author-email: siwat@siwatinc.com diff --git a/src/espmega_lightshow/drivers.py b/src/espmega_lightshow/drivers.py index eb09563..c54f908 100644 --- a/src/espmega_lightshow/drivers.py +++ b/src/espmega_lightshow/drivers.py @@ -135,7 +135,7 @@ class ESPMegaLightDriver(LightDriver): def __init__(self, controller: ESPMega, pwm_channel: int) -> int: self.controller = controller - self.pwm_channel = pwm_channel + self.pwm_channel = int(pwm_channel) if controller is None: self.connected = False self.exception = "Controller is not connected." @@ -215,7 +215,9 @@ def get_controller(self, base_topic: str, light_server: str, light_server_port: # If there is no connection, create one self.mqtt_connections[(light_server, light_server_port)] = MQTTClient() try: - self.mqtt_connections[(light_server, light_server_port)].connect(light_server, light_server_port) + print(f"Connecting to light server at {light_server}:{light_server_port}") + self.mqtt_connections[(light_server, light_server_port)].connect(light_server, int(light_server_port)) + print(f"Starting thread for {light_server}:{light_server_port}") self.mqtt_connections[(light_server, light_server_port)].loop_start() print(f"Connected to {light_server}:{light_server_port}") except Exception as e: @@ -505,6 +507,7 @@ def read_light_map(self, light_map: list) -> list: self._validate_light_map(light_map) # Then we will initialize the light map self.initialize_light_map(light_map) + print(light_map) for row_index, row in enumerate(light_map): for column_index, light in enumerate(row): # light is a dictionary with fields varying by driver @@ -519,7 +522,6 @@ def read_light_map(self, light_map: list) -> list: continue # Let's switch on the driver field driver_type = light["driver"] - print(light) # If the driver is espmega, we utilize the ESPMegaMultiController to manage the controllers if driver_type == "espmega": controller = self.espmega_driver_bank.get_controller(light["base_topic"], light["light_server"], light["light_server_port"]) @@ -543,7 +545,7 @@ def read_light_map_from_file(self, filename: str): try: with open(filename, "r") as file: light_map = json.load(file) - self.read_light_map(light_map) + self.read_light_map(light_map) except FileNotFoundError: raise FileNotFoundError("The light map file does not exist.") def initialize_light_map(self, light_map): diff --git a/test_universal_driver.py b/test_universal_driver.py index e510797..77943f5 100644 --- a/test_universal_driver.py +++ b/test_universal_driver.py @@ -1,18 +1,13 @@ from src.espmega_lightshow.drivers import UniversalLightGrid -from secrets_storage import ha_api_key from time import sleep -example_universal_grid_map = [[{"driver":"espmega","light_server":"192.168.0.26","light_server_port":1883,"base_topic":"/espmega/ProR3","pwm_id":0},{"driver":"homeassistant","api_url":"http://192.168.0.25/api","api_key":ha_api_key,"entity_id":"light.laboratory_ceiling_light"}],[{"driver":"espmega","light_server":"192.168.0.26","light_server_port":1883,"base_topic":"/espmega/ProR3","pwm_id":1},{"driver":"homeassistant","api_url":"http://192.168.0.26/api","api_key":ha_api_key,"entity_id":"light.laboratory_light_strip"}]] +map_path = "C:\\Users\\siwat\\Nextcloud\\Documents\\m21_map_emg.json" grid = UniversalLightGrid() -grid.read_light_map(example_universal_grid_map) +grid.read_light_map_from_file(map_path) +sleep(5) + +# Check if light at 0,0 is connected print(grid.get_light_state(0, 0)) -grid.set_light_state(0, 0, True) -print(grid.get_light_state(0, 0)) -grid.set_light_state(0, 1, False) -print(grid.get_light_state(0, 1)) -grid.set_light_state(1, 0, True) -print(grid.get_light_state(1, 0)) -grid.set_light_state(1, 1, False) # Cycle the light on and off in order to test the driver # Note that this is a 2x2 grid, we will go clockwise