class InsteonInterfaceTests(TestCase):
    useMock = True

    def setUp(self):
        self.ms = MockInterface()
        if self.useMock:  # Use Mock Serial Port
            self.insteon = InsteonPLM(self.ms)
        else:
# If we are running live, the insteon interface doesnt like to be bombarded with requests
#            time.sleep(3)
#            self.serial = Serial('/dev/ttyUSB0', 4800)
#            self.insteon = InsteonPLM(self.serial)
            self.tcp = TCP('192.168.13.146', 9761)
            self.insteon = InsteonPLM(self.tcp)

        #self.insteon.start()

    def tearDown(self):
        self.insteon.shutdown()
        self.serial = None
        try:
            self.tcp.shutdown()
            self.tcp = None
        except:
            pass

    def test_instantiation(self):
        self.assertIsNotNone(self.insteon,
                             'Insteon interface could not be instantiated')

    def test_get_firmware_version(self):
        """
        >0000   02 60    .`
        <0000   02 60 16 F9 EC 03 05 92 06    .`.......
        """
        self.ms.add_response({Conversions.hex_to_ascii('0260'):
                                  Conversions.hex_to_ascii('026016F9EC03059206')})

        info = self.insteon.getPLMInfo()
        self.assertEqual(info['firmwareVersion'], "92")
        #select.select([], [], [])

    def test_device_on(self):
        """
        Transmit>
        0000   02 62 19 05 7B 0F 11 FF    .b..{...
        <  0000   02 62 19 05 7B 0F 11 FF 06    .b..{....
        <  0000   02 50 19 05 7B 16 F9 EC 2B 11 FF    .P..{...+..
        """
        self.ms.add_response({Conversions.hex_to_ascii('026219057B0F11FF'):
                              Conversions.hex_to_ascii('026219057B0F11FF06') + \
                              Conversions.hex_to_ascii('025019057B16F9EC2B11FF')})
        response = self.insteon.on('19.05.7b')
        #time.sleep(4000)
        self.assertEqual(response, True)

    def test_insteon_level(self):
        response = self.insteon.l40('19.05.7b')
        self.assertEqual(response, False)
Example #2
0
 def test_insteon_level2(self):
     m = Mock()
     m.disabled.return_value = False
     i = InsteonPLM(m)
     i.level('12.20.B0', 50)
     #todo: figure out how to really deal with this race condition
     time.sleep(3)
     m.write.assert_called_with(unhexlify('02621220b00f117f'))
    def setUp(self):
        self.ms = MockInterface()
        if self.useMock:  # Use Mock Serial Port
            self.insteon = InsteonPLM(self.ms)
        else:
# If we are running live, the insteon interface doesnt like to be bombarded with requests
#            time.sleep(3)
#            self.serial = Serial('/dev/ttyUSB0', 4800)
#            self.insteon = InsteonPLM(self.serial)
            self.tcp = TCP('192.168.13.146', 9761)
            self.insteon = InsteonPLM(self.tcp)
Example #4
0
 def setUp(self):
     self.ms = Mock_Interface()
     self.insteon = InsteonPLM(self.ms)
Example #5
0
class InsteonInterfaceTests(TestCase):
    useMock = True

    def setUp(self):
        self.ms = Mock_Interface()
        self.insteon = InsteonPLM(self.ms)

# If we are running live, the insteon interface doesnt like to be bombarded with requests
#            time.sleep(3)
#            self.serial = Serial('/dev/ttyUSB0', 4800)
#            self.insteon = InsteonPLM(self.serial)
#            self.tcp = TCP('192.168.13.146', 9761)
#            self.insteon = InsteonPLM2(self.tcp)

        #self.insteon.start()

    def tearDown(self):
        self.insteon.shutdown()
        self.serial = None
        try:
            self.tcp.shutdown()
            self.tcp = None
        except:
            pass

    def test_instantiation(self):
        self.assertIsNotNone(self.insteon,
                             'Insteon interface could not be instantiated')

    def test_device_on(self):
        """
        Transmit>
        0000   02 62 19 05 7B 0F 11 FF    .b..{...
        <  0000   02 62 19 05 7B 0F 11 FF 06    .b..{....
        <  0000   02 50 19 05 7B 16 F9 EC 2B 11 FF    .P..{...+..
        """
#        self.ms.add_response({Conversions.hex_to_ascii('026219057B0F11FF'):
#                              Conversions.hex_to_ascii('026219057B0F11FF06') + \
#                              Conversions.hex_to_ascii('025019057B16F9EC2B11FF')})
        response = self.insteon.on('19.05.7b')
        self.assertIn(Conversions.hex_to_ascii('026219057B0F11FF'), self.ms.query_write_data())
        self.ms.put_read_data(Conversions.hex_to_ascii('026219057B0F11FF06'))
        self.ms.put_read_data(Conversions.hex_to_ascii('025019057B16F9EC2B11FF'))
        time.sleep(2)
        self.assertEqual(response, True)
        
    def test_insteon_level2(self):
        self.ms.disabled = False
        
        self.insteon.level('12.20.B0', 50)
        #todo: figure out how to really deal with this race condition
        time.sleep(3)
        self.assertIn(unhexlify('02621220b00f117f'), self.ms.query_write_data())
#        self.ms.write.assert_called_with(unhexlify('02621220b00f117f'))

    def test_insteon_receive_status(self):
        """
        [2013/09/07 15:24:51] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 00 00 01 CB 11 00    .P#........
        d395e51a11bb096e20f9ae84b47f8884
        
        [2013/09/07 15:24:51] [WARNING] [InsteonPLM] Unhandled packet (couldn't find any pending command to deal with it) 
        [2013/09/07 15:24:51] [WARNING] [InsteonPLM] This could be a status message from a broadcast
        [2013/09/07 15:24:51] [DEBUG] [InsteonPLM] Running status request..........
        [2013/09/07 15:24:51] [DEBUG] [InsteonPLM] Command: 23.D2.BE 19 00
        [2013/09/07 15:24:51] [DEBUG] [InsteonPLM] Queued bff1ddfd362ac6ef71555d959edbb90a
        [2013/09/07 15:24:53] [DEBUG] [InsteonPLM] Timed out for bff1ddfd362ac6ef71555d959edbb90a - Requeueing (already had 0 retries)
        [2013/09/07 15:24:53] [DEBUG] [InsteonPLM] Interesting.  timed out for bff1ddfd362ac6ef71555d959edbb90a, but there are no pending com$
        [2013/09/07 15:24:53] [DEBUG] [InsteonPLM] Removing Lock <thread.lock object at 0x1a7f030>
        [2013/09/07 15:24:53] [DEBUG] [InsteonPLM] Transmit>026223d2be0f1900
        [2013/09/07 15:24:53] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 22 FF 5B 41 11 01    .P#..".[A..
        4996cf7dd3a4b4722f120dc9c0fe5b17
        
        [2013/09/07 15:24:53] [WARNING] [InsteonPLM] Unhandled packet (couldn't find any pending command to deal with it)
        [2013/09/07 15:24:53] [WARNING] [InsteonPLM] This could be a status message from a broadcast
        [2013/09/07 15:24:53] [DEBUG] [InsteonPLM] Running status request..........
        [2013/09/07 15:24:53] [DEBUG] [InsteonPLM] Command: 23.D2.BE 19 00
        
        """
        global logging_default_level
        ## Default logging level
        #logging_default_level = "DEBUG"
        self._result = False
        self.insteon.onCommand(self._insteon_receive_status_callback, '23.D2.BE')
        self.ms.put_read_data(Conversions.hex_to_ascii('025023D2BE000001CB1100'))
        time.sleep(1)
        # Transmits: 026223d2be0f1900
        self.ms.put_read_data(Conversions.hex_to_ascii('025023D2BE22FF5B411101'))
        time.sleep(3)
        self.assertEqual(self._result, True)

    def _insteon_receive_status_callback(self, *args, **kwargs):
        command = kwargs.get('command', None)
        print 'command:' + command
        if command == Command.ON:
            self._result = True

    def test_insteon_status(self):
        response = self.insteon.status('44.33.22')
        self.assertEqual(response, True)
 def test_insteon_level2(self):
     m = Mock()
     m.disabled.return_value = False
     i = InsteonPLM(m)
     i.level('12.20.B0', 50)
     m.write.assert_called_with(unhexlify('02621220b00f117f'))
Example #7
0
import select
import time

from pytomation.interfaces import Serial, W800rf32, InsteonPLM, Wtdio, NamedPipe, \
                                StateInterface, Command, HTTPServer
from pytomation.devices import Motion, Door, Light, Location, InterfaceDevice, Room, \
                                Photocell, Generic, StateDevice, State, Attribute


###################### INTERFACE CONFIG #########################
web = HTTPServer()

insteon = InsteonPLM(Serial('/dev/ttyR2', 19200, xonxoff=False))
wtdio = Wtdio(Serial('/dev/mh_weeder_port', 9600))
w800 = W800rf32(Serial('/dev/mh_w800_port', 4800, xonxoff=False))

# Set the I/O points as inputs on the wtdio board, these are all set as inputs
wtdio.setChannel('ASA')
wtdio.setChannel('ASB')
wtdio.setChannel('ASC')
wtdio.setChannel('ASD')
wtdio.setChannel('ASE')
wtdio.setChannel('ASF')
wtdio.setChannel('ASG')

#wtdio.dio_invert('G')

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

# ______ REMOTES ____________________________________________________
Example #8
0
 def setUp(self):
     self.ms = Mock_Interface()
     self.insteon = InsteonPLM(self.ms)
Example #9
0
class InsteonInterfaceTests(TestCase):
    useMock = True

    def setUp(self):
        self.ms = Mock_Interface()
        self.insteon = InsteonPLM(self.ms)

# If we are running live, the insteon interface doesnt like to be bombarded with requests
#            time.sleep(3)
#            self.serial = Serial('/dev/ttyUSB0', 4800)
#            self.insteon = InsteonPLM(self.serial)
#            self.tcp = TCP('192.168.13.146', 9761)
#            self.insteon = InsteonPLM2(self.tcp)

#self.insteon.start()

    def tearDown(self):
        self.insteon.shutdown()
        self.serial = None
        try:
            self.tcp.shutdown()
            self.tcp = None
        except:
            pass

    def test_instantiation(self):
        self.assertIsNotNone(self.insteon,
                             'Insteon interface could not be instantiated')

    def test_device_on(self):
        """
        Transmit>
        0000   02 62 19 05 7B 0F 11 FF    .b..{...
        <  0000   02 62 19 05 7B 0F 11 FF 06    .b..{....
        <  0000   02 50 19 05 7B 16 F9 EC 2B 11 FF    .P..{...+..
        """
        #        self.ms.add_response({Conversions.hex_to_ascii('026219057B0F11FF'):
        #                              Conversions.hex_to_ascii('026219057B0F11FF06') + \
        #                              Conversions.hex_to_ascii('025019057B16F9EC2B11FF')})
        response = self.insteon.on('19.05.7b')
        self.assertIn(Conversions.hex_to_ascii('026219057B0F11FF'),
                      self.ms.query_write_data())
        self.ms.put_read_data(Conversions.hex_to_ascii('026219057B0F11FF06'))
        self.ms.put_read_data(
            Conversions.hex_to_ascii('025019057B16F9EC2B11FF'))
        time.sleep(2)
        self.assertEqual(response, True)

    def test_insteon_level2(self):
        self.ms.disabled = False

        self.insteon.level('12.20.B0', 50)
        #todo: figure out how to really deal with this race condition
        time.sleep(3)
        self.assertIn(unhexlify('02621220b00f117f'),
                      self.ms.query_write_data())


#        self.ms.write.assert_called_with(unhexlify('02621220b00f117f'))

    def test_insteon_receive_status(self):
        """
[2013/10/09 19:56:54] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 00 00 01 CB 11 00    .P#........
d395e51a11bb096e20f9ae84b47f8884

[2013/10/09 19:56:54] [WARNING] [InsteonPLM] Unhandled packet (couldn't find any pending command to deal with it)
[2013/10/09 19:56:54] [WARNING] [InsteonPLM] This could be a status message from a broadcast
[2013/10/09 19:56:54] [DEBUG] [InsteonPLM] HandleStandDirect
[2013/10/09 19:56:54] [DEBUG] [InsteonPLM] Running status request:False:True:True:..........
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Command: 23.D2.BE 19 00
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Queued bff1ddfd362ac6ef71555d959edbb90a
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Transmit>026223d2be0f1900
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] TransmitResult>8
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 22 FF 5B 41 11 01    .P#..".[A..
4996cf7dd3a4b4722f120dc9c0fe5b17

[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] ValidResponseCheck: 0000   53 44 31 39                SD19

[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] ValidResponseCheck2: {'callBack': <bound method InsteonPLM._handle_StandardDirect_LightSta$
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] ValidResponseCheck3: ['SD19']
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Valid Insteon Command COde: SD11
[2013/10/09 19:56:55] [WARNING] [InsteonPLM] Unhandled packet (couldn't find any pending command to deal with it)
[2013/10/09 19:56:55] [WARNING] [InsteonPLM] This could be a status message from a broadcast
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] HandleStandDirect
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Setting status for:23.D2.BE:17:1..........
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Received Command:23.D2.BE:on
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Delegates for Command: []
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Devices for Command: []
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Received Command:23.D2.BE:on
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Delegates for Command: []
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Devices for Command: []
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Received a Modem NAK! Resending command, loop time 0.400000
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Queued bff1ddfd362ac6ef71555d959edbb90a
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Received a Modem NAK! Resending command, loop time 0.600000
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Transmit>026223d2be0f1900
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] TransmitResult>8
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 11 01 01 CB 06 00    .P#........
0e3a2974df58ef76268f23a48ec650a9

        """
        global logging_default_level
        ## Default logging level
        #logging_default_level = "DEBUG"
        self._result = False
        self.insteon.onCommand(self._insteon_receive_status_callback,
                               '23.D2.BE')
        self.ms.put_read_data(
            Conversions.hex_to_ascii('025023D2BE000001CB1100'))
        time.sleep(1)
        # Transmits: 026223d2be0f1900
        self.ms.put_read_data(
            Conversions.hex_to_ascii('025023D2BE22FF5B411101'))
        time.sleep(3)
        self.assertEqual(self._result, Command.ON)

    def _insteon_receive_status_callback(self, *args, **kwargs):
        command = kwargs.get('command', None)
        print 'command:' + command
        self._result = command

    def test_insteon_status(self):
        response = self.insteon.status('44.33.22')
        self.assertEqual(response, True)

    def test_insteon_receive_status2(self):
        """
Receive Broadcast OFF command from a remote device
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 00 00 01 CB 13 00    .P#........
Message Flags = CB = 1100 1011
b1 = broadcast
b2 = group
b3 = ack
b4 = extended
b56 = hops left
b78 = max hops
[2013/10/07 20:37:40] [DEBUG] [InsteonPLM] Running status request:False:True:True:..........
[2013/10/07 20:37:40] [DEBUG] [InsteonPLM] Command: 23.D2.BE 19 00
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Transmit>026223d2be0f1900
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 22 FF 5B 41 13 01    .P#..".[A..
1079120c278d439fdc0c998fe6af970e

[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] ValidResponseCheck: 0000   53 44 31 39                SD19
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Setting status for:23.D2.BE:19:1..........
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Received Command:23.D2.BE:off

        """
        self._result = None
        self.insteon.onCommand(self._insteon_receive_status_callback,
                               '23.D2.BE')
        self.ms.put_read_data(
            Conversions.hex_to_ascii('025023D2BE000001CB1300'))
        time.sleep(1)
        # Transmits: 026223d2be0f1900
        self.assertEqual(self._result, Command.OFF)

    def test_door_light_delgate_caseinsensitive(self):
        d = Door(address='23.d2.bE', devices=self.insteon)
        d.close()
        self.ms.put_read_data(
            Conversions.hex_to_ascii('025023D2BE000001CB1100'))
        time.sleep(3)
        self.ms.put_read_data(
            Conversions.hex_to_ascii('025023D2BE22FF5B411101'))
        time.sleep(3)
        self.assertEqual(d.state, State.OPEN)
Example #10
0
 def test_insteon_level2(self):
     m = Mock()
     i = InsteonPLM(m)
     i.level('12.20.B0', 50)
     m.write.assert_called_with(unhexlify('02621220b00f117f'))
from pytomation.config import *
from pytomation.interfaces import InsteonPLM, TCP

debug['Insteon'] = 1
tcp = TCP('192.168.13.146', 9761)
insteon = InsteonPLM(tcp)
insteon.start()

# Turn on Light - Address 19.05.7b
response = insteon.on('19.05.7b')

# Turn off Light - Address 19.05.7b
response2 = insteon.off('19.05.7b')

# Check for success
if response:
    print "Message was successfully sent!"
else:
    print "Interface not responding"

# Code is done, we no longer need the interface
insteon.shutdown()
tcp.shutdown()
Example #12
0
# import the standard python modules "select" and "time"
import select
import time

# Import all the Pytomation interfaces we are going to use.
from pytomation.interfaces import InsteonPLM, Serial, HTTP, VenstarThermostat, Command, PytoWebSocketServer, Open_zwave

# Import all the Pytomation Devices we will use.
from pytomation.devices import Attribute, Light, Location, Thermostat, Room, Door, Lock
#from pytomation.devices.scene import Scene

#Web Server
websocket = PytoWebSocketServer()

#Interfaces
insteon = InsteonPLM(Serial('/dev/insteon', 19200, xonxoff=False))
ozw = Open_zwave(serialDevicePath="/dev/zwave", config_path="/etc/openzwave")

#Thermostat (override available commads)
thermostat_commands = [
    Command.AUTOMATIC, Command.COOL, Command.HEAT, Command.HOLD,
    Command.SCHEDULE, Command.OFF, Command.LEVEL, Command.CIRCULATE,
    Command.STILL, Command.VACATE, Command.OCCUPY, Command.SETPOINT
]
hall_thermostat = Thermostat(commands=thermostat_commands,
                             name="Thermostat",
                             devices=VenstarThermostat(
                                 HTTP(host='HallThermostat')))

#Sensors
ph_calculated = Location('38.576492',
Example #13
0
class InsteonInterfaceTests(TestCase):
    useMock = True

    def setUp(self):
        self.ms = Mock_Interface()
        self.insteon = InsteonPLM(self.ms)

# If we are running live, the insteon interface doesnt like to be bombarded with requests
#            time.sleep(3)
#            self.serial = Serial('/dev/ttyUSB0', 4800)
#            self.insteon = InsteonPLM(self.serial)
#            self.tcp = TCP('192.168.13.146', 9761)
#            self.insteon = InsteonPLM2(self.tcp)

        #self.insteon.start()

    def tearDown(self):
        self.insteon.shutdown()
        self.serial = None
        try:
            self.tcp.shutdown()
            self.tcp = None
        except:
            pass

    def test_instantiation(self):
        self.assertIsNotNone(self.insteon,
                             'Insteon interface could not be instantiated')

    def test_device_on(self):
        """
        Transmit>
        0000   02 62 19 05 7B 0F 11 FF    .b..{...
        <  0000   02 62 19 05 7B 0F 11 FF 06    .b..{....
        <  0000   02 50 19 05 7B 16 F9 EC 2B 11 FF    .P..{...+..
        """
#        self.ms.add_response({Conversions.hex_to_ascii('026219057B0F11FF'):
#                              Conversions.hex_to_ascii('026219057B0F11FF06') + \
#                              Conversions.hex_to_ascii('025019057B16F9EC2B11FF')})
        response = self.insteon.on('19.05.7b')
        self.assertIn(Conversions.hex_to_ascii('026219057B0F11FF'), self.ms.query_write_data())
        self.ms.put_read_data(Conversions.hex_to_ascii('026219057B0F11FF06'))
        self.ms.put_read_data(Conversions.hex_to_ascii('025019057B16F9EC2B11FF'))
        time.sleep(2)
        self.assertEqual(response, True)
        
    def test_insteon_level2(self):
        self.ms.disabled = False
        
        self.insteon.level('12.20.B0', 50)
        #todo: figure out how to really deal with this race condition
        time.sleep(3)
        self.assertIn(unhexlify('02621220b00f117f'), self.ms.query_write_data())
#        self.ms.write.assert_called_with(unhexlify('02621220b00f117f'))

    def test_insteon_receive_status(self):
        """
[2013/10/09 19:56:54] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 00 00 01 CB 11 00    .P#........
d395e51a11bb096e20f9ae84b47f8884

[2013/10/09 19:56:54] [WARNING] [InsteonPLM] Unhandled packet (couldn't find any pending command to deal with it)
[2013/10/09 19:56:54] [WARNING] [InsteonPLM] This could be a status message from a broadcast
[2013/10/09 19:56:54] [DEBUG] [InsteonPLM] HandleStandDirect
[2013/10/09 19:56:54] [DEBUG] [InsteonPLM] Running status request:False:True:True:..........
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Command: 23.D2.BE 19 00
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Queued bff1ddfd362ac6ef71555d959edbb90a
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Transmit>026223d2be0f1900
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] TransmitResult>8
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 22 FF 5B 41 11 01    .P#..".[A..
4996cf7dd3a4b4722f120dc9c0fe5b17

[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] ValidResponseCheck: 0000   53 44 31 39                SD19

[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] ValidResponseCheck2: {'callBack': <bound method InsteonPLM._handle_StandardDirect_LightSta$
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] ValidResponseCheck3: ['SD19']
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Valid Insteon Command COde: SD11
[2013/10/09 19:56:55] [WARNING] [InsteonPLM] Unhandled packet (couldn't find any pending command to deal with it)
[2013/10/09 19:56:55] [WARNING] [InsteonPLM] This could be a status message from a broadcast
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] HandleStandDirect
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Setting status for:23.D2.BE:17:1..........
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Received Command:23.D2.BE:on
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Delegates for Command: []
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Devices for Command: []
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Received Command:23.D2.BE:on
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Delegates for Command: []
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Devices for Command: []
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Received a Modem NAK! Resending command, loop time 0.400000
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Queued bff1ddfd362ac6ef71555d959edbb90a
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Received a Modem NAK! Resending command, loop time 0.600000
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Transmit>026223d2be0f1900
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] TransmitResult>8
[2013/10/09 19:56:55] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 11 01 01 CB 06 00    .P#........
0e3a2974df58ef76268f23a48ec650a9

        """
        global logging_default_level
        ## Default logging level
        #logging_default_level = "DEBUG"
        self._result = False
        self.insteon.onCommand(self._insteon_receive_status_callback, '23.D2.BE')
        self.ms.put_read_data(Conversions.hex_to_ascii('025023D2BE000001CB1100'))
        time.sleep(1)
        # Transmits: 026223d2be0f1900
        self.ms.put_read_data(Conversions.hex_to_ascii('025023D2BE22FF5B411101'))
        time.sleep(3)
        self.assertEqual(self._result, Command.ON)

    def _insteon_receive_status_callback(self, *args, **kwargs):
        command = kwargs.get('command', None)
        print 'command:' + command
        self._result = command

    def test_insteon_status(self):
        response = self.insteon.status('44.33.22')
        self.assertEqual(response, True)
        
    def test_insteon_receive_status2(self):
        """
Receive Broadcast OFF command from a remote device
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 00 00 01 CB 13 00    .P#........
Message Flags = CB = 1100 1011
b1 = broadcast
b2 = group
b3 = ack
b4 = extended
b56 = hops left
b78 = max hops
[2013/10/07 20:37:40] [DEBUG] [InsteonPLM] Running status request:False:True:True:..........
[2013/10/07 20:37:40] [DEBUG] [InsteonPLM] Command: 23.D2.BE 19 00
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Transmit>026223d2be0f1900
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Receive< 0000   02 50 23 D2 BE 22 FF 5B 41 13 01    .P#..".[A..
1079120c278d439fdc0c998fe6af970e

[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] ValidResponseCheck: 0000   53 44 31 39                SD19
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Setting status for:23.D2.BE:19:1..........
[2013/10/07 20:37:42] [DEBUG] [InsteonPLM] Received Command:23.D2.BE:off

        """
        self._result = None
        self.insteon.onCommand(self._insteon_receive_status_callback, '23.D2.BE')
        self.ms.put_read_data(Conversions.hex_to_ascii('025023D2BE000001CB1300'))
        time.sleep(1)
        # Transmits: 026223d2be0f1900
        self.assertEqual(self._result, Command.OFF)

    def test_door_light_delgate_caseinsensitive(self):
        d = Door(address='23.d2.bE', 
                 devices=self.insteon)
        d.close()
        self.ms.put_read_data(Conversions.hex_to_ascii('025023D2BE000001CB1100'))
        time.sleep(3)
        self.ms.put_read_data(Conversions.hex_to_ascii('025023D2BE22FF5B411101'))
        time.sleep(3)
        self.assertEqual(d.state, State.OPEN)
Example #14
0
import select
import time

from pytomation.interfaces import Serial, W800rf32, InsteonPLM, Wtdio, NamedPipe, \
                                StateInterface, Command, HTTPServer
from pytomation.devices import Motion, Door, Light, Location, InterfaceDevice, Room, \
                                Photocell, Generic, StateDevice, State, Attribute


###################### INTERFACE CONFIG #########################
web = HTTPServer()

insteon = InsteonPLM(Serial('/dev/ttyR2', 19200, xonxoff=False))
wtdio = Wtdio(Serial('/dev/mh_weeder_port', 9600))
w800 = W800rf32(Serial('/dev/mh_w800_port', 4800, xonxoff=False))

# Set the I/O points as inputs on the wtdio board, these are all set as inputs
wtdio.setChannel('ASA')
wtdio.setChannel('ASB')
wtdio.setChannel('ASC')
wtdio.setChannel('ASD')
wtdio.setChannel('ASE')
wtdio.setChannel('ASF')
wtdio.setChannel('ASG')

#wtdio.dio_invert('G')

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

# ______ REMOTES ____________________________________________________ 
Example #15
0
                                Room, Thermostat, XMPP_Client

#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)