Beispiel #1
0
 def test_motion_triggered(self):
     motion = Motion("D1", initial_state=State.STILL)
     self.assertEqual(motion.state, State.STILL)
     light = Light("D1", motion)
     self.assertEqual(light.state, State.OFF)
     motion.motion()
     self.assertEqual(light.state, State.ON)
Beispiel #2
0
 def test_light_scenario_2(self):
     m = Motion()
     l = Light(
         address=(49, 3),
         devices=(m),
         ignore=({
             Attribute.COMMAND: Command.DARK,
         }, {
             Attribute.COMMAND: Command.STILL
         }),
         time={
             Attribute.TIME: '11:59pm',
             Attribute.COMMAND: Command.OFF
         },
         mapped={
             Attribute.COMMAND: (
                 Command.MOTION,
                 Command.OPEN,
                 Command.CLOSE,
                 Command.LIGHT,
             ),
             Attribute.MAPPED:
             Command.OFF,
             Attribute.SECS:
             2,
         },
         name='Foyer Light',
     )
     l.off()
     self.assertEqual(l.state, State.OFF)
     m.motion()
     self.assertEqual(l.state, State.OFF)
     time.sleep(3)
     self.assertEqual(l.state, State.OFF)
Beispiel #3
0
 def test_motion_triggered(self):
     motion = Motion('D1', initial=State.STILL)
     self.assertEqual(motion.state, State.STILL)
     light = Light('D1', devices=motion)
     self.assertEqual(light.state, State.OFF)
     motion.motion()
     self.assertEqual(light.state, State.ON)
Beispiel #4
0
 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_2(self):
     m = Motion()
     l = Light(
             address=(49, 3),
             devices=(m),
              ignore=({
                      Attribute.COMMAND: Command.DARK,
                      },
                      {
                       Attribute.COMMAND: Command.STILL}
                      ),
              time={
                    Attribute.TIME: '11:59pm',
                    Attribute.COMMAND: Command.OFF
                    },
              mapped={
                      Attribute.COMMAND: (
                                          Command.MOTION, Command.OPEN,
                                           Command.CLOSE, Command.LIGHT,
                                           ),
                      Attribute.MAPPED: Command.OFF,
                      Attribute.SECS: 2,
                      },
      name='Foyer Light',
             )
     l.off()
     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_motion_triggered(self):
     motion = Motion('D1', initial=State.STILL)
     self.assertEqual(motion.state, State.STILL)
     light = Light('D1', devices=motion)
     self.assertEqual(light.state, State.OFF)
     motion.motion()
     self.assertEqual(light.state, State.ON)
Beispiel #7
0
 def test_room_occupied(self):
     m = Motion()
     r = Room(devices=m)
     r.vacate()
     self.assertEqual(r.state, State.VACANT)
     m.motion()
     self.assertEqual(r.state, State.OCCUPIED)
Beispiel #8
0
 def test_room_occupied(self):
     m = Motion()
     r = Room(devices=m)
     r.vacate()
     self.assertEqual(r.state, State.VACANT)
     m.motion()
     self.assertEqual(r.state, State.OCCUPIED)
Beispiel #9
0
 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)
Beispiel #10
0
 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)
Beispiel #11
0
 def test_motion_delay_from_interface(self):
     i = Mock()
     m = Motion(devices=i,
                delay={
                       Attribute.COMMAND: Command.STILL,
                       Attribute.SECS: 2,
                       })
     m.command(command=Command.MOTION, source=i)
     self.assertEqual(m.state, State.MOTION)
     m.command(command=Command.STILL, source=i)
     self.assertEqual(m.state, State.MOTION)
     time.sleep(3)
     self.assertEqual(m.state, State.STILL)
Beispiel #12
0
 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)
Beispiel #13
0
 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)
Beispiel #14
0
 def test_motion_ignore(self):
     self.device = Motion(
         'D1',
         devices=(self.interface),
         ignore={
             'command': Command.STILL,
         },
     )
     self.device.command(Command.MOTION, source=self.interface)
     #        self.device._on_command('D1', State.ON, self.interface)
     self.assertEqual(self.device.state, State.MOTION)
     self.device.command(Command.MOTION, source=self.interface)
     #        self.device._on_command('D1', State.OFF, self.interface)
     self.assertEqual(self.device.state, State.MOTION)
 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)
 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)
Beispiel #17
0
 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_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_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)
Beispiel #20
0
    def test_motion_ignore(self):
        self.device = Motion('D1', devices=(self.interface), ignore={
                                                                      'command': Command.STILL,
                                                                      },
                              )
        self.device.command(Command.MOTION, source=self.interface)
#        self.device._on_command('D1', State.ON, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
        self.device.command(Command.MOTION, source=self.interface)
#        self.device._on_command('D1', State.OFF, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
    def test_motion_ignore(self):
        self.device = Motion('D1', devices=(self.interface), ignore_off=True)
        self.device._on_command('D1', State.ON, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
        self.device._on_command('D1', State.OFF, self.interface)
        self.assertEqual(self.device.state, State.MOTION)

        # Make sure we can turn ignore off
        self.device.ignore_off(False)
        self.device._on_command('D1', State.OFF, self.interface)
        self.assertEqual(self.device.state, State.STILL)        
 def test_light_scenario1(self):
     m = Motion()
     l = Light(
             address=(49, 6), 
             devices=m,
             mapped={
                     Attribute.COMMAND: Command.MOTION,
                     Attribute.SECS: 30*60
                     },
             ignore=({
                     Attribute.COMMAND: Command.STILL
                     },
                     {
                     Attribute.COMMAND: Command.DARK
                     },
                 ),
             name='Lamp',
             )
     self.assertEqual(l.state, State.UNKNOWN)
     m.command(command=State.ON, source=None)
     self.assertEqual(l.state, State.UNKNOWN)
Beispiel #23
0
 def test_light_unrestricted(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)
     motion.unrestricted = True
     motion.motion()
     self.assertEqual(light.state, State.ON)
 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)
Beispiel #25
0
 def test_light_scenario1(self):
     m = Motion()
     l = Light(
         address=(49, 6),
         devices=m,
         mapped={
             Attribute.COMMAND: Command.MOTION,
             Attribute.SECS: 30 * 60
         },
         ignore=(
             {
                 Attribute.COMMAND: Command.STILL
             },
             {
                 Attribute.COMMAND: Command.DARK
             },
         ),
         name='Lamp',
     )
     self.assertEqual(l.state, State.UNKNOWN)
     m.command(command=State.ON, source=None)
     self.assertEqual(l.state, State.UNKNOWN)
Beispiel #26
0
 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)
Beispiel #27
0
 def test_motion_retrigger(self):
     i = Mock()
     m = Motion(
         devices=i,
         retrigger_delay={
             Attribute.SECS: 2,
         },
     )
     s = Light(devices=m)
     s.off()
     self.assertEqual(s.state, State.OFF)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.ON)
     s.off()
     self.assertEqual(s.state, State.OFF)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.OFF)
     time.sleep(3)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.ON)
Beispiel #28
0
 def test_motion_delay_from_interface(self):
     i = Mock()
     m = Motion(devices=i,
                delay={
                    Attribute.COMMAND: Command.STILL,
                    Attribute.SECS: 2,
                })
     m.command(command=Command.MOTION, source=i)
     self.assertEqual(m.state, State.MOTION)
     m.command(command=Command.STILL, source=i)
     self.assertEqual(m.state, State.MOTION)
     time.sleep(3)
     self.assertEqual(m.state, State.STILL)
Beispiel #29
0
 def test_motion_retrigger(self):
     i = Mock()
     m = Motion(devices=i,
                retrigger_delay={
                                 Attribute.SECS: 2,
                                 },
                )
     s = Light(devices=m)
     s.off()
     self.assertEqual(s.state, State.OFF)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.ON)
     s.off()
     self.assertEqual(s.state, State.OFF)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.OFF)
     time.sleep(3)
     m.command(command=Command.ON, source=i)
     self.assertEqual(s.state, State.ON)
Beispiel #30
0
 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)
Beispiel #31
0
class MotionTests(TestCase):
    
    def setUp(self):
        self.interface = Mock()
        self.interface.state = State.UNKNOWN
        self.device = Motion('D1', self.interface)

    def test_instantiation(self):
        self.assertIsNotNone(self.device,
                             'Motion Device could not be instantiated')

    def test_motion_motion(self):
        self.assertEqual(self.device.state, State.UNKNOWN)
        self.device.command(Command.MOTION, source=self.interface)
#        self.device._on_command('D1', State.ON)
        self.assertEqual(self.device.state, State.MOTION)
#        self.device._on_command('D1', State.OFF)
        self.device.command(Command.STILL, source=self.interface)
        self.assertEqual(self.device.state, State.STILL)

    def test_motion_ignore(self):
        self.device = Motion('D1', devices=(self.interface), ignore={
                                                                      'command': Command.STILL,
                                                                      },
                              )
        self.device.command(Command.MOTION, source=self.interface)
#        self.device._on_command('D1', State.ON, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
        self.device.command(Command.MOTION, source=self.interface)
#        self.device._on_command('D1', State.OFF, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
        
    def test_motion_on(self):
        m = Motion()
        m.command(command=Command.ON, source=None)
        self.assertEqual(m.state, State.MOTION)        
Beispiel #32
0
 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)
Beispiel #33
0
 def setUp(self):
     self.interface = Mock()
     self.interface.state = State.UNKNOWN
     self.device = Motion('D1', self.interface)
Beispiel #34
0
bedroom_onoff = Generic('G1', w800, name='Bedroom Remote')
all_lights = Generic('G2', w800)

#'D1' slimeline downstairs

# KR22A X10 4 button remote - low range
x1 = Generic('E1', w800, name='X1')
x2 = Generic('E2', w800)
x3 = Generic('E3', w800)
x4 = Generic('E4', w800)



# ______ MOTION SENSORS _____________________________________________

m_kitchen = Motion(address='AC', devices=wtdio, name='Kitchen Motion')
m_laundry = Motion(address='AD', devices=wtdio, name='Laundry Room Motion')
m_hallway = Motion(address='AE', devices=wtdio, name='Hallway Motion')

# Don't allow this to trigger ON again for 20 seconds
m_stairs  = Motion(address='H1', devices=w800,
        retrigger_delay = {
            Attribute.SECS: 20
        },
        name='Stair Motion')
m_recroom = Motion(address='I1', devices=w800, name='Recroom Motion')
m_backdoor = Motion(address='J1', devices=w800, name='Backdoor Motion')



# ______ DOOR CONTACTS ______________________________________________
 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)
Beispiel #36
0
xmpp.mapped(
    command=Command.OPEN,
    mapped=(Command.MESSAGE, '*****@*****.**', 'Garage door was opened!'),
)

#general input
i_laundry_security = Generic('D7', sg, name='Laundry Keypad')
i_master_security = Generic('D9', sg, name='Master Keypad')
i_laser_perimeter = Generic('D12', sg, name='Laser Perimeter')

#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')
Beispiel #37
0
    def test_room_to_room_vacate(self):
        m1 = Motion(name='m1')
        m2 = Motion(name='m2')
        m3 = Motion(name='m3')
        r1 = Room(name='r1', devices=m1)
        r2 = Room(name='r2', devices=(m2, r1))
        r3 = Room(name='r3', devices=(m3, r2))
        r1.add_device(r2)
        r2.add_device(r3)

        m1.motion()
        self.assertEqual(r1.state, State.OCCUPIED)
        self.assertEqual(r2.state, State.VACANT)
        self.assertEqual(r3.state, State.UNKNOWN)
        m2.motion()
        self.assertEqual(r1.state, State.VACANT)
        self.assertEqual(r2.state, State.OCCUPIED)
        self.assertEqual(r3.state, State.VACANT)
        m3.motion()
        self.assertEqual(r1.state, State.VACANT)
        self.assertEqual(r2.state, State.VACANT)
        self.assertEqual(r3.state, State.OCCUPIED)
        m1.motion()
        self.assertEqual(r1.state, State.OCCUPIED)
        self.assertEqual(r2.state, State.VACANT)
        self.assertEqual(r3.state, State.OCCUPIED)
        m2.motion()
        self.assertEqual(r1.state, State.VACANT)
        self.assertEqual(r2.state, State.OCCUPIED)
        self.assertEqual(r3.state, State.VACANT)
        
        
class MotionTests(TestCase):
    
    def setUp(self):
        self.interface = Mock()
        self.interface.state = State.UNKNOWN
        self.device = Motion('D1', self.interface)

    def test_instantiation(self):
        self.assertIsNotNone(self.device,
                             'Motion Device could not be instantiated')

    def test_motion_motion(self):
        self.assertEqual(self.device.state, State.UNKNOWN)
        self.device._on_command('D1', State.ON)
        self.assertEqual(self.device.state, State.MOTION)
        self.device._on_command('D1', State.OFF)
        self.assertEqual(self.device.state, State.STILL)

    def test_motion_ignore(self):
        self.device = Motion('D1', devices=(self.interface), ignore_off=True)
        self.device._on_command('D1', State.ON, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
        self.device._on_command('D1', State.OFF, self.interface)
        self.assertEqual(self.device.state, State.MOTION)

        # Make sure we can turn ignore off
        self.device.ignore_off(False)
        self.device._on_command('D1', State.OFF, self.interface)
        self.assertEqual(self.device.state, State.STILL)        
Beispiel #39
0
cs_masterbath = Door(address=None,
                     devices=(pi_masterbath),
                     name="Master Bathroom Window")

pi_backdoor = StateInterface(RPIInput(24))  #BCM 2
cs_backdoor = Door(address=None, devices=(pi_backdoor), name="Back Door")

pi_hallway = StateInterface(RPIInput(12))  #BCM 18
mt_hallway = Motion(address=None,
                    devices=(pi_hallway),
                    initial=Command.STILL,
                    name="Hallway Motion",
                    mapped=({
                        Attribute.COMMAND: Command.OPEN,
                        Attribute.MAPPED: Command.MOTION
                    }, {
                        Attribute.COMMAND: Command.CLOSE,
                        Attribute.MAPPED: Command.STILL
                    }),
                    delay={
                        Attribute.COMMAND: Command.STILL,
                        Attribute.SECS: 30
                    })

#Example of a hardware scene not defined in the PLM
s_masterbath = Scene('15.64.1D:04',
                     devices=(insteon, ),
                     name="Master Bathroom",
                     controllers=[Controller(sl_master2)],
                     responders={sl_master2: {
                         'state': State.ON
###################### INTERFACE CONFIG #########################
upb = UPB(Serial('/dev/ttyMI0', 4800))

#insteon = InsteonPLM(TCP('192.168.13.146', 9761))
#insteon.start()

sg = Stargate(Serial('/dev/ttyMI2', 9600))
# invert the DIO channels for these contact sensors
sg.dio_invert(1)
sg.dio_invert(8)

###################### DEVICE CONFIG #########################

d_foyer = Door('D1', sg)

m_family = Motion('D8', sg)
# Motion sensor is hardwired and immediate OFF.. Want to give it some time to still detect motion right after
m_family.delay_still(2*60) 

ph_sun = Location('35.2269', '-80.8433', tz='US/Eastern', mode=Location.MODE.STANDARD, is_dst=True)

# Turn on the foyer light at night when either the door is opened or family PIR is tripped.
l_foyer = Light((49, 3), (upb, d_foyer, m_family, ph_sun))
# After being turned on, turn off again after 2 minutes of inactivity.
l_foyer.delay_off(2*60)
# Turn off the light no matter what at 11:59pm
l_foyer.time_off('11:59pm')
# Do not turn on the light automatically when it is night time (indoor light)
# Only looks at dark for restricing the whether the light should come on
l_foyer.ignore_dark(True)
Beispiel #41
0
 def test_motion_on(self):
     m = Motion()
     m.command(command=Command.ON, source=None)
     self.assertEqual(m.state, State.MOTION)
Beispiel #42
0
 def setUp(self):
     self.interface = Mock()
     self.interface.state = State.UNKNOWN
     self.device = Motion('D1', self.interface)
Beispiel #43
0
 def test_motion_on(self):
     m = Motion()
     m.command(command=Command.ON, source=None)
     self.assertEqual(m.state, State.MOTION)        
Beispiel #44
0
class MotionTests(TestCase):
    def setUp(self):
        self.interface = Mock()
        self.interface.state = State.UNKNOWN
        self.device = Motion('D1', self.interface)

    def test_instantiation(self):
        self.assertIsNotNone(self.device,
                             'Motion Device could not be instantiated')

    def test_motion_motion(self):
        self.assertEqual(self.device.state, State.UNKNOWN)
        self.device.command(Command.MOTION, source=self.interface)
        #        self.device._on_command('D1', State.ON)
        self.assertEqual(self.device.state, State.MOTION)
        #        self.device._on_command('D1', State.OFF)
        self.device.command(Command.STILL, source=self.interface)
        self.assertEqual(self.device.state, State.STILL)

    def test_motion_ignore(self):
        self.device = Motion(
            'D1',
            devices=(self.interface),
            ignore={
                'command': Command.STILL,
            },
        )
        self.device.command(Command.MOTION, source=self.interface)
        #        self.device._on_command('D1', State.ON, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
        self.device.command(Command.MOTION, source=self.interface)
        #        self.device._on_command('D1', State.OFF, self.interface)
        self.assertEqual(self.device.state, State.MOTION)

    def test_motion_on(self):
        m = Motion()
        m.command(command=Command.ON, source=None)
        self.assertEqual(m.state, State.MOTION)

    def test_motion_delay_from_interface(self):
        i = Mock()
        m = Motion(devices=i,
                   delay={
                       Attribute.COMMAND: Command.STILL,
                       Attribute.SECS: 2,
                   })
        m.command(command=Command.MOTION, source=i)
        self.assertEqual(m.state, State.MOTION)
        m.command(command=Command.STILL, source=i)
        self.assertEqual(m.state, State.MOTION)
        time.sleep(3)
        self.assertEqual(m.state, State.STILL)

    def test_motion_retrigger(self):
        i = Mock()
        m = Motion(
            devices=i,
            retrigger_delay={
                Attribute.SECS: 2,
            },
        )
        s = Light(devices=m)
        s.off()
        self.assertEqual(s.state, State.OFF)
        m.command(command=Command.ON, source=i)
        self.assertEqual(s.state, State.ON)
        s.off()
        self.assertEqual(s.state, State.OFF)
        m.command(command=Command.ON, source=i)
        self.assertEqual(s.state, State.OFF)
        time.sleep(3)
        m.command(command=Command.ON, source=i)
        self.assertEqual(s.state, State.ON)
Beispiel #45
0
    def test_room_to_room_vacate(self):
        m1 = Motion(name="m1")
        m2 = Motion(name="m2")
        m3 = Motion(name="m3")
        r1 = Room(name="r1", devices=m1)
        r2 = Room(name="r2", devices=(m2, r1))
        r3 = Room(name="r3", devices=(m3, r2))
        r1.add_device(r2)
        r2.add_device(r3)

        m1.motion()
        self.assertEqual(r1.state, State.OCCUPIED)
        self.assertEqual(r2.state, State.VACANT)
        self.assertEqual(r3.state, State.UNKNOWN)
        m2.motion()
        self.assertEqual(r1.state, State.VACANT)
        self.assertEqual(r2.state, State.OCCUPIED)
        self.assertEqual(r3.state, State.VACANT)
        m3.motion()
        self.assertEqual(r1.state, State.VACANT)
        self.assertEqual(r2.state, State.VACANT)
        self.assertEqual(r3.state, State.OCCUPIED)
        m1.motion()
        self.assertEqual(r1.state, State.OCCUPIED)
        self.assertEqual(r2.state, State.VACANT)
        self.assertEqual(r3.state, State.OCCUPIED)
        m2.motion()
        self.assertEqual(r1.state, State.VACANT)
        self.assertEqual(r2.state, State.OCCUPIED)
        self.assertEqual(r3.state, State.VACANT)
Beispiel #46
0
    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)
Beispiel #47
0
class MotionTests(TestCase):
    
    def setUp(self):
        self.interface = Mock()
        self.interface.state = State.UNKNOWN
        self.device = Motion('D1', self.interface)

    def test_instantiation(self):
        self.assertIsNotNone(self.device,
                             'Motion Device could not be instantiated')

    def test_motion_motion(self):
        self.assertEqual(self.device.state, State.UNKNOWN)
        self.device.command(Command.MOTION, source=self.interface)
#        self.device._on_command('D1', State.ON)
        self.assertEqual(self.device.state, State.MOTION)
#        self.device._on_command('D1', State.OFF)
        self.device.command(Command.STILL, source=self.interface)
        self.assertEqual(self.device.state, State.STILL)

    def test_motion_ignore(self):
        self.device = Motion('D1', devices=(self.interface), ignore={
                                                                      'command': Command.STILL,
                                                                      },
                              )
        self.device.command(Command.MOTION, source=self.interface)
#        self.device._on_command('D1', State.ON, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
        self.device.command(Command.MOTION, source=self.interface)
#        self.device._on_command('D1', State.OFF, self.interface)
        self.assertEqual(self.device.state, State.MOTION)
        
    def test_motion_on(self):
        m = Motion()
        m.command(command=Command.ON, source=None)
        self.assertEqual(m.state, State.MOTION)        

    def test_motion_delay_from_interface(self):
        i = Mock()
        m = Motion(devices=i,
                   delay={
                          Attribute.COMMAND: Command.STILL,
                          Attribute.SECS: 2,
                          })
        m.command(command=Command.MOTION, source=i)
        self.assertEqual(m.state, State.MOTION)
        m.command(command=Command.STILL, source=i)
        self.assertEqual(m.state, State.MOTION)
        time.sleep(3)
        self.assertEqual(m.state, State.STILL)

    def test_motion_retrigger(self):
        i = Mock()
        m = Motion(devices=i,
                   retrigger_delay={
                                    Attribute.SECS: 2,
                                    },
                   )
        s = Light(devices=m)
        s.off()
        self.assertEqual(s.state, State.OFF)
        m.command(command=Command.ON, source=i)
        self.assertEqual(s.state, State.ON)
        s.off()
        self.assertEqual(s.state, State.OFF)
        m.command(command=Command.ON, source=i)
        self.assertEqual(s.state, State.OFF)
        time.sleep(3)
        m.command(command=Command.ON, source=i)
        self.assertEqual(s.state, State.ON)