public void IsHome_FirstCheck_IsHome()
        {
            // Arrange
            var timeIntervals = new List <TimeInterval>();

            timeIntervals.Add(new TimeInterval(6, 0, 12, 0));

            var config = new MowControlConfig()
            {
                TimeIntervals                   = timeIntervals,
                AverageWorkPerDayHours          = 12,
                MaxHourlyThunderPercent         = 0,
                MaxHourlyPrecipitaionMillimeter = 0
            };

            var systemTime      = new TestSystemTime(new DateTime(2018, 6, 22, 6, 30, 0));
            var powerSwitch     = new TestPowerSwitch(true);
            var systemStartTime = systemTime.Now;

            var homeSensor = new TimeBasedHomeSensor(systemStartTime, config, powerSwitch, systemTime);

            // Act
            bool isHome = homeSensor.IsHome;

            // Assert
            Assert.IsTrue(isHome);
        }
        public void IsHome_EnoughTimeSinceYesterdaysInterval_IsHome()
        {
            // Arrange
            var timeIntervals = new List <TimeInterval>();

            timeIntervals.Add(new TimeInterval(18, 0, 23, 59));

            var config = new MowControlConfig()
            {
                TimeIntervals                   = timeIntervals,
                AverageWorkPerDayHours          = 12,
                MaxHourlyThunderPercent         = 0,
                MaxHourlyPrecipitaionMillimeter = 0
            };
            var systemTime      = new TestSystemTime(new DateTime(2018, 6, 22, 1, 00, 0));
            var powerSwitch     = new TestPowerSwitch(true);
            var systemStartTime = systemTime.Now.AddDays(-1);

            var homeSensor = new TimeBasedHomeSensor(systemStartTime, config, powerSwitch, systemTime);

            // Act

            // Assert
            Assert.IsTrue(homeSensor.IsHome);
        }
        public void IsHome_JustStoppedMowingAndOnItsWayHome_IsNotHome()
        {
            // Arrange
            var timeIntervals = new List <TimeInterval>();

            timeIntervals.Add(new TimeInterval(6, 0, 12, 0));

            var config = new MowControlConfig()
            {
                TimeIntervals                   = timeIntervals,
                AverageWorkPerDayHours          = 12,
                MaxHourlyThunderPercent         = 0,
                MaxHourlyPrecipitaionMillimeter = 0
            };
            var systemTime      = new TestSystemTime(new DateTime(2018, 6, 22, 12, 15, 0));
            var powerSwitch     = new TestPowerSwitch(true);
            var systemStartTime = systemTime.Now.AddDays(-1);
            var homeSensor      = new TimeBasedHomeSensor(systemStartTime, config, powerSwitch, systemTime);

            // Act
            bool isHome = homeSensor.IsHome; // First is always true

            // Assert
            Assert.IsFalse(isHome);
        }
        public void IsHome_AfterAnIntervalWithPowerOff_IsStillHome()
        {
            // Arrange
            var timeIntervals = new List <TimeInterval>();

            timeIntervals.Add(new TimeInterval(6, 0, 12, 0));

            var config = new MowControlConfig()
            {
                TimeIntervals                   = timeIntervals,
                AverageWorkPerDayHours          = 12,
                MaxHourlyThunderPercent         = 0,
                MaxHourlyPrecipitaionMillimeter = 0
            };

            var systemTime      = new TestSystemTime(new DateTime(2018, 6, 22, 11, 59, 0));
            var powerSwitch     = new TestPowerSwitch(false);
            var systemStartTime = systemTime.Now.AddDays(-1);
            var homeSensor      = new TimeBasedHomeSensor(systemStartTime, config, powerSwitch, systemTime);

            var isHome = homeSensor.IsHome;

            systemTime.TickMinutes(2);
            powerSwitch.TurnOn();

            // Act
            isHome = homeSensor.IsHome;

            // Assert
            Assert.IsTrue(isHome);
        }
Beispiel #5
0
        public void IsWet_LightRainSixHoursAgo_Dry()
        {
            // Assign
            var systemTime = new TestSystemTime(2018, 8, 13, 18, 0);

            // Forecasted weather
            var smhi = new TestSmhi(systemTime, new ForecastTimeSerie[]
            {
                NewTimeSerie(new DateTime(2018, 8, 13, 18, 0, 0), precipitationMax: 0m, relativeHumidity: 45),
            });

            // Past weather
            var rainSensor = new SmhiRainSensor(systemTime, smhi, new ForecastTimeSerie[] {
                NewTimeSerie(new DateTime(2018, 8, 13, 12, 0, 0), precipitationMax: 0.1m, relativeHumidity: 40),
                NewTimeSerie(new DateTime(2018, 8, 13, 13, 0, 0), precipitationMax: 0m, relativeHumidity: 40),
                NewTimeSerie(new DateTime(2018, 8, 13, 14, 0, 0), precipitationMax: 0m, relativeHumidity: 40),
                NewTimeSerie(new DateTime(2018, 8, 13, 15, 0, 0), precipitationMax: 0m, relativeHumidity: 40),
                NewTimeSerie(new DateTime(2018, 8, 13, 16, 0, 0), precipitationMax: 0m, relativeHumidity: 40),
                NewTimeSerie(new DateTime(2018, 8, 13, 17, 0, 0), precipitationMax: 0m, relativeHumidity: 40),
            });

            // Act
            bool isWet = rainSensor.IsWet;

            // Assert
            Assert.IsFalse(isWet);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void IsWet_NotRainButHighHumidityDuringNight_Wet()
        {
            // Assign
            var systemTime = new TestSystemTime(2018, 8, 14, 6, 0);

            // Forecasted weather
            var smhi = new TestSmhi(systemTime, new ForecastTimeSerie[]
            {
                NewTimeSerie(new DateTime(2018, 8, 14, 6, 0, 0), precipitationMax: 0m, relativeHumidity: 70),
            });

            // Past weather
            var rainSensor = new SmhiRainSensor(systemTime, smhi, new ForecastTimeSerie[] {
                NewTimeSerie(new DateTime(2018, 8, 13, 12, 22, 0), precipitationMax: 0m, relativeHumidity: 80),
                NewTimeSerie(new DateTime(2018, 8, 13, 13, 23, 0), precipitationMax: 0, relativeHumidity: 85),
                NewTimeSerie(new DateTime(2018, 8, 14, 14, 0, 0), precipitationMax: 0, relativeHumidity: 90),
                NewTimeSerie(new DateTime(2018, 8, 14, 15, 1, 0), precipitationMax: 0, relativeHumidity: 95),
                NewTimeSerie(new DateTime(2018, 8, 14, 16, 2, 0), precipitationMax: 0, relativeHumidity: 99),
                NewTimeSerie(new DateTime(2018, 8, 14, 17, 3, 0), precipitationMax: 0, relativeHumidity: 98),
                NewTimeSerie(new DateTime(2018, 8, 14, 17, 4, 0), precipitationMax: 0m, relativeHumidity: 95),
                NewTimeSerie(new DateTime(2018, 8, 14, 17, 5, 0), precipitationMax: 0m, relativeHumidity: 90),
            });

            // Act
            bool isWet = rainSensor.IsWet;

            // Assert
            Assert.IsTrue(isWet);
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        public void IsWet_CurrentlyRaining_Wet()
        {
            // Assign
            var systemTime = new TestSystemTime(2018, 8, 13, 8, 0);

            // Forecasted weather
            var smhi = new TestSmhi(systemTime, new ForecastTimeSerie[]
            {
                NewTimeSerie(new DateTime(2018, 8, 13, 8, 0, 0), precipitationMax: 0.2m, relativeHumidity: 65),
            });

            // Past weather
            var rainSensor = new SmhiRainSensor(systemTime, smhi, new ForecastTimeSerie[] {});

            // Act
            bool isWet = rainSensor.IsWet;

            // Assert
            Assert.IsTrue(isWet);
        }
Beispiel #10
0
        public void IsWet_HeavyRainAnHourAgo_StillWet()
        {
            // Assign
            var systemTime = new TestSystemTime(2018, 8, 13, 8, 0);

            // Forecasted weather
            var smhi = new TestSmhi(systemTime, new ForecastTimeSerie[]
            {
                NewTimeSerie(new DateTime(2018, 8, 13, 8, 0, 0), precipitationMax: 0m, relativeHumidity: 69),
            });

            // Past weather
            var rainSensor = new SmhiRainSensor(systemTime, smhi, new ForecastTimeSerie[] {
                NewTimeSerie(new DateTime(2018, 8, 13, 7, 0, 0), precipitationMax: 1.5m, relativeHumidity: 75),
            });

            // Act
            bool isWet = rainSensor.IsWet;

            // Assert
            Assert.IsTrue(isWet);
        }
Beispiel #11
0
        public void IsWet_SmhiReportsWeatherThatLaterChanges_FirstWetThenNotWet()
        {
            // Assign
            var systemTime = new TestSystemTime(2018, 8, 14, 5, 0);

            // Forecasted weather
            var smhi = new TestSmhi(systemTime, new ForecastTimeSerie[]
            {
                NewTimeSerie(new DateTime(2018, 8, 14, 5, 0, 0), precipitationMax: 0.5m, relativeHumidity: 45),
            });

            // Past weather
            var rainSensor = new SmhiRainSensor(systemTime, smhi, new ForecastTimeSerie[] {
                NewTimeSerie(new DateTime(2018, 8, 14, 5, 0, 0), precipitationMax: 0m, relativeHumidity: 50),
            });

            // Act
            bool isWet = rainSensor.IsWet;

            // Assert
            Assert.IsTrue(isWet);
        }