def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.sg = Stargate(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 2400) self.sg = Stargate(self.serial)
import select from pytomation.interfaces import UPB, InsteonPLM, TCP, Serial, Stargate from pytomation.devices import Motion, Door, Light, Location from pytomation.common.system import * ###################### 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)
#from pytomation.common.system import * ###################### INTERFACE CONFIG ######################### web = HTTPServer() xmpp = XMPP_Client(id='*****@*****.**', password='******', server='talk.google.com', port=5222) upb = UPB(Serial('/dev/ttyMI0', 4800)) #insteon = InsteonPLM(TCP('192.168.13.146', 9761)) insteon = InsteonPLM(Serial('/dev/ttyMI1', 19200, xonxoff=False)) w800 = W800rf32(Serial('/dev/ttyMI3', 4800)) sg = Stargate(Serial('/dev/ttyMI4', 9600)) # invert the DIO channels for these contact sensors sg.dio_invert(1) sg.dio_invert(2) sg.dio_invert(3) sg.dio_invert(4) sg.dio_invert(5) sg.dio_invert(6) sg.dio_invert(7) sg.dio_invert(8) sg.dio_invert(9) sg.dio_invert(10) sg.dio_invert(11) sg.dio_invert(12) # My camera motion software will echo a "motion" to this pipe.
class StargateInterfaceTests(TestCase): useMock = True def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.sg = Stargate(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 2400) self.sg = Stargate(self.serial) #self.sg.start() def tearDown(self): self.sg.shutdown() self.serial = None def test_instantiation(self): self.assertIsNotNone(self.sg, 'SG interface could not be instantiated') def test_digital_input(self): """ digital input #1 ON !!07/01083237a0fe digital input #1 OFF !!07/01083239a0ff """ """ 0000 21 21 30 38 2F 30 31 30 !!08/010 0008 38 31 39 33 30 61 30 66 81930a0f 0010 65 e """ # What will be written / what should we get back self.ms.add_response({'##%1d\r': '!!07/01083237a001\r\n'}) # Register delegate self.sg.onCommand(callback=self._digital_input_callback, address='D1') # resend EchoMode to trigger response self.sg.echoMode() time.sleep(3) self.assertEqual(self.__digital_input_params['kwargs']['address'].upper(), 'D8') def test_digital_input_multiple(self): """ 0000 21 21 30 38 2F 30 31 30 !!08/010 0008 37 38 38 30 37 61 30 66 78807a0f 0010 65 0D 0A 21 21 30 38 2F e..!!08/ 0018 30 31 30 37 38 38 30 37 01078807 0020 34 30 30 31 0D 0A 21 21 4001..!! 0028 30 38 2F 30 31 30 37 38 08/01078 0030 38 30 37 34 31 30 30 0D 8074100. 0038 0A . """ # What will be written / what should we get back self.ms.add_response({'##%1d\r': '!!07/01083237a001\r\n!!07/01083237a000\r\n'}) # Register delegate self.sg.onCommand(callback=self._digital_input_callback, address='D1') # resend EchoMode to trigger response self.sg.echoMode() time.sleep(1.5) self.assertEqual(self.__digital_input_params['kwargs']['address'].upper(), 'D1') def _digital_input_callback(self, *args, **kwargs): print "Args:" + str(args) + " Kwargs:" + str(kwargs) self.__digital_input_params = {'args': args, 'kwargs': kwargs}
class StargateInterfaceTests(TestCase): useMock = True def setUp(self): self.ms = MockInterface() if self.useMock: # Use Mock Serial Port self.sg = Stargate(self.ms) else: self.serial = Serial('/dev/ttyUSB0', 2400) self.sg = Stargate(self.serial) #self.sg.start() def tearDown(self): self.sg.shutdown() self.serial = None def test_instantiation(self): self.assertIsNotNone(self.sg, 'SG interface could not be instantiated') def test_digital_input(self): """ digital input #1 ON !!07/01083237a0fe digital input #1 OFF !!07/01083239a0ff """ """ 0000 21 21 30 38 2F 30 31 30 !!08/010 0008 38 31 39 33 30 61 30 66 81930a0f 0010 65 e """ # What will be written / what should we get back self.ms.add_response({'##%1d\r': '!!07/01083237a001\r\n'}) # Register delegate self.sg.onCommand(callback=self._digital_input_callback, address='D1') # resend EchoMode to trigger response self.sg.echoMode() time.sleep(3) self.assertEqual( self.__digital_input_params['kwargs']['address'].upper(), 'D8') def test_digital_input_multiple(self): """ 0000 21 21 30 38 2F 30 31 30 !!08/010 0008 37 38 38 30 37 61 30 66 78807a0f 0010 65 0D 0A 21 21 30 38 2F e..!!08/ 0018 30 31 30 37 38 38 30 37 01078807 0020 34 30 30 31 0D 0A 21 21 4001..!! 0028 30 38 2F 30 31 30 37 38 08/01078 0030 38 30 37 34 31 30 30 0D 8074100. 0038 0A . """ # What will be written / what should we get back self.ms.add_response( {'##%1d\r': '!!07/01083237a001\r\n!!07/01083237a000\r\n'}) # Register delegate self.sg.onCommand(callback=self._digital_input_callback, address='D1') # resend EchoMode to trigger response self.sg.echoMode() time.sleep(1.5) self.assertEqual( self.__digital_input_params['kwargs']['address'].upper(), 'D1') def _digital_input_callback(self, *args, **kwargs): print("Args:" + str(args) + " Kwargs:" + str(kwargs)) self.__digital_input_params = {'args': args, 'kwargs': kwargs}
from pytomation.config import * from pytomation.interfaces import Stargate, Serial def on_digital_input(command=None, address=None): print "Digital Input #" + str(address) + " -> " + command debug['Stargate'] = 1 serial = Serial('/dev/ttyUSB0', 2400) sg = Stargate(serial) sg.start() # Listen for changes on Digital Input #1 on Stargate sg.onCommand(callback=on_digital_input, address='D1') # Code is done, we no longer need the interface sg.shutdown()
###################### INTERFACE CONFIG ######################### web = HTTPServer() xmpp = XMPP_Client(id='*****@*****.**', password='******', server='talk.google.com', port=5222) upb = UPB(Serial('/dev/ttyMI0', 4800)) #insteon = InsteonPLM(TCP('192.168.13.146', 9761)) insteon = InsteonPLM(Serial('/dev/ttyMI1', 19200, xonxoff=False)) w800 = W800rf32(Serial('/dev/ttyMI3', 4800)) sg = Stargate(Serial('/dev/ttyMI4', 9600)) # invert the DIO channels for these contact sensors sg.dio_invert(1) sg.dio_invert(2) sg.dio_invert(3) sg.dio_invert(4) sg.dio_invert(5) sg.dio_invert(6) sg.dio_invert(7) sg.dio_invert(8) sg.dio_invert(9) sg.dio_invert(10) sg.dio_invert(11) sg.dio_invert(12) # My camera motion software will echo a "motion" to this pipe.