async def post(self) -> web.Response: """ Find and add all WLED devices on the LAN """ async_fire_and_forget(self._ledfx.devices.find_wled_devices(), self._ledfx.loop) response = {"status": "success"} return web.json_response(data=response, status=200)
async def deactivate(self): _LOGGER.info( ("Deactivating {} integration").format(self._config["name"]) ) self._active = False self._status = 2 async_fire_and_forget(self.disconnect(), self._ledfx.loop)
def start(self, open_ui=False): async_fire_and_forget(self.async_start(open_ui=open_ui), self.loop) # Windows does not seem to handle Ctrl+C well so as a workaround # register a handler and manually stop the app if sys.platform == 'win32': import win32api def handle_win32_interrupt(sig, func=None): self.stop() return True win32api.SetConsoleCtrlHandler(handle_win32_interrupt, 1) try: self.loop.run_forever() except KeyboardInterrupt: self.loop.call_soon_threadsafe(self.loop.create_task, self.async_stop()) self.loop.run_forever() except: # Catch all other exceptions and terminate the application. The loop # exeception handler will take care of logging the actual error and # LedFx will cleanly shutdown. self.loop.run_until_complete(self.async_stop(exit_code = -1)) pass finally: self.loop.stop() return self.exit_code
async def activate(self): _LOGGER.info( ("Activating {} integration").format(self._config["name"]) ) self._active = True self._status = 3 async_fire_and_forget(self.connect(), self._ledfx.loop)
def on_shutdown(e): for integration in self.values(): integration.on_shutdown() # TODO Make sure program lets this finish before closing! async_fire_and_forget( self.close_all_connections(), self._ledfx.loop )
async def disconnect(self): self._cancel_connect() if self._client is not None: # fire and forget bc for some reason close() never returns... -o- async_fire_and_forget(self._client.disconnect(), loop=self._ledfx.loop) await super().disconnect("Disconnected from QLC+ websocket") else: await super().disconnect()
async def async_start(self, open_ui=False): _LOGGER.info("Starting ledfx") await self.http.start() self.devices = Devices(self) self.effects = Effects(self) # TODO: Deferr self.devices.create_from_config(self.config['devices']) # TODO: This step blocks for 1.5 secs while searching for devices. # It needs a callback in 3-5 seconds to kill the zeroconf browser, which is # implemented using a blocking time.sleep if not self.devices.values(): _LOGGER.info("No devices saved in config.") async_fire_and_forget(self.devices.find_wled_devices(), self.loop) if open_ui: import webbrowser webbrowser.open(self.http.base_url) await self.flush_loop()
async def async_start(self, open_ui=False): _LOGGER.info("Starting ledfx") await self.http.start() self.devices = Devices(self) self.effects = Effects(self) self.integrations = Integrations(self) # TODO: Deferr self.devices.create_from_config(self.config["devices"]) self.integrations.create_from_config(self.config["integrations"]) if not self.devices.values(): _LOGGER.info("No devices saved in config.") async_fire_and_forget(self.devices.find_wled_devices(), self.loop) async_fire_and_forget(self.integrations.activate_integrations(), self.loop) if open_ui: import webbrowser # Check if we're binding to all adaptors if str(self.config["host"]) == "0.0.0.0": url = f"http://127.0.0.1:{str(self.config['port'])}" else: # If the user has specified an adaptor, launch its address url = self.http.base_url try: webbrowser.get().open(url) except webbrowser.Error: _LOGGER.warning( f"Failed to open default web browser. To access LedFx's web ui, open {url} in your browser. To prevent this error in future, configure a default browser for your system." ) await self.flush_loop()
def stop(self, exit_code=0): async_fire_and_forget(self.async_stop(exit_code), self.loop)
def callback(_): _LOGGER.info( f"QLC+ sent payload, triggered by event '{event_type}' with filter {event_filter}" ) async_fire_and_forget(self._send_payload(qlc_payload), loop=self._ledfx.loop)