private static void CloseController()
        {
            if (_controller == null)
            {
                Console.WriteLine($"Controller is already closed");

                return;
            }

            try
            {
                var name = _controller.GateWayName;

                Console.WriteLine($"Closing '{name}'");

                _collectedInformation = null;

                _controller = null;

                Console.WriteLine($"Closed '{name}'");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"CloseController exception {ex.Message}");
            }
        }
        /// <summary>
        /// Collect hub information and make it available globally.
        /// </summary>
        static async Task <bool> CollectInformation()
        {
            Console.WriteLine("Information collecting (this can take a while...)");

            var result = false;

            if (_controller != null)
            {
                if (_controller.GatewayController == null)
                {
                    System.Console.WriteLine("controller.GatewayController is null.");
                    return(false);
                }

                System.Console.WriteLine("Start GetGroupObjects");

                var groups = await _controller.GatewayController.GetGroupObjects();

                System.Console.WriteLine("Start GetDeviceObjects");

                var deviceObjects = await _controller.GatewayController.GetDeviceObjects();

                if (groups != null &&
                    deviceObjects != null)
                {
                    Console.WriteLine($"Number of groups found: '{groups.Count}'");
                    Console.WriteLine($"Number of devices found: '{deviceObjects.Count}'");

                    _collectedInformation = new CollectedInformation();

                    foreach (var group in groups)
                    {
                        var deviceGroup = new Group
                        {
                            name       = group.Name,
                            lightState = group.LightState,
                            activeMood = group.ActiveMood
                        };

                        Console.WriteLine($"{group.ID} - {group.Name} - {group.ActiveMood}");

                        foreach (var id in group.Devices.The15002.ID)
                        {
                            var device = new Device();

                            var deviceObject = deviceObjects.FirstOrDefault(x => x.ID == id);

                            if (deviceObject != null)
                            {
                                device.deviceType      = deviceObject.DeviceType.ToString();
                                device.name            = deviceObject.Name;
                                device.battery         = deviceObject.Info.Battery;
                                device.deviceTypeExt   = deviceObject.Info.DeviceType.ToString();
                                device.lastSeen        = deviceObject.LastSeen;
                                device.reachableState  = deviceObject.ReachableState.ToString();
                                device.serial          = deviceObject.Info.Serial;
                                device.firmwareVersion = deviceObject.Info.FirmwareVersion;
                                device.powerSource     = deviceObject.Info.PowerSource.ToString();

                                if (deviceObject.LightControl != null &&
                                    deviceObject.LightControl.Count > 0)
                                {
                                    device.dimmer   = deviceObject.LightControl[0].Dimmer;
                                    device.state    = deviceObject.LightControl[0].State.ToString();
                                    device.colorHex = deviceObject.LightControl[0].ColorHex;
                                }
                            }

                            deviceGroup.devices.Add(id, device);
                        }

                        _collectedInformation.groups.Add(group.ID, deviceGroup);
                    }

                    result = true;
                }
                else
                {
                    Console.WriteLine("No groups or devices found.");

                    return(false);
                }
            }
            else
            {
                Console.WriteLine("Controller is null.");

                return(false);
            }

            Console.WriteLine("Information collected");

            return(result);
        }