def test_light_scenario_g1(self): d = Door() p = Photocell() p.light() l = Light(address='xx.xx.xx', devices=(d, p), mapped={ Attribute.COMMAND: (Command.CLOSE), Attribute.MAPPED: Command.OFF, Attribute.SECS: 2, }, ignore=({Attribute.COMMAND: Command.DARK}), name="Hallway Lights",) l.on() self.assertEqual(l.state, State.ON) d.close() self.assertEqual(l.state, State.ON) time.sleep(3) self.assertEqual(l.state, State.OFF) d.open() self.assertEqual(l.state, State.OFF)
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_scenario_g1(self): d = Door() p = Photocell() p.light() l = Light( address='xx.xx.xx', devices=(d, p), mapped={ Attribute.COMMAND: (Command.CLOSE), Attribute.MAPPED: Command.OFF, Attribute.SECS: 2, }, ignore=({ Attribute.COMMAND: Command.DARK }), name="Hallway Lights", ) l.on() self.assertEqual(l.state, State.ON) d.close() self.assertEqual(l.state, State.ON) time.sleep(3) self.assertEqual(l.state, State.OFF) d.open() self.assertEqual(l.state, State.OFF)
def test_light_photocell_delay(self): # Delay off should not trigger when photocell tells us to go dark. # Do it immediately photo = Photocell() photo.dark() light = Light(address="e3", devices=photo, delay_off=3) self.assertEqual(light.state, State.ON) photo.light() self.assertEqual(light.state, State.OFF)
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_light_restricted(self): photo = Photocell("D1", initial_state=State.LIGHT) motion = Motion("D1", initial_state=State.STILL) light = Light("D2", (motion, photo)) self.assertEqual(light.state, State.OFF) motion.motion() self.assertEqual(light.state, State.OFF) photo.dark() self.assertEqual(light.state, State.ON) light.off() self.assertEqual(light.state, State.OFF) motion.motion() self.assertEqual(light.state, State.ON)
def test_light_restricted(self): photo = Photocell('D1', initial=State.LIGHT) self.assertEqual(photo.state, State.LIGHT) motion = Motion('D1', initial=State.STILL) light = Light('D2', devices=(motion, photo), initial=photo) self.assertEqual(light.state, State.OFF) motion.motion() self.assertEqual(light.state, State.OFF) photo.dark() self.assertEqual(light.state, State.ON) light.off() self.assertEqual(light.state, State.OFF) motion.motion() self.assertEqual(light.state, State.ON)
class PhotocellTests(TestCase): def setUp(self): self.interface = Mock() self.interface.state = State.UNKNOWN self.device = Photocell("D1", self.interface) def test_instantiation(self): self.assertIsNotNone(self.device, "Photocell Device could not be instantiated") def test_photocell_state(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device._on_command("D1", State.ON) self.assertEqual(self.device.state, State.DARK) self.device._on_command("D1", State.OFF) self.assertEqual(self.device.state, State.LIGHT)
class PhotocellTests(TestCase): def setUp(self): self.interface = Mock() self.interface.state = State.UNKNOWN self.device = Photocell('D1', self.interface) def test_instantiation(self): self.assertIsNotNone(self.device, 'Photocell Device could not be instantiated') def test_photocell_state(self): self.assertEqual(self.device.state, State.UNKNOWN) self.device.command(Command.DARK) self.assertEqual(self.device.state, State.DARK) self.device.command(Command.LIGHT) self.assertEqual(self.device.state, State.LIGHT)
def test_light_restriction_idle(self): ph = Photocell() m = Motion() ph.dark() l = Light( devices=(ph, m), idle={Attribute.MAPPED: (Command.LEVEL, 30), Attribute.SECS: 2, } ) m.motion() self.assertEqual(l.state, State.ON) ph.light() self.assertEqual(l.state, State.OFF) m.motion() self.assertEqual(l.state, State.OFF) time.sleep(3) self.assertEqual(l.state, State.OFF)
def test_light_restriction_idle(self): ph = Photocell() m = Motion() ph.dark() l = Light(devices=(ph, m), idle={ Attribute.MAPPED: (Command.LEVEL, 30), Attribute.SECS: 2, }) m.motion() self.assertEqual(l.state, State.ON) ph.light() self.assertEqual(l.state, State.OFF) m.motion() self.assertEqual(l.state, State.OFF) time.sleep(3) self.assertEqual(l.state, State.OFF)
def test_photocell_triggered(self): photo = Photocell('D1', initial=State.LIGHT) light = Light('D1', devices=photo) self.assertEquals(light.state, State.OFF) photo.dark() self.assertEquals(light.state, State.ON)
def setUp(self): self.interface = Mock() self.interface.state = State.UNKNOWN self.device = Photocell("D1", self.interface)
def setUp(self): self.interface = Mock() self.interface.state = State.UNKNOWN self.device = Photocell('D1', self.interface)
def test_photocell_triggered(self): photo = Photocell("D1", initial_state=State.LIGHT) light = Light("D1", photo) self.assertEquals(light.state, State.OFF) photo.dark() self.assertEquals(light.state, State.ON)
#motion # Motion sensor is hardwired and immediate OFF.. Want to give it some time to still detect motion right after m_family = Motion(address='D8', devices=(sg), delay={ Attribute.COMMAND: Command.STILL, Attribute.SECS: 30, }, name='Family Motion') m_front_porch = Motion( address='F1', devices=w800, name='Front Porch Motion', ) ph_front_porch = Photocell(address='F2', devices=w800) m_front_garage = Motion(address='F3', devices=w800, name='Front Garage Motion') ph_front_garage = Photocell(address='F4', devices=w800) m_front_driveway = Motion(address='F5', devices=w800, name='Front Driveway Motion') ph_front_driveway = Photocell(address='F6', devices=w800) m_front_camera = Motion(address=None, devices=pipe_front_yard_motion) m_garage = Motion(address='G1', devices=w800, name='Garage Motion') ph_garage = Photocell(address='G2', devices=w800) m_utility = Motion(address='G3', devices=w800, name='Utility Motion') ph_utility = Photocell(address='G4', devices=w800) m_breakfast = Motion(address='G7', devices=w800, name='Breakfast Motion')