protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device; var color = context.ReadParameter("Color").ToColor(); device.ColorSwitch.SetValue(color); }
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); }
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); }
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); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device; var fanMode = context.ReadParameter("FanMode").ToThermostatFanMode(); device.Thermostat.Fan.SetMode(fanMode); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device; var mode = context.ReadParameter("ThermostatMode").ToThermostatMode(); device.Thermostat.Core.SetMode(mode); }
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); }
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); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device; var power = context.ReadParameter("Power").ToInteger(); device.MultilevelSwitch.SetPower(power); }
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); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device as Q42HueDevice; var command = new LightCommand { Effect = Effect.ColorLoop, }; device.SendCommand(command); }
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); }
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; }
//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(); }
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"); }
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); }
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(); } }
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); }
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()); }
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 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); }
//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(); }
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); }
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; } }
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); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device as PiEngineeringDevice; device.Reconnect(); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device; device.BinarySwitch.SetPower(BinarySwitchPower.Off); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device; device.BinarySwitch.SetPower(BinarySwitchPower.On); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device; device.IlluminanceSensor.Poll(); }
protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context) { var device = context.Device; device.Poll(); }