public MainWindow() { InitializeComponent(); Slider.IsEnabled = false; OffButton.IsEnabled = false; OnButton.IsEnabled = false; NightButton.IsEnabled = false; _config = EnvironmentConfig.Load(); _smartHub = new SmartHub { Environment = _config, LightAdapters = new List <ILightAdapter> { new HueLightAdapter() }, SensorAdapters = new List <ISensorAdapter> { new HueSensorAdapater() } }; LoadRooms(); _isActive = true; _workerThread = new Thread(AsyncUpdate); _workerThread.Start(); }
static void Main(string[] args) { var smartHub = new SmartHub { Environment = EnvironmentConfig.Load(), LightAdapters = new List <ILightAdapter> { new HueLightAdapter() }, SensorAdapters = new List <ISensorAdapter> { new HueSensorAdapater() } }; HomeLogger.WriteLine("Loading rules"); string path = "rules.json"; if (!File.Exists(path)) { path = "../../../../config/rules.json"; if (!File.Exists(path)) { throw new Exception("Could not find rules!"); } } var rules = JsonConvert.DeserializeObject <Rule[]>(File.ReadAllText(path)); HomeLogger.WriteLine("Initializing smarthub"); smartHub.Initialize(); HomeLogger.WriteLine("Starting rule engine loop"); var ruleProcessor = new RuleProcessor(rules, smartHub); ruleProcessor.Run(); Console.ReadLine(); ruleProcessor.Stop(); }
static void Main(string[] args) { var smartHub = new SmartHub { Environment = EnvironmentConfig.Load(), LightAdapters = new List <ILightAdapter> { new HueLightAdapter() }, SensorAdapters = new List <ISensorAdapter> { new HueSensorAdapater() } }; smartHub.Initialize(); IList <ISmartLight> lights = smartHub.PollLights(); IList <ISmartSensor> sensors = smartHub.PollSensors(); foreach (ISmartLight light in lights) { light.State.On = false; light.State.Brightness = 199; smartHub.UpdateLight(light); } Thread.Sleep(5000); var lightState = new LightState { On = true, Brightness = 255, Saturation = 255, Hue = 0 }; smartHub.UpdateLightsInRooms(new [] { smartHub.Environment.Rooms[0].Id }, lightState); System.Console.ReadLine(); }