コード例 #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            HomeKitServer.Init();

            var logger = new ConsoleLogger("mylogger", (s, level) => true, false);

            string ltpk = null;

            if (File.Exists("LTPK"))
            {
                ltpk = File.ReadAllText("LTPK");
            }

            string ltsk = null;

            if (File.Exists("LTSK"))
            {
                ltsk = File.ReadAllText("LTSK");
            }

            var homekit = new HomeKitServer(logger, 52765, "11automaticacore-1ad18", ltsk, ltpk, "BA:2F:FA:1A:CD:AA",
                                            "123-45-555", "AutomaticaCore123", "1AutomaticaCoreBridge");

            homekit.PairingCompleted += Homekit_PairingCompleted;

            var lightAccessory          = AccessoryFactory.CreateLightBulbAccessory("Light1", "AutomaticaCore", "123456", false);
            var outletAccessory         = AccessoryFactory.CreateOutletAccessory("Outlet", "AutomaticaCore", "123456", false);
            var switchAccessory         = AccessoryFactory.CreateSwitchAccessory("Switch1", "AutomaticaCore", "123456", false);
            var contactSensorAcceessory = AccessoryFactory.CreateContactSensorAccessory("Contact1", "AutomaticaCore", "123456", 0);

            homekit.AddAccessory(lightAccessory);
            homekit.AddAccessory(outletAccessory);
            homekit.AddAccessory(switchAccessory);
            homekit.AddAccessory(contactSensorAcceessory);
            homekit.AddAccessory(AccessoryFactory.CreateTemperatureSensorAccessory("Temperature1", "AutomaticaCore", "asdfasdf", 22.9));

            homekit.ValueChanged += (sender, eventArgs) =>
                                    Console.WriteLine($"Value changed {eventArgs.Characteristic.Value}");

            await homekit.Start();

            Console.ReadLine();

            var onoff = lightAccessory.Services[1].Characteristics.SingleOrDefault(a => a.Id == 8);

            homekit.SetCharacteristicValue(onoff, true);

            Console.ReadLine();

            await homekit.Stop();
        }
コード例 #2
0
ファイル: HomeKitDriver.cs プロジェクト: cuonghd4k/automatica
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            if (ctx.NodeInstance.This2NodeTemplateNavigation.Key == "pairing-key")
            {
                _pairingNode = new PairingKeyNode(ctx);

                return(_pairingNode);
            }

            Accessory accessory = null;


            switch (ctx.NodeInstance.This2NodeTemplateNavigation.Key)
            {
            case "light-bulb-folder":
                accessory = AccessoryFactory.CreateLightBulbAccessory(ctx.NodeInstance.Name, "AutomaticaCore",
                                                                      ctx.NodeInstance.ObjId.ToString(), false);
                break;

            case "power-outlet-folder":
                accessory = AccessoryFactory.CreateOutletAccessory(ctx.NodeInstance.Name, "AutomaticaCore",
                                                                   ctx.NodeInstance.ObjId.ToString(), false);
                break;

            case "contact-sensor-folder":
                accessory = AccessoryFactory.CreateContactSensorAccessory(ctx.NodeInstance.Name, "AutomaticaCore",
                                                                          ctx.NodeInstance.ObjId.ToString(), 1);
                break;

            case "switch-folder":
                accessory = AccessoryFactory.CreateSwitchAccessory(ctx.NodeInstance.Name, "AutomaticaCore",
                                                                   ctx.NodeInstance.ObjId.ToString(), false);
                break;

            case "temperature-sensor-folder":
                accessory = AccessoryFactory.CreateTemperatureSensorAccessory(ctx.NodeInstance.Name, "AutomaticaCore",
                                                                              ctx.NodeInstance.ObjId.ToString(), 0);
                break;
            }

            if (accessory == null)
            {
                return(null);
            }

            _accessories.Add(accessory);

            return(new FolderNodeInstance(ctx, this, accessory));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: vsssunder/automatica
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var logger = new ConsoleLogger();

            HomeKitServer.Init(logger);


            string ltpk = null;

            if (File.Exists("LTPK"))
            {
                ltpk = File.ReadAllText("LTPK");
            }

            string ltsk = null;

            if (File.Exists("LTSK"))
            {
                ltsk = File.ReadAllText("LTSK");
            }

            ServerInfo.ServerUid = Guid.NewGuid();

            var    objId = new Guid("e00b1712-a2bf-4420-b3e5-c9b9a0c4a5f2").ToString().Replace("-", "");
            string code  = $"{CreateRandom(100, 999)}-{CreateRandom(10, 99)}-{CreateRandom(100, 999)}";

            code = "111-23-222";

            Console.WriteLine($"Code is {code}");

            var homekitId =
                $"{objId[0]}{objId[1]}:{objId[2]}{objId[3]}:{objId[4]}{objId[5]}:{objId[6]}{objId[7]}:{objId[8]}{objId[9]}:{objId[10]}{objId[11]}";

            var homekit = new HomeKitServer(logger, 54321, "HomeKitA", ltsk, ltpk, homekitId,
                                            code, "demo", "demo" + homekitId, 6);

            homekit.PairingCompleted += Homekit_PairingCompleted;

            var lightAccessory           = AccessoryFactory.CreateLightBulbAccessory(0, "Light1", "AutomaticaCore", "123456", false);
            var lightAccessory2          = AccessoryFactory.CreateLightBulbAccessory(1, "Light2", "AutomaticaCore", "12345", false);
            var lightAccessory3          = AccessoryFactory.CreateLightBulbAccessory(3, "Light3", "AutomaticaCore", "1234567", false);
            var outletAccessory          = AccessoryFactory.CreateOutletAccessory(4, "Outlet", "AutomaticaCore", "123", false);
            var switchAccessory          = AccessoryFactory.CreateSwitchAccessory(5, "Switch1", "AutomaticaCore", "1456", false);
            var contactSensorAcceessory  = AccessoryFactory.CreateContactSensorAccessory(6, "Contact1", "AutomaticaCore", "d123456", 0);
            var contactSensorAcceessory2 = AccessoryFactory.CreateContactSensorAccessory(7, "Contact2", "AutomaticaCore", "1b23456", 0);
            var contactSensorAcceessory3 = AccessoryFactory.CreateContactSensorAccessory(10, "Contact3", "AutomaticaCore", "1b23456d", 0);
            var lightAccessory4          = AccessoryFactory.CreateLightBulbAccessory(9, "Light4", "AutomaticaCore", "asdf1234567", false);

            homekit.AddAccessory(lightAccessory);
            homekit.AddAccessory(lightAccessory2);
            homekit.AddAccessory(lightAccessory3);
            homekit.AddAccessory(lightAccessory4);
            homekit.AddAccessory(outletAccessory);
            homekit.AddAccessory(switchAccessory);
            homekit.AddAccessory(contactSensorAcceessory);
            homekit.AddAccessory(contactSensorAcceessory2);
            homekit.AddAccessory(contactSensorAcceessory3);
            homekit.AddAccessory(AccessoryFactory.CreateTemperatureSensorAccessory(8, "Temperature1", "AutomaticaCore", "asdfasdf", 22.9));

            homekit.ValueChanged += (sender, eventArgs) =>
                                    Console.WriteLine($"Value changed {eventArgs.Characteristic.Value}");

            homekit.PairingCompleted += (sender, eventArgs) =>
            {
                Console.WriteLine($"Paring completed...");
            };

            await homekit.Start();


            ThreadPool.QueueUserWorkItem(async state =>
            {
                var value = true;
                while (true)
                {
                    var onoff = contactSensorAcceessory.Services[1].Characteristics.SingleOrDefault(a => a.Id == 8);
                    homekit.SetCharacteristicValue(onoff, value);

                    value = !value;
                    await Task.Delay(1000);
                }
            });

            Console.ReadLine();

            await homekit.Stop();
        }