Ejemplo n.º 1
0
 def test_target_temperature(self):
     fill_timetable(self.timetable)
     
     time = datetime(2016,2,14,17,23,0)
     day = time.strftime('%w')
     hour = timetable.json_format_hour(time.hour)
     quarter = int(time.minute // 15)
     
     self.assertAlmostEqual(self.timetable.target_temperature(time), self.timetable.tmax, delta=0.01)
     t = 45.0
     self.timetable.update(day, hour, quarter, t)
     self.assertAlmostEqual(self.timetable.target_temperature(time), t, delta=0.01)
     
     self.assertAlmostEqual(self.timetable.target_temperature(datetime(2016,2,10,9,34,0)), self.timetable.tmin, delta=0.01)
     self.assertAlmostEqual(self.timetable.target_temperature(datetime(2016,2,10,23,34,0)), self.timetable.t0, delta=0.01)
     
     self.timetable.mode = timetable.JSON_MODE_ON
     self.assertEqual(self.timetable.target_temperature(time), None)
     
     self.timetable.mode = timetable.JSON_MODE_OFF
     self.assertEqual(self.timetable.target_temperature(time), None)
     
     self.timetable.mode = timetable.JSON_MODE_TMAX
     self.assertAlmostEqual(self.timetable.target_temperature(time), self.timetable.tmax, delta=0.01)
     
     self.timetable.mode = timetable.JSON_MODE_TMIN
     self.assertAlmostEqual(self.timetable.target_temperature(time), self.timetable.tmin, delta=0.01)
     
     self.timetable.mode = timetable.JSON_MODE_T0
     self.assertAlmostEqual(self.timetable.target_temperature(time), self.timetable.t0, delta=0.01)
Ejemplo n.º 2
0
 async def test_timetable_06c(self):  # the same of test 06 with inertia==3
     fill_timetable(self.timetable)
     self.timetable._inertia = 3
     
     now = datetime.now()
     day = now.strftime('%w')
     hour = timetable.json_format_hour(now.hour)
     quarter = int(now.minute // 15)
     
     self.timetable.mode = timetable.JSON_MODE_AUTO
     self.timetable.update(day,hour,quarter,timetable.JSON_TMAX_STR)
     
     # check if the heating should be on
     self.assertTrue(self.timetable.should_the_heating_be_on(19, await self.heating.status))
     
     # virtually switching on and set internal state
     await self.heating.switch_on()
     
     # the temperature start increasing
     self.assertTrue(self.timetable.should_the_heating_be_on(19.5, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(20.0, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(20.4, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(20.5, await self.heating.status))  # off at target-diff
     self.assertFalse(self.timetable.should_the_heating_be_on(21.0, await self.heating.status))
     
     # virtually switching off and set internal state
     await self.heating.switch_off()
     
     # the temperature start decreasing
     self.assertFalse(self.timetable.should_the_heating_be_on(21.0, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(20.5, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(20.1, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(20.0, await self.heating.status))  # on at target-2*diff
     self.assertTrue(self.timetable.should_the_heating_be_on(19.5, await self.heating.status))
Ejemplo n.º 3
0
 async def test_timetable_09(self):
     fill_timetable(self.timetable)
     
     now = datetime.now()
     day = now.strftime('%w')
     hour = timetable.json_format_hour(now.hour)
     quarter = int(now.minute // 15)
     
     self.timetable.mode = timetable.JSON_MODE_AUTO
     self.timetable.update(day,hour,quarter,timetable.JSON_TMAX_STR)
     await self.heating.switch_on()
     
     # The heating is on and it remains on untill target temperature
     # plus differential
     self.assertTrue(self.timetable.should_the_heating_be_on(21.1, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(21.4, await self.heating.status))
     
     # I simulate the time passing by changing the target temperature
     # next quarter is tmin
     self.timetable.update(day,hour,quarter,timetable.JSON_TMIN_STR)
     self.assertFalse(self.timetable.should_the_heating_be_on(21, await self.heating.status))
     await self.heating.switch_off()
     
     # Next quarter is tmax again, the heating remains off until target minus differential
     self.timetable.update(day,hour,quarter,timetable.JSON_TMAX_STR)
     self.assertFalse(self.timetable.should_the_heating_be_on(21, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(20.6, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(20.5, await self.heating.status))
Ejemplo n.º 4
0
 async def test_timetable_04(self):  # test on/off modes
     fill_timetable(self.timetable)
     
     now = datetime.now()
     day = now.strftime('%w')
     hour = timetable.json_format_hour(now.hour)
     quarter = int(now.minute // 15)
     
     self.timetable.mode = timetable.JSON_MODE_ON
     self.timetable.update(day,hour,quarter,timetable.JSON_TMAX_STR)
     self.assertTrue(self.timetable.should_the_heating_be_on(3, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(10, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(20, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(22, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(25, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(30, await self.heating.status))
     
     self.timetable.mode = timetable.JSON_MODE_OFF
     self.timetable.update(day,hour,quarter,timetable.JSON_TMAX_STR)
     self.assertFalse(self.timetable.should_the_heating_be_on(3, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(10, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(20, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(22, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(25, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(30, await self.heating.status))
Ejemplo n.º 5
0
 def test_locale(self):
     # setlocale doesn't work on Windows
     if os.name == 'posix':
         locale.setlocale(locale.LC_ALL,'it_IT.utf8')
         
         fill_timetable(self.timetable)
         
         self.assertIsNone(self.timetable.update('Lun',10,1,30))
         self.assertIsNone(self.timetable.update('mer',11,2,20))
         settings = self.timetable.__getstate__()
         
         day = timetable.json_get_day_name(1)
         hour = timetable.json_format_hour(10)
         quarter = 1
         t1 = timetable.temperature_to_float(settings[timetable.JSON_TIMETABLE][day][hour][quarter])
         t2 = timetable.temperature_to_float(30)
         self.assertEqual(t1, t2)
 
         day = timetable.json_get_day_name(3)
         hour = timetable.json_format_hour(11)
         quarter = 2
         t1 = timetable.temperature_to_float(settings[timetable.JSON_TIMETABLE][day][hour][quarter])
         t2 = timetable.temperature_to_float(20)
         self.assertEqual(t1, t2)
Ejemplo n.º 6
0
 async def test_timetable_05(self):  # test auto mode
     fill_timetable(self.timetable)
     
     now = datetime.now()
     day = now.strftime('%w')
     hour = timetable.json_format_hour(now.hour)
     quarter = int(now.minute // 15)
     
     self.timetable.mode = timetable.JSON_MODE_AUTO
     
     # current target t0
     self.timetable.update(day,hour,quarter,timetable.JSON_T0_STR)
     self.assertTrue(self.timetable.should_the_heating_be_on(3, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(10, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(20, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(22, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(25, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(30, await self.heating.status))
     
     # current target tmin
     self.timetable.update(day,hour,quarter,timetable.JSON_TMIN_STR)
     self.assertTrue(self.timetable.should_the_heating_be_on(3, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(10, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(20, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(22, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(25, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(30, await self.heating.status))
     
     # current target tmax
     self.timetable.update(day,hour,quarter,timetable.JSON_TMAX_STR)
     self.assertTrue(self.timetable.should_the_heating_be_on(3, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(10, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(20, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(22, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(25, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(30, await self.heating.status))
     
     # current target manual temperature
     self.timetable.update(day,hour,quarter,27.5)
     self.assertTrue(self.timetable.should_the_heating_be_on(3, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(10, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(20, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(22, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(25, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(30, await self.heating.status))
Ejemplo n.º 7
0
 async def test_timetable_06_cooling(self):  # # the same of test 06 with hvac_mode==cooling
     fill_timetable(self.timetable)
     
     now = datetime.now()
     day = now.strftime('%w')
     hour = timetable.json_format_hour(now.hour)
     quarter = int(now.minute // 15)
     
     self.timetable.mode = timetable.JSON_MODE_AUTO
     self.timetable.hvac_mode = HVAC_COOLING
     self.timetable.tmax = 30
     self.timetable.tmin = 24
     self.timetable.update(day,hour,quarter,timetable.JSON_TMIN_STR)  # tmin mean 'off' even for cooling
     
     # the cooling should be on if current temp above tmax
     self.assertTrue(self.timetable.should_the_heating_be_on(31, await self.heating.status))
     
     # the cooling should be off for tmin in auto mode
     self.assertFalse(self.timetable.should_the_heating_be_on(25, await self.heating.status))
     
     # the cooling should be on now
     self.timetable.update(day,hour,quarter,timetable.JSON_TMAX_STR)  # tmax mean 'on' even for cooling
     self.assertTrue(self.timetable.should_the_heating_be_on(25, await self.heating.status))
     
     # virtually switching on and set internal state
     await self.heating.switch_on()
     
     # the temperature start decreasing
     self.assertTrue(self.timetable.should_the_heating_be_on(24.8, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(24.5, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(24.2, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(23.9, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(23.4, await self.heating.status))
     
     # virtually switching off and set internal state
     await self.heating.switch_off()
     
     # the temperature start increasing
     self.assertFalse(self.timetable.should_the_heating_be_on(23.7, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(24.0, await self.heating.status))
     self.assertFalse(self.timetable.should_the_heating_be_on(24.4, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(24.9, await self.heating.status))
     self.assertTrue(self.timetable.should_the_heating_be_on(25.1, await self.heating.status))
Ejemplo n.º 8
0
 async def test_timetable_03(self):  # test tmax mode
     fill_timetable(self.timetable)
     
     now = datetime.now()
     day = now.strftime('%w')
     hour = timetable.json_format_hour(now.hour)
     quarter = int(now.minute // 15)
     
     self.timetable.mode = timetable.JSON_MODE_TMAX
     self.timetable.update(day,hour,quarter,timetable.JSON_T0_STR)
     
     for temp in range(10,21):
         self.assertTrue(self.timetable.should_the_heating_be_on(temp, await self.heating.status))
     
     # Not testing temp equal to tmax (21 degrees) because the result
     # depends by both differential and `ison` internal state.
     
     for temp in range(22,27):
         self.assertFalse(self.timetable.should_the_heating_be_on(temp, await self.heating.status))