def test_blind_situation(self, datetime_mock): datetime_mock.datetime.now = Mock( return_value=datetime.datetime.strptime('Aug 26 2017 19:54', '%b %d %Y %H:%M')) blind = Blind( elevation=11, azimuth=290, azimuth_entry=256, azimuth_exit=359, wind_lock=False, window_open=False, lux_last_10_minutes=61000, outside_temperature=30, inside_temperature=25.2, ) s = blind.blind_hysteresis.status_update(61421, 10, 11) self.assertEqual(s, True) s = blind.blind_hysteresis.status_update(23421, 10, 11) self.assertEqual(s, True) s = blind.blind_hysteresis.status_update(20148, 9, 8) self.assertEqual(s, True) s = blind.blind_hysteresis.status_update(14300, 10, 11) self.assertEqual(s, False) blind.Control() self.assertEqual(blind.desired_position_reason, "Sun hits the window, closing blind") blind.SetLux(23421) blind.SetElevation(10) r = blind.Control() datetime_mock.datetime.now = Mock( return_value=datetime.datetime.strptime('Aug 26 2017 19:58', '%b %d %Y %H:%M')) self.assertEqual(blind.desired_position_reason, "Sun hits the window, closing blind") blind.SetLux(23421) blind.SetLux(20148) blind.SetElevation(9) r = blind.Control() datetime_mock.datetime.now = Mock( return_value=datetime.datetime.strptime('Aug 26 2017 20:00', '%b %d %Y %H:%M')) self.assertEqual(blind.desired_position_reason, "Sun hits the window, closing blind") blind.SetLux(14300) blind.SetElevation(8) r = blind.Control() self.assertEqual(blind.desired_position_reason, "Blinds go up, there is not enough sun")
def test_hysteresis(self): blind = Blind( elevation=40, azimuth=176, azimuth_entry=173, azimuth_exit=270, wind_lock=False, window_open=False, lux_last_10_minutes=70000, outside_temperature=30, inside_temperature=27, ) blind.Control() self.compare(blind, Blind.DOWN, 80, 'Sun hits the window, closing blind') # Hysteresis should detect that this is still too much sun, should still be down. blind.SetLux(30000) blind.Control() self.compare(blind, Blind.DOWN, 80, 'Sun hits the window, closing blind') # hysteresis should detect that this is still too warm, although the limit is 24 degrees. blind.SetInsideTemperature(24.6) print(blind.inside_temperature) print( blind.temperature_hysteresis.status_update( blind.inside_temperature)) blind.Control() self.compare(blind, Blind.DOWN, 80, 'Sun hits the window, closing blind') # now this is not enough sun anymore. blind.SetLux(10000) blind.Control() self.compare(blind, Blind.UP, Blind.UP, 'Blinds go up, there is not enough sun') blind.SetElevation(13) blind.SetLux(29498) blind.Control()