예제 #1
0
파일: SetColor.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;
            var color  = context.ReadParameter("Color").ToColor();

            device.ColorSwitch.SetValue(color);
        }
예제 #2
0
파일: SetColor.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;
            var color = context.ReadParameter("Color").ToColor();

            device.ColorSwitch.SetValue(color);
        }
예제 #3
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device       = context.Device as PiEngineeringDevice;
            var bankString   = context.ReadParameter("Color").Value;
            var button       = context.ReadParameter("Button").Value;
            var statusString = context.ReadParameter("Status").Value;

            Bank bank;

            if (!Enum.TryParse(bankString, out bank))
            {
                throw new RoomieRuntimeException("Color \"" + bankString + "\" is not valid");
            }

            var column = (byte)(button[0] - 'A');
            var row    = (byte)(button[1] - '1');

            LightStatus status;

            if (!Enum.TryParse(statusString, out status))
            {
                throw new RoomieRuntimeException("Status \"" + statusString + "\" is not valid");
            }

            device.SetButtonLight(bank, row, column, status);
        }
예제 #4
0
파일: SlowDim.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            var startPower = context.ReadParameter("StartPower").ToInteger();
            var endPower = context.ReadParameter("EndPower").ToInteger();

            TimeSpan duration = context.ReadParameter("Duration").ToTimeSpan();

            if (startPower == endPower)
            {
                System.Threading.Thread.Sleep(duration);
                return;
            }

            int numSteps = Math.Abs(endPower - startPower);
            TimeSpan timeStep = new TimeSpan(0, 0, 0, 0, ((int)duration.TotalMilliseconds)/(numSteps-1));

            int powerStep = 1;
            if (endPower < startPower)
                powerStep = -1;

            for (var currentPower = startPower; currentPower != endPower; currentPower = (currentPower + powerStep))
            {
                Console.Write(currentPower);
                device.MultilevelSwitch.SetPower(currentPower);
                System.Threading.Thread.Sleep(timeStep);
            }
            device.MultilevelSwitch.SetPower(endPower);
        }
예제 #5
0
파일: SlowDim.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            var startPower = context.ReadParameter("StartPower").ToInteger();
            var endPower   = context.ReadParameter("EndPower").ToInteger();

            TimeSpan duration = context.ReadParameter("Duration").ToTimeSpan();

            if (startPower == endPower)
            {
                System.Threading.Thread.Sleep(duration);
                return;
            }

            int      numSteps = Math.Abs(endPower - startPower);
            TimeSpan timeStep = new TimeSpan(0, 0, 0, 0, ((int)duration.TotalMilliseconds) / (numSteps - 1));


            int powerStep = 1;

            if (endPower < startPower)
            {
                powerStep = -1;
            }

            for (var currentPower = startPower; currentPower != endPower; currentPower = (currentPower + powerStep))
            {
                Console.Write(currentPower);
                device.MultilevelSwitch.SetPower(currentPower);
                System.Threading.Thread.Sleep(timeStep);
            }
            device.MultilevelSwitch.SetPower(endPower);
        }
예제 #6
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;
            var fanMode = context.ReadParameter("FanMode").ToThermostatFanMode();

            device.Thermostat.Fan.SetMode(fanMode);
        }
예제 #7
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;
            var mode   = context.ReadParameter("ThermostatMode").ToThermostatMode();

            device.Thermostat.Core.SetMode(mode);
        }
예제 #8
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var power  = context.ReadParameter("Power").ToInteger();
            var name   = context.ReadParameter("Name").Value;
            var device = context.Device;

            device.CurrentStateGenerator.AddStep(new WattsPower(power), name);
        }
예제 #9
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;
            var temperature = context.ReadParameter("Temperature").ToTemperature();
            var setpointType = context.ReadParameter("Setpoint").ToThermostatSetpointType();

            device.Thermostat.Setpoints.SetSetpoint(setpointType, temperature);
        }
예제 #10
0
파일: Dim.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            var power = context.ReadParameter("Power").ToInteger();

            device.MultilevelSwitch.SetPower(power);
        }
예제 #11
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device       = context.Device;
            var temperature  = context.ReadParameter("Temperature").ToTemperature();
            var setpointType = context.ReadParameter("Setpoint").ToThermostatSetpointType();

            device.Thermostat.Setpoints.SetSetpoint(setpointType, temperature);
        }
예제 #12
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device    = context.Device as PiEngineeringDevice;
            var bluePower = context.ReadParameter("BluePower").ToByte();
            var redPower  = context.ReadParameter("RedPower").ToByte();

            device.SetButtonLightIntensity(bluePower, redPower);
        }
예제 #13
0
파일: Dim.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            var power = context.ReadParameter("Power").ToInteger();

            device.MultilevelSwitch.SetPower(power);
        }
예제 #14
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var power = context.ReadParameter("Power").ToInteger();
            var name = context.ReadParameter("Name").Value;
            var device = context.Device;

            device.CurrentStateGenerator.AddStep(new WattsPower(power), name);
        }
예제 #15
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device  = context.Device as Q42HueDevice;
            var command = new LightCommand
            {
                Effect = Effect.ColorLoop,
            };

            device.SendCommand(command);
        }
예제 #16
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device         = context.Device;
            var network        = device.Network;
            var networkContext = network.Context;
            var history        = networkContext.History;
            var interpreter    = context.Interpreter;
            var deviceHistory  = history.DeviceEvents.FilterEntity(device);

            ListEvents.WriteHistory(deviceHistory, interpreter);
        }
예제 #17
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;
            var network = device.Network;
            var networkContext = network.Context;
            var history = networkContext.History;
            var interpreter = context.Interpreter;
            var deviceHistory = history.DeviceEvents.FilterEntity(device);

            ListEvents.WriteHistory(deviceHistory, interpreter);
        }
예제 #18
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device          = context.Device as ZWaveDevice;
            var interpreter     = context.Interpreter;
            var parameterNumber = context.ReadParameter("ParameterNumber").ToByte();
            var value           = context.ReadParameter("Value").ToByte();

            var parameter = device.BackingObject.ConfigurationParameters[parameterNumber];

            parameter.Value = value;
        }
예제 #19
0
        //TODO: rethink this command
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var interpreter = context.Interpreter;
            var device      = context.Device;

            TimeSpan pollInterval = context.ReadParameter("PollInterval").ToTimeSpan();
            int      maxErrors    = context.ReadParameter("MaxErrors").ToInteger();

            if (pollInterval.Seconds < 0)
            {
                throw new RoomieRuntimeException("PollInterval must be a positive (or 0) time interval.");
            }
            if (maxErrors < -1)
            {
                throw new RoomieRuntimeException("MaxErrors must be a positive (or 0, -1) integer.");
            }

            device.Poll();

            var startPower   = device.MultilevelSwitch.Power;
            var currentPower = startPower;

            int numFails = 0;

            while (true)
            {
                System.Threading.Thread.Sleep(pollInterval);
                try
                {
                    device.Poll();

                    currentPower = device.MultilevelSwitch.Power;
                    if (currentPower != startPower)
                    {
                        return;
                    }
                }
                catch (HomeAutomationException e) //TODO: specialized timeout exception?
                {
                    interpreter.WriteEvent("fail");
                    numFails++;
                    if (maxErrors >= 0 &&
                        numFails >= maxErrors)
                    {
                        throw new RoomieRuntimeException("HomeAutomation Error: " + e.Message);
                    }
                }
            }

            //WaitForChangeHelper helper = new WaitForChangeHelper(interpreter);
            //zWaveDevice.LevelChanged += new ControlThink.ZWave.Devices.ZWaveDevice.LevelChangedEventHandler(helper.zWaveDevice_LevelChanged);
            //helper.WaitUntilChange();
        }
예제 #20
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var interpreter = context.Interpreter;
            var device      = context.Device as OpenZWaveDevice;
            var returnRoute = context.ReadParameter(ReturnRouteKey).ToBoolean();

            interpreter.WriteEvent("Optimizing " + device);

            device.OptimizePaths(returnRoute);

            interpreter.WriteEvent("Done");
        }
예제 #21
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device      = context.Device as ZWaveDevice;
            var interpreter = context.Interpreter;

            for (byte i = 0; i < byte.MaxValue; i++)
            {
                ListValue(interpreter, device, i);
            }

            ListValue(interpreter, device, 255);
        }
예제 #22
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var interpreter = context.Interpreter;
            var device = context.Device;

            device.Network.RemoveDevice(device);

            interpreter.WriteEvent("Device removed: " + device);

            if (WebHookConnector.WebHookPresent(context))
            {
                context.AddSyncWithCloud();
            }
        }
예제 #23
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var interpreter = context.Interpreter;
            var device      = context.Device;

            device.Network.RemoveDevice(device);

            interpreter.WriteEvent("Device removed: " + device);

            if (WebHookConnector.WebHookPresent(context))
            {
                context.AddSyncWithCloud();
            }
        }
예제 #24
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device     = context.Device as PiEngineeringDevice;
            var bankString = context.ReadParameter("Color").Value;
            var power      = context.ReadParameter("Power").ToBoolean();

            Bank bank;

            if (!Enum.TryParse(bankString, out bank))
            {
                throw new RoomieRuntimeException("Color \"" + bankString + "\" is not valid");
            }

            device.SetAllButtonLights(bank, power);
        }
예제 #25
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device          = context.Device as ZWaveDevice;
            var interpreter     = context.Interpreter;
            var parameterNumber = context.ReadParameter("ParameterNumber").ToByte();

            var parameter = device.BackingObject.ConfigurationParameters[parameterNumber];

            if (parameter == null)
            {
                interpreter.WriteEvent("Parameter does not exist");
                return;
            }

            interpreter.WriteEvent(parameter.Value.ToString());
        }
예제 #26
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var interpreter = context.Interpreter;
            var device      = context.Device as OpenZWaveDevice;

            var headers = new[]
            {
                "Command Class",
                "Index",
                "Instance",
                "Value",
                "Units",
                "Type",
                "Label",
                "Help"
            };

            var values = device.Values
                         .OrderBy(x => x.Index)
                         .OrderBy(x => x.Instance)
                         .OrderBy(x => x.CommandClass.ToString());

            var rows = values.Select(TransformValue).ToArray();

            var rowsAndHeaders = new[] { headers }.Concat(rows).ToArray();

            var columnWidths = new int[headers.Length];

            for (var i = 0; i < columnWidths.Length; i++)
            {
                columnWidths[i] = rowsAndHeaders.Max(x => x[i].Length);
            }


            var tableBuilder = new TextTable(columnWidths);

            interpreter.WriteEvent(tableBuilder.StartOfTable(headers));

            foreach (var row in rows)
            {
                interpreter.WriteEvent(tableBuilder.ContentLine(row));
            }

            interpreter.WriteEvent(tableBuilder.EndOfTable());
        }
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var currentAction   = context.ReadParameter("CurrentAction").Value;
            var originalCommand = context.OriginalCommand;
            var commands        = originalCommand.InnerCommands;
            var device          = context.Device;
            var network         = device.Network;
            var triggers        = network.Context.Triggers;
            var history         = network.Context.History;
            var threadPool      = network.Context.ThreadPool;

            var trigger = new WhenTheCurrentActionChangesTrigger(device, currentAction, history.DeviceEvents);
            var action  = new RunScriptTriggerAction(threadPool, commands);

            var triggerBundle = new TriggerBundle(trigger, action);

            triggers.Add(triggerBundle);
        }
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var currentAction = context.ReadParameter("CurrentAction").Value;
            var originalCommand = context.OriginalCommand;
            var commands = originalCommand.InnerCommands;
            var device = context.Device;
            var network = device.Network;
            var triggers = network.Context.Triggers;
            var history = network.Context.History;
            var threadPool = network.Context.ThreadPool;

            var trigger = new WhenTheCurrentActionChangesTrigger(device, currentAction, history.DeviceEvents);
            var action = new RunScriptTriggerAction(threadPool, commands);

            var triggerBundle = new TriggerBundle(trigger, action);

            triggers.Add(triggerBundle);
        }
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var target = context.ReadParameter("Target").ToHumidity();
            var originalCommand = context.OriginalCommand;
            var commands = originalCommand.InnerCommands;
            var device = context.Device;
            var network = device.Network;
            var triggers = network.Context.Triggers;
            var history = network.Context.History;
            var threadPool = network.Context.ThreadPool;

            var trigger = new WhenHumidityFallsBelowValueTrigger(device, target, history.DeviceEvents);
            var action = new RunScriptTriggerAction(threadPool, commands);

            var triggerBundle = new TriggerBundle(trigger, action);

            triggers.Add(triggerBundle);
        }
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var target          = context.ReadParameter("Target").ToHumidity();
            var originalCommand = context.OriginalCommand;
            var commands        = originalCommand.InnerCommands;
            var device          = context.Device;
            var network         = device.Network;
            var triggers        = network.Context.Triggers;
            var history         = network.Context.History;
            var threadPool      = network.Context.ThreadPool;

            var trigger = new WhenHumidityRisesAboveValueTrigger(device, target, history.DeviceEvents);
            var action  = new RunScriptTriggerAction(threadPool, commands);

            var triggerBundle = new TriggerBundle(trigger, action);

            triggers.Add(triggerBundle);
        }
예제 #31
0
        //TODO: rethink this command
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var interpreter = context.Interpreter;
            var device = context.Device;

            TimeSpan pollInterval = context.ReadParameter("PollInterval").ToTimeSpan();
            int maxErrors = context.ReadParameter("MaxErrors").ToInteger();

            if (pollInterval.Seconds < 0)
                throw new RoomieRuntimeException("PollInterval must be a positive (or 0) time interval.");
            if (maxErrors < -1)
                throw new RoomieRuntimeException("MaxErrors must be a positive (or 0, -1) integer.");

            device.Poll();

            var startPower = device.MultilevelSwitch.Power;
            var currentPower = startPower;

            int numFails = 0;
            while (true)
            {
                System.Threading.Thread.Sleep(pollInterval);
                try
                {
                    device.Poll();

                    currentPower = device.MultilevelSwitch.Power;
                    if (currentPower != startPower)
                        return;
                }
                catch(HomeAutomationException e) //TODO: specialized timeout exception?
                {
                    interpreter.WriteEvent("fail");
                    numFails++;
                    if (maxErrors>=0
                        && numFails >= maxErrors)
                        throw new RoomieRuntimeException("HomeAutomation Error: " + e.Message);
                }
            }

            //WaitForChangeHelper helper = new WaitForChangeHelper(interpreter);
            //zWaveDevice.LevelChanged += new ControlThink.ZWave.Devices.ZWaveDevice.LevelChangedEventHandler(helper.zWaveDevice_LevelChanged);
            //helper.WaitUntilChange();
        }
예제 #32
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var filename       = context.ReadParameter("Filename").Value;
            var includeHeaders = context.ReadParameter("IncludeHeaders").ToBoolean();

            var device         = context.Device;
            var network        = device.Network;
            var networkContext = network.Context;
            var history        = networkContext.History;

            var deviceHistory = history.DeviceEvents
                                .FilterEntity(device)
                                .FilterType(new DevicePowerSensorValueChanged());

            var converter = new Converter();
            var writer    = new CsvWriter <IDeviceEvent>(converter);

            writer.Write(filename, deviceHistory, includeHeaders);
        }
예제 #33
0
파일: Toggle.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            if (device.BinarySwitch.Power == null)
            {
                device.Poll();
            }

            switch (device.BinarySwitch.Power)
            {
                case BinarySwitchPower.On:
                    device.BinarySwitch.SetPower(BinarySwitchPower.Off);
                    break;

                    case BinarySwitchPower.Off:
                    device.BinarySwitch.SetPower(BinarySwitchPower.On);
                    break;
            }
        }
예제 #34
0
파일: Toggle.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            if (device.BinarySwitch.Power == null)
            {
                device.Poll();
            }

            switch (device.BinarySwitch.Power)
            {
            case BinarySwitchPower.On:
                device.BinarySwitch.SetPower(BinarySwitchPower.Off);
                break;

            case BinarySwitchPower.Off:
                device.BinarySwitch.SetPower(BinarySwitchPower.On);
                break;
            }
        }
예제 #35
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device       = context.Device as PiEngineeringDevice;
            var ledString    = context.ReadParameter("LED").Value;
            var statusString = context.ReadParameter("Status").Value;

            Led led;

            if (!Enum.TryParse(ledString, out led))
            {
                throw new RoomieRuntimeException("LED \"" + ledString + "\" is not valid");
            }

            LightStatus status;

            if (!Enum.TryParse(statusString, out status))
            {
                throw new RoomieRuntimeException("Status \"" + statusString + "\" is not valid");
            }

            device.SetLeds(led, status);
        }
예제 #36
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device as PiEngineeringDevice;

            device.Reconnect();
        }
예제 #37
0
파일: PowerOff.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            device.BinarySwitch.SetPower(BinarySwitchPower.Off);
        }
예제 #38
0
파일: PowerOn.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            device.BinarySwitch.SetPower(BinarySwitchPower.On);
        }
예제 #39
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            device.IlluminanceSensor.Poll();
        }
예제 #40
0
파일: PollDevice.cs 프로젝트: Mavtak/roomie
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var device = context.Device;

            device.Poll();
        }