def test_light_photocell_intial(self): motion = Motion() motion.still() photo = Photocell(address="asdf") photo.dark() light = Light(address="e3", devices=(photo, motion), initial_state=photo) self.assertEqual(light.state, State.ON)
def test_light_photocell_intial(self): motion = Motion() motion.still() photo = Photocell(address='asdf') photo.dark() light = Light( address='e3', devices=(photo, motion), initial=photo, ) self.assertEqual(light.state, State.ON)
def test_delay_light_specific(self): # Motion.Still and Photocell.Light events do not retrigger motion = Motion() light = Light(address="D1", devices=(self.interface, motion), delay_off=3) motion.motion() self.assertEqual(light.state, State.ON) time.sleep(2) motion.still() self.assertEqual(light.state, State.ON) time.sleep(1) self.assertEqual(light.state, State.OFF)
def test_delay_non_native_command(self): m = Motion() l = Light(devices=m, delay={ Attribute.COMMAND: Command.STILL, Attribute.SECS: 2, }, initial=State.ON) self.assertEqual(l.state, State.ON) m.still() self.assertEqual(l.state, State.ON) time.sleep(3) self.assertEqual(l.state, State.OFF)
def test_delay_non_native_command(self): m = Motion() l = Light( devices=m, delay={ Attribute.COMMAND: Command.STILL, Attribute.SECS: 2, }, initial=State.ON ) self.assertEqual(l.state, State.ON) m.still() self.assertEqual(l.state, State.ON) time.sleep(3) self.assertEqual(l.state, State.OFF)
def test_light_idle(self): m = Motion() m.still() l = Light(devices=(m), idle={ Attribute.MAPPED: (Command.LEVEL, 30), Attribute.SECS: 2, }) l.on() self.assertEqual(l.state, State.ON) time.sleep(3) self.assertEqual(l.state, (State.LEVEL, 30)) #Light shouldnt idle if it is off l.off() self.assertEqual(l.state, State.OFF) time.sleep(3) self.assertEqual(l.state, State.OFF)
def test_light_idle(self): m = Motion() m.still() l = Light( devices=(m), idle={Attribute.MAPPED: (Command.LEVEL, 30), Attribute.SECS: 2, } ) l.on() self.assertEqual(l.state, State.ON) time.sleep(3) self.assertEqual(l.state, (State.LEVEL, 30)) #Light shouldnt idle if it is off l.off() self.assertEqual(l.state, State.OFF) time.sleep(3) self.assertEqual(l.state, State.OFF)
def test_delay_light_specific(self): # motion.off and Photocell.Light events do not retrigger motion = Motion() light = Light(address='D1', devices=(self.interface, motion), trigger={ Attribute.COMMAND: Command.ON, Attribute.MAPPED: Command.OFF, Attribute.SECS: 3, }, ignore={ Attribute.COMMAND: Command.STILL, Attribute.SOURCE: motion, }) motion.motion() self.assertEqual(light.state, State.ON) time.sleep(2) motion.still() self.assertEqual(light.state, State.ON) time.sleep(1) self.assertEqual(light.state, State.OFF)
def test_delay_light_specific(self): # motion.off and Photocell.Light events do not retrigger motion = Motion() light = Light(address='D1', devices=(self.interface, motion), trigger={ 'command': Command.ON, 'mapped': Command.OFF, 'secs': 3, }, ignore={ 'command': Command.STILL, 'source': motion, } ) motion.motion() self.assertEqual(light.state, State.ON) time.sleep(2) motion.still() self.assertEqual(light.state, State.ON) time.sleep(1) self.assertEqual(light.state, State.OFF)
def test_delay_light_specific(self): # motion.off and Photocell.Light events do not retrigger motion = Motion() light = Light(address='D1', devices=(self.interface, motion), trigger={ Attribute.COMMAND: Command.ON, Attribute.MAPPED: Command.OFF, Attribute.SECS: 3, }, ignore={ Attribute.COMMAND: Command.STILL, Attribute.SOURCE: motion, } ) motion.motion() self.assertEqual(light.state, State.ON) time.sleep(2) motion.still() self.assertEqual(light.state, State.ON) time.sleep(1) self.assertEqual(light.state, State.OFF)
def test_light_scenario_g3(self): m1 = Motion() m2 = Motion() interface = Mock() l = Light( devices=(interface, m1, m2), ignore={ Attribute.COMMAND: Command.STILL, }, trigger=( { Attribute.COMMAND: Command.ON, Attribute.MAPPED: Command.OFF, Attribute.SOURCE: m2, Attribute.SECS: 2 }, { Attribute.COMMAND: Command.ON, Attribute.MAPPED: Command.OFF, Attribute.SOURCE: m1, Attribute.SECS: 10 }, ), initial=State.OFF, ) self.assertEqual(l.state, State.OFF) m1.motion() self.assertEqual(l.state, State.ON) # Interface updates us on the status l.command(command=Command.ON, source=interface) # call still just to add some noise. Should be ignored m1.still() self.assertEqual(l.state, State.ON) time.sleep(2) # Light should still be on < 10 secs self.assertEqual(l.state, State.ON) m2.motion() self.assertEqual(l.state, State.ON) # more noise to try and force an issue. Should be ignored m2.still() m1.still() self.assertEqual(l.state, State.ON) time.sleep(3) # total of 5 secs have elapsed since m1 and 3 since m2 # Light should be off as m2 set the new time to only 2 secs self.assertEqual(l.state, State.OFF)
def test_light_scenario_g3(self): m1 = Motion() m2 = Motion() interface = Mock() l = Light( devices=(interface, m1, m2), ignore={ Attribute.COMMAND: Command.STILL, }, trigger=( { Attribute.COMMAND: Command.ON, Attribute.MAPPED: Command.OFF, Attribute.SOURCE: m2, Attribute.SECS: 2 }, { Attribute.COMMAND: Command.ON, Attribute.MAPPED: Command.OFF, Attribute.SOURCE: m1, Attribute.SECS: 10 }, ), initial=State.OFF, ) self.assertEqual(l.state, State.OFF) m1.motion() self.assertEqual(l.state, State.ON) # Interface updates us on the status l.command(command=Command.ON, source=interface) # call still just to add some noise. Should be ignored m1.still() self.assertEqual(l.state, State.ON) time.sleep(2) # Light should still be on < 10 secs self.assertEqual(l.state, State.ON) m2.motion() self.assertEqual(l.state, State.ON) # more noise to try and force an issue. Should be ignored m2.still() m1.still() self.assertEqual(l.state, State.ON) time.sleep(3) # total of 5 secs have elapsed since m1 and 3 since m2 # Light should be off as m2 set the new time to only 2 secs self.assertEqual(l.state, State.OFF)