Пример #1
0
        public Program(ConsoleLogger logger)
        {
            _smartHub = new SmartHub(logger, new List <ISmartHouseFramework> {
                new ZWaveFramework()
            }, new FileStorage <DeviceWrapper>("DeviceWrappers.txt"));

            _smartHub.SaveDeviceWrappers();

            foreach (var smartLifeDeviceWrapper in _smartHub.DeviceWrappers.Where(x => x.Device is UnknownDevice))
            {
                logger.Log($"Found a unknown device! {smartLifeDeviceWrapper.DeviceId} {smartLifeDeviceWrapper.Device}");
            }

            var zone = _smartHub.Zones.Where(x => x.Key == "#1").SelectMany(x => x.Value).Select(x => x.Device);

            var powerPlug    = zone.FirstOrDefault(x => x is ISwitch);
            var motionSensor = zone.FirstOrDefault(x => x is IMotionSensor);

            if (powerPlug != null && motionSensor != null)
            {
                _smartHub.AddOperation(new TemperatureSensorPowerPlug((ITemperatureMeasure)motionSensor, (ISwitch)powerPlug, 18));

                //var plugs = _smartHub.DeviceWrappers.Where(x => !x.Zones.Any()).Where(x => x is ILedRing).Select(x => x.Device).ToList();
                //_smartHub.AddOperation(new LuxSensorPowerPlugs((ILuxMeasure)motionSensor, plugs));
            }

            var temp = _smartHub.DeviceWrappers.Select(x => x.Device).Where(x => x is IColorLight);

            foreach (var device in temp)
            {
                _bulbs.Add((IColorLight)device);
            }
        }
Пример #2
0
        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();
        }
Пример #3
0
        private void Initialize(ConsoleLogger logger)
        {
            var zwave = new ZWaveFramework();

            _smartHub = new SmartHub(logger, new List <ISmartHouseFramework> {
                zwave
            }, new FileStorage <DeviceWrapper>("DeviceWrappers.txt"));
        }
Пример #4
0
        public RuleProcessor(Rule[] rules, SmartHub smartHub)
        {
            _workerThread = new Thread(UpdateLoop);

            _rules    = rules;
            _smartHub = smartHub;

            InitializeMaps();
        }
Пример #5
0
        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();
        }
Пример #6
0
        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();
        }