Example #1
0
    def testTurnOff_bothLightAndTimerOn_timerIsRenewed(self):
        self.lightItem.setState(scope.OnOffType.ON)
        self.light._startTimer(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.light._isTimerActive())

        self.light.turnOff(MockedEventDispatcher(scope.itemRegistry))
        self.assertFalse(self.light._isTimerActive())
Example #2
0
    def testOnSwitchTurnedOff_validParams_timerIsTurnedOn(self):
        self.lightItem.setState(scope.OnOffType.ON)
        self.light._startTimer(MockedEventDispatcher(scope.itemRegistry))

        isProcessed = self.light.onSwitchTurnedOff(
            MockedEventDispatcher(scope.itemRegistry),
            self.lightItem.getName())
        self.assertTrue(isProcessed)
        self.assertFalse(self.light._isTimerActive())
Example #3
0
    def setUp(self):
        scope.itemRegistry.remove(MOTION_SENSOR_SWITCH_NAME)

        self.motionSensorItem = SwitchItem(MOTION_SENSOR_SWITCH_NAME)
        scope.itemRegistry.add(self.motionSensorItem)

        self.motionSensorItem.setState(scope.OnOffType.OFF)

        self.motionSensor = MotionSensor(self.motionSensorItem)

        self.events = MockedEventDispatcher(scope.itemRegistry)
Example #4
0
class MotionSensorTest(unittest.TestCase):
    def setUp(self):
        scope.itemRegistry.remove(MOTION_SENSOR_SWITCH_NAME)

        self.motionSensorItem = SwitchItem(MOTION_SENSOR_SWITCH_NAME)
        scope.itemRegistry.add(self.motionSensorItem)

        self.motionSensorItem.setState(scope.OnOffType.OFF)

        self.motionSensor = MotionSensor(self.motionSensorItem)

        self.events = MockedEventDispatcher(scope.itemRegistry)

    def tearDown(self):
        scope.itemRegistry.remove(self.motionSensorItem.getName())

    def testIsOn_various_returnsExpected(self):
        self.events.sendCommand(self.motionSensorItem.getName(), "ON")
        self.assertTrue(self.motionSensor.isOn())

        self.events.sendCommand(self.motionSensorItem.getName(), "OFF")
        self.assertFalse(self.motionSensor.isOn())

    def testIsOccupied_various_returnsExpected(self):
        itemName = self.motionSensorItem.getName()

        self.events.sendCommand(itemName, "ON")
        self.motionSensor.onMotionSensorTurnedOn(self.events, itemName)
        self.assertTrue(self.motionSensor.isOccupied())

        self.events.sendCommand(self.motionSensorItem.getName(), "OFF")
        self.assertTrue(self.motionSensor.isOccupied())
Example #5
0
    def testTurnOn_lightWasAlreadyOn_timerIsRenewed(self):
        self.lightItem.setState(scope.OnOffType.ON)
        self.assertFalse(self.light._isTimerActive())

        self.light.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertEqual(scope.OnOffType.ON, self.lightItem.getState())
        self.assertTrue(self.light._isTimerActive())
Example #6
0
    def testTurnOn_lightWasOffWithinDimTimeRange_returnsExpected(self):
        timeStruct = time.localtime()
        hourOfDay = timeStruct[3]

        dimLevel = 5
        nextHour = 0 if hourOfDay == 23 else hourOfDay + 1  # 24-hour wrapping
        timeRanges = "{}-{}".format(hourOfDay, nextHour)
        self.dimmer = Dimmer(self.dimmerItem, 10, dimLevel, timeRanges)

        self.dimmer.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.dimmer.isOn())
        self.assertEqual(dimLevel, self.dimmerItem.getState().intValue())
        self.assertTrue(self.dimmer._isTimerActive())
Example #7
0
    def testTimerTurnedOff_validParams_switchIsOff(self):
        zm = ZoneManager()
        self.light = Light(self.lightItem, 0.004)  # makes it 0.24 sec
        self.light = self.light.setZoneManager(zm._createImmutableInstance())

        zone = Zone('ff', [self.light])
        zm.addZone(zone)

        self.lightItem.setState(scope.OnOffType.ON)
        self.light._startTimer(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.light._isTimerActive())

        time.sleep(0.3)
        self.assertFalse(self.light._isTimerActive())
        self.assertFalse(self.light.isOn())
Example #8
0
    def testTurnOn_lightWasOffOutsideDimTimeRange_returnsExpected(self):
        timeStruct = time.localtime()
        hourOfDay = timeStruct[3]

        if hourOfDay >= 22:  # handle 24-hour wrapping
            hourOfDay = 0

        dimLevel = 5
        timeRanges = "{}-{}".format(hourOfDay + 2, hourOfDay + 2)
        self.dimmer = Dimmer(self.dimmerItem, 10, dimLevel, timeRanges)

        self.dimmer.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.dimmer.isOn())
        self.assertEqual(100, self.dimmerItem.getState().intValue())
        self.assertTrue(self.dimmer._isTimerActive())
Example #9
0
 def testOnSwitchTurnedOff_invalidItemName_returnsFalse(self):
     isProcessed = self.light.onSwitchTurnedOff(
         MockedEventDispatcher(scope.itemRegistry), "wrong name")
     self.assertFalse(isProcessed)
Example #10
0
 def testTurnOn_lightWasOff_returnsExpected(self):
     self.light.turnOn(MockedEventDispatcher(scope.itemRegistry))
     self.assertEqual(scope.OnOffType.ON, self.lightItem.getState())
Example #11
0
    def testTurnOff_bothLightAndTimerOn_timerIsRenewed(self):
        self.dimmerItem.setState(PercentType(0))

        self.dimmer.turnOff(MockedEventDispatcher(scope.itemRegistry))
        self.assertFalse(self.dimmer.isOn())
Example #12
0
    def testTurnOn_lightWasAlreadyOn_timerIsRenewed(self):
        self.dimmerItem.setState(PercentType(100))

        self.dimmer.turnOn(MockedEventDispatcher(scope.itemRegistry))
        self.assertTrue(self.dimmer.isOn())
        self.assertTrue(self.dimmer._isTimerActive())