Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def delete(self, device_id) -> web.Response:
device = self._ledfx.devices.get(device_id)
if device is None:
response = { 'not found': 404 }
return web.Response(text=json.dumps(response), status=404)
self._ledfx.devices.destroy(device_id)
# Update and save the configuration
self._ledfx._config['devices'] = [device for device in self._ledfx._config['devices'] if device['id'] != device_id]
save_config(
config = self._ledfx._config,
config_dir = self._ledfx._config_dir)
response = { 'status' : 'success' }
return web.Response(text=json.dumps(response), status=200)
async def delete(self, device_id) -> web.Response:
device = self._ledfx.devices.get(device_id)
if device is None:
response = { 'not found': 404 }
return web.Response(text=json.dumps(response), status=404)
device.clear_effect()
self._ledfx.devices.destroy(device_id)
# Update and save the configuration
self._ledfx.config['devices'] = [device for device in self._ledfx.config['devices'] if device['id'] != device_id]
save_config(
config = self._ledfx.config,
config_dir = self._ledfx.config_dir)
response = { 'status' : 'success' }
return web.Response(text=json.dumps(response), status=200)
return web.Response(text=json.dumps(response), status=500)
device_id = generate_id(device_config.get('name'))
# Remove the device it if already exist?
# Create the device
_LOGGER.info("Adding device of type {} with config {}".format(device_type, device_config))
device = self._ledfx.devices.create(
id = device_id,
type = device_type,
config = device_config,
ledfx = self._ledfx)
# Update and save the configuration
self._ledfx.config['devices'].append({'id': device.id, 'type': device.type, 'config': device.config })
save_config(
config = self._ledfx.config,
config_dir = self._ledfx.config_dir)
response = { 'status' : 'success', 'device': { 'type': device.type, 'config': device.config, 'id': device.id }}
return web.Response(text=json.dumps(response), status=200)
print('Stopping LedFx.')
# Fire a shutdown event and flush the loop
self.events.fire_event(LedFxShutdownEvent())
await asyncio.sleep(0, loop=self.loop)
await self.http.stop()
# Cancel all the remaining task and wait
tasks = [task for task in asyncio.Task.all_tasks() if task is not
asyncio.tasks.Task.current_task()]
list(map(lambda task: task.cancel(), tasks))
results = await asyncio.gather(*tasks, return_exceptions=True)
# Save the configuration before shutting down
save_config(config=self.config, config_dir=self.config_dir)
await self.flush_loop()
self.executor.shutdown()
self.exit_code = exit_code
self.loop.stop()
return web.Response(text=json.dumps(response), status=500)
device_id = generate_id(device_config.get('name'))
# Remove the device it if already exist?
# Create the device
_LOGGER.info("Adding device of type {} with config {}".format(device_type, device_config))
device = self._ledfx.devices.create(
id = device_id,
type = device_type,
config = device_config,
ledfx = self._ledfx)
# Update and save the configuration
self._ledfx._config['devices'].append({'id': device.id, 'type': device.type, 'config': device.config })
save_config(
config = self._ledfx._config,
config_dir = self._ledfx._config_dir)
response = { 'status' : 'success', 'device': { 'type': device.type, 'config': device.config, 'id': device.id }}
return web.Response(text=json.dumps(response), status=200)