handle method

Future<void> handle({
  1. Application? app,
  2. DeviceCommand? command,
  3. WebSocketCommunicator? comm,
})

Implementation

Future<void> handle({
  Application? app,
  DeviceCommand? command,
  WebSocketCommunicator? comm,
}) async {
  if (command is ListDevicesCommand) {
    final devices = app!.devices.values
        .where((device) =>
            device.online == true &&
            (device.driverName == null || command.availableOnly != true))
        .toList();
    devices.sort((a, b) => a.device.compareTo(b.device));

    final reply = CommandAck(
      commandId: command.id,
      response: ListDevicesResponse(
        devices: devices
            .map(
              (device) => device.toConnectedDevice(),
            )
            .toList(),
      ),
    );

    await comm!.sendCommand(reply);
  }
}