public HomeKitServer(ILogger logger, int port, string name, string ltsk, string ltpk, string deviceId, string pairCode, string manufacturer, string bridgeName, int configVersion)
        {
            if (!HomeKitSetup.IsSetupCodeValid(pairCode))
            {
                throw new ArgumentException($"{nameof(pairCode)} is not valid...");
            }

            if (configVersion <= 0)
            {
                configVersion = 1;
            }

            Manufacturer = manufacturer;
            BridgeName   = bridgeName;
            var hapPort = port;

            _bonjour   = new BonjourService(logger, Convert.ToUInt16(hapPort), name, deviceId, configVersion);
            _hapServer = new HapControllerServer(logger, this, hapPort, ltsk, ltpk, deviceId, pairCode);

            _bonjour.AlreadyPaired = !string.IsNullOrEmpty(ltpk);

            _hapServer.PairingCompleted += HapServerOnPairingCompleted;

            var bridgeAccessory = new Accessory
            {
                Id = 1
            };

            bridgeAccessory.Services.Add(AccessoryFactory.CreateAccessoryInfo(bridgeAccessory, 1, bridgeName, manufacturer, ServerInfo.ServerUid.ToString()));
            _accessoryContainer.AddAccessory(bridgeAccessory);
        }
Exemple #2
0
 public void TestInvalidSetupCodes()
 {
     Assert.False(HomeKitSetup.IsSetupCodeValid("000-00-000"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("111-11-111"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("222-22-222"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("333-33-333"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("444-44-444"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("555-55-555"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("666-66-666"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("777-77-777"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("888-88-888"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("999-99-999"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("123-45-678"));
     Assert.False(HomeKitSetup.IsSetupCodeValid("876-54-321"));
 }