Пример #1
0
        public void Trigger()
        {
            if (TriggerCommand != null)
            {
                cli.Execute(TriggerCommand, echo: true);
            }

            tokenSource?.Cancel();
            tokenSource = new CancellationTokenSource();

            var task = Task.Delay(ResetDelay, tokenSource.Token).ContinueWith(x =>
            {
                if (!x.IsCanceled && ResetCommand != null)
                {
                    cli.Execute(ResetCommand, echo: true);
                }
            });
        }
Пример #2
0
        static void wallMote1Changed(object sender, ReportEventArgs <CentralSceneReport> e)
        {
            var button = e.Report.SceneNumber;

            switch (button)
            {
            case 1: wallmote1_button1.Inc(); break;

            case 3: cli.Execute("turn study lights off", echo: true); break;

            case 2: cli.Execute("turn snug lights on", echo: true); break;

            case 4: cli.Execute("turn snug lights off", echo: true); break;
            }
        }
Пример #3
0
        static void Main()
        {
            KeepAlive();

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore,
                Converters        = { new StringEnumConverter() }
            };

            // Start the network
            var controller = CreateController("COM3");
            //controller.Channel.Log = Console.Out;
            var nodeStates = LoadStates();
            var network    = new ZWaveNetwork(controller, nodeStates)
            {
                OnStateChange = () => SaveStates(nodeStates)
            };

            Task.Run(() => network.Start()).Wait();

            var twilight = LoadTwilight();

            // Build a context for commands to run in
            var context = new Context
            {
                Network  = network,
                Areas    = new List <Area>(),
                Tasks    = new List <BackgroundTask>(),
                Twilight = twilight
            };

            // Start the twilight tracker
            Task.Run(async() =>
            {
                while (true)
                {
                    var sleepFor = DateTimeOffset.Now.Date.AddDays(1) - DateTimeOffset.Now;
                    await Task.Delay(sleepFor);
                    var twilightSvc  = new TwilightService();
                    var twilight     = await twilightSvc.Get();
                    context.Twilight = twilight;
                    SaveTwilight(context.Twilight);
                }
            });

            // Create the command line interface
            cli = new Cli(context);

            // Load any background tasks and launch them again
            var tasks = LoadTasks();

            tasks.ForEach(x => cli.Execute(x, nak: true));

            // Run any startup commands
            var autoexec = LoadAutoexec();

            autoexec.ForEach(x => cli.Execute(x, nak: true));

            // TODO: Hack in Wallmote button handlers until I write some built-in support
            wallmote1_button1 = new IncrementalStateSwitch(cli)
            {
                StateCommands = new string[]
                {
                    "turn study desk lamp on",
                    "turn study ceiling lights on",
                }
            };
            var wallmote1 = network.nodes[18].GetCommandClass <CentralScene>();

            wallmote1.Changed += wallMote1Changed;

            wallmote2_button1 = new IncrementalStateSwitch(cli)
            {
                StateCommands = new string[]
                {
                    "turn porch indoor light",
                    "turn porch outdoor light on",
                    "turn driveway lights on",
                }
            };
            var wallmote2 = network.nodes[23].GetCommandClass <CentralScene>();

            wallmote2.Changed += wallMote2Changed;

            // TODO: Hack in outside motion sensors also
            var motionDetection = new DelayedSwitch(cli)
            {
                TriggerCommand = "turn driveway lights on then turn porch lights on then turn patio lights on",
                ResetCommand   = "turn driveway lights on then turn porch lights off then turn patio lights off",
                ResetDelay     = TimeSpan.FromMinutes(15)
            };

            var steinel1 = network.nodes[31].GetCommandClass <Alarm>();

            steinel1.Changed += (a, b) => motionDetection.Trigger();
            var steinel2 = network.nodes[32].GetCommandClass <Alarm>();

            steinel2.Changed += (a, b) => motionDetection.Trigger();

            Console.WriteLine("\nSystem ready");

            cli.RunCommandLoop();

            network.Stop();
            controller.Close();

            SaveStates(nodeStates);
            SaveTasks(context.Tasks);
        }
Пример #4
0
 public void Inc()
 {
     cli.Execute(StateCommands[state], echo: true);
     state = Math.Min(state + 1, StateCommands.Length - 1);
 }