Пример #1
0
        public NEEODevice Build(string adapterName)
        {
            if (adapterName == null)
            {
                throw new NEEOException("MISSING_ADAPTERNAME");
            }
            if (_buttons.Count > 0 && _buttonHandler == null)
            {
                _logger.LogError("BUTTONS_DEFINED_BUT_NO_BUTTONHANDLER_DEFINED");
                //throw new NEEOException("BUTTONS_DEFINED_BUT_NO_BUTTONHANDLER_DEFINED");
            }
            if (_timeing != null && ValidationModule.DeviceTypeDoesNotSupportTiming(_type))
            {
                throw new NEEOException("TIMING_DEFINED_BUT_DEVICETYPE_HAS_NO_SUPPORT");
            }

            foreach (var button in _buttons)
            {
                if (_buttonHandler != null)
                {
                    button.Controller = new Controller(async(deviceId) => {
                        await _buttonHandler(button.Name, deviceId);
                        return((object)true);
                    });
                }
            }

            var deviceCapability = DeviceCapability.Build(this, adapterName, _logger);
            var capabilities     = deviceCapability.Capabilities;
            var handler          = deviceCapability.HandlerMap;

            if (capabilities.Count == 0)
            {
                throw new NEEOException("INVALID_DEVICE_DESCRIPTION_NO_CAPABILITIES");
            }

            if (ValidationModule.DeviceTypeNeedsInputCommand(_type) && ValidationModule.HasNoInputButtonsDefined(_buttons))
            {
                _logger.LogWarning("\nWARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!");
                _logger.LogWarning("WARNING: no input commands defined! Your device might not work as desired, check the docs");
            }

            NEEODevice device = new NEEODevice
            {
                AdapterName          = _deviceIdentifier,
                ApiVersion           = API_VERSION,
                Type                 = _type,
                Manufacturer         = _manufacturer,
                Setup                = _setup,
                Devices              = new NEEODevice.DevicePar[] { new NEEODevice.DevicePar(_type, _manufacturer, _devicename, _additionalSearchTokens.ToArray()) },
                Capabilities         = capabilities.ToArray(),
                DeviceCapabilities   = _deviceCapabilities.ToArray(),
                Handler              = handler,
                SubscriptionFunction = _subscriptionFunction,
                InitializeFunction   = _initializeFunction,
                Timing               = _timeing
            };

            return(device);
        }
Пример #2
0
 public DeviceEntry(int index, NEEODevice adapter, NEEODevice.DevicePar device)
 {
     Id                 = index;
     AdapterName        = adapter.AdapterName;
     Type               = device.Type == DeviceType.TYPE.UNKNOWN ? adapter.Type : device.Type;
     Manufacturer       = device.Manufacturer == null ? adapter.Manufacturer : device.Manufacturer;
     Name               = device.Name;
     Tokens             = device.Tokens == null ? string.Empty : string.Join(" ", device.Tokens);
     Device             = device;
     Setup              = adapter.Setup;
     Timing             = adapter.Timing;
     Capabilities       = adapter.Capabilities;
     DeviceCapabilities = adapter.DeviceCapabilities;
 }