Exemplo n.º 1
0
 def testStringToTimeRangeLists_multipleRanges_returnsExpected(self):
     list = time_utilities.stringToTimeRangeLists(
         "7:10 - 8:30, 9, 13 - 15, 16-17:30")
     self.assertEqual(4, len(list))
     self.assertEqual([7, 10, 8, 30], list[0])
     self.assertEqual([9, 0, 9, 59], list[1])
     self.assertEqual([13, 0, 15, 0], list[2])
     self.assertEqual([16, 0, 17, 30], list[3])
Exemplo n.º 2
0
    def __init__(self,
                 switchItem,
                 durationInMinutes,
                 dimLevel=5,
                 timeRanges=None,
                 illuminanceLevel=None,
                 disableTrigeringFromMotionSensor=False,
                 noPrematureTurnOffTimeRange=None):
        '''
        Constructs a new object.

        :raise ValueError: if any parameter is invalid
        '''
        Light.__init__(self, switchItem, durationInMinutes, illuminanceLevel,
                       disableTrigeringFromMotionSensor,
                       noPrematureTurnOffTimeRange)

        if dimLevel < 0 or dimLevel > 100:
            raise ValueError('dimLevel must be between 0 and 100 inclusive')

        time_utilities.stringToTimeRangeLists(timeRanges)  # validate

        self.dimLevel = dimLevel
        self.timeRanges = timeRanges
Exemplo n.º 3
0
    def testStringToTimeRangeLists_noRange_throwsError(self):
        with self.assertRaises(ValueError) as cm:
            time_utilities.stringToTimeRangeLists('')

        self.assertEqual('Must have at least one time range.',
                         cm.exception.args[0])
Exemplo n.º 4
0
 def testStringToTimeRangeLists_wrapAroundHour_returnsExpected(self):
     list = time_utilities.stringToTimeRangeLists("21 - 7")
     self.assertEqual(1, len(list))
     self.assertEqual([21, 0, 7, 0], list[0])
Exemplo n.º 5
0
 def testStringToTimeRangeLists_oneRangeWithDiffHourMinutes_returnsExpected(
         self):
     list = time_utilities.stringToTimeRangeLists("7:10 - 12:30")
     self.assertEqual(1, len(list))
     self.assertEqual([7, 10, 12, 30], list[0])
Exemplo n.º 6
0
 def testStringToTimeRangeLists_oneRangeWithSameHourNoMinutes_returnsExpected(
         self):
     list = time_utilities.stringToTimeRangeLists("7")
     self.assertEqual(1, len(list))
     self.assertEqual([7, 0, 7, 59], list[0])
Exemplo n.º 7
0
    def testStringToTimeRangeLists_invalidMinute_throwsError(self):
        with self.assertRaises(ValueError) as cm:
            time_utilities.stringToTimeRangeLists('7 - 8:60')

        self.assertEqual('Minute must be between 0 and 59 inclusive.',
                         cm.exception.args[0])
Exemplo n.º 8
0
    def testStringToTimeRangeLists_invalidHour_throwsError(self):
        with self.assertRaises(ValueError) as cm:
            time_utilities.stringToTimeRangeLists('24')

        self.assertEqual('Hour must be between 0 and 23 inclusive.',
                         cm.exception.args[0])
Exemplo n.º 9
0
    def testStringToTimeRangeLists_wrongFormat_throwsError(self):
        with self.assertRaises(ValueError) as cm:
            time_utilities.stringToTimeRangeLists('9, 3:2:3-5')

        self.assertEqual('Must be in format "HH" or "HH:MM".',
                         cm.exception.args[0])