Ejemplo n.º 1
0
        public void ManualMowingBeforeIntervalStart_MowerReturnsDuringIntervalInWeb_NotMowingStarted()
        {
            // Arrange
            var systemTime = new TestSystemTime(2019, 8, 11, 22, 1, 0);
            var config     = TestFactory.NewConfig10To12And20To2359(
                usingContactHomeSensor: true);

            var logger = TestFactory.NewMowLogger(new DateTime(2019, 8, 11, 0, 0, 0));

            logger.LogItems.Add(new LogItem(new DateTime(2019, 8, 11, 0, 0, 0), LogType.PowerOn, LogLevel.Debug, ""));
            logger.LogItems.Add(new LogItem(new DateTime(2019, 8, 11, 19, 35, 0), LogType.MowerLeft, LogLevel.Debug, ""));
            logger.LogItems.Add(new LogItem(new DateTime(2019, 8, 11, 21, 35, 0), LogType.MowerLost, LogLevel.Debug, ""));

            var powerSwitch     = new TestPowerSwitch(PowerStatus.On);
            var weatherForecast = TestFactory.NewWeatherForecastGood(systemTime);
            var homeSensor      = new TestHomeSensor(systemTime,
                                                     isHome: true,
                                                     mowerLeftTime: new DateTime(2019, 8, 11, 19, 35, 0),
                                                     mowerCameTime: new DateTime(2019, 8, 11, 22, 1, 0));
            var rainSensor    = new TestRainSensor(isWet: true);
            var mowController = new MowController(config, powerSwitch, weatherForecast, systemTime, homeSensor, logger, rainSensor, mowerIsHome: false);

            // Act
            mowController.CheckAndAct();

            // Assert
            Assert.AreEqual(powerSwitch.Status, PowerStatus.On);

            var logItem = logger.LogItems.FirstOrDefault(x => x.Type == LogType.MowerCame);

            Assert.IsNotNull(logItem);

            logItem = logger.LogItems.FirstOrDefault(x => x.Type == LogType.MowingStarted);
            Assert.IsNull(logItem);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string path                = Directory.GetCurrentDirectory();
            var    serializer          = new XmlSerializer(typeof(MowitConfig));
            bool   simulatedHomeSensor = false;

            foreach (string arg in args)
            {
                if (arg == "/configexample")
                {
                    TextWriter textWriter = new StreamWriter(Path.Combine(path, "MowitSettings.xml.example"));
                    serializer.Serialize(textWriter, MowitConfig.GetExampleConfig());
                    textWriter.Flush();

                    return;
                }

                if (arg == "/simulatedcontacthomesensor")
                {
                    simulatedHomeSensor = true;
                }
            }

            TextReader textReader = new StreamReader(Path.Combine(path, "MowitSettings.xml"));

            Config = (MowitConfig)serializer.Deserialize(textReader);

            Console.WriteLine("Press ENTER to start the Mowit service.");
            Console.ReadLine();

            EmailSender.Init(Config.EmailConfig);

            var         systemTime  = new SystemTime();
            var         powerSwitch = new UrlPowerSwitch(Config.MowControlConfig.PowerOnUrl, Config.MowControlConfig.PowerOffUrl);
            IHomeSensor homeSensor;

            if (simulatedHomeSensor)
            {
                homeSensor = new SimulatedContactHomeSensor(systemTime, Config.MowControlConfig.TimeIntervals.ToArray(), powerSwitch);
            }
            else
            {
                homeSensor = new TimeBasedHomeSensor(systemTime.Now, Config.MowControlConfig, powerSwitch, systemTime);
            }

            Smhi smhi            = new Smhi(Config.MowControlConfig.CoordLat, Config.MowControlConfig.CoordLon, new TimeSpan(1, 0, 0));
            var  weatherForecast = new WeatherForecast(smhi, Config.MowControlConfig.MaxHourlyThunderPercent, Config.MowControlConfig.MaxHourlyPrecipitaionMillimeter, Config.MowControlConfig.MaxRelativeHumidityPercent);

            var logger = new MowLogger();

            logger.LogItemWritten += Logger_LogItemWritten;

            var rainSensor    = new SmhiRainSensor(systemTime, smhi);
            var mowController = new MowController(Config.MowControlConfig, powerSwitch, weatherForecast, systemTime, homeSensor, logger, rainSensor);
            var task          = mowController.StartAsync();

            task.Wait();
        }
Ejemplo n.º 3
0
        private static void RunOverTime(MowController mowController, TestSystemTime systemTime, int hours, int minutes)
        {
            minutes = hours * 60 + minutes;

            for (int i = 0; i < minutes * 2; i++)
            {
                mowController.CheckAndAct();
                systemTime.TickSeconds(30);
            }
        }