Esempio n. 1
0
def test_x10():
    addr = Address.x10('A', 5)

    assert addr.hex == '000601'
    assert addr.human == 'X10.A.05'
    assert addr.is_x10
    assert addr.x10_housecode == 'A'
    assert addr.x10_unitcode == 5
    assert addr.x10_housecode_byte == 6
    assert addr.x10_unitcode_byte == 1

    addr2 = Address.x10('A', 20)
    assert addr2.human == 'X10.A.20'
Esempio n. 2
0
 def __init__(self, plm, housecode, unitcode):
     """Initialize the X10Device class."""
     self._address = Address.x10(housecode, unitcode)
     self._plm = plm
     self._description = "Generic X10 device"
     self._model = ''
     self._aldb = ALDB(None, None, self._address, version=ALDBVersion.Null)
     self._message_callbacks = MessageCallback()
     self._stateList = StateList()
     self._send_msg_lock = asyncio.Lock(loop=self._plm.loop)
     self.log = logging.getLogger()
Esempio n. 3
0
 def _handle_x10_send_receive(self, msg):
     housecode_byte, unit_command_byte = rawX10_to_bytes(msg.rawX10)
     housecode = byte_to_housecode(housecode_byte)
     if msg.flag == 0x00:
         unitcode = byte_to_unitcode(unit_command_byte)
         self._x10_address = Address.x10(housecode, unitcode)
         if self._x10_address:
             device = self.devices[self._x10_address.id]
             if device:
                 device.receive_message(msg)
     else:
         self._x10_command_to_device(housecode, unit_command_byte, msg)
Esempio n. 4
0
async def do_plm_x10(loop):
    """Asyncio coroutine to test the PLM X10 message handling."""
    _LOGGER.setLevel(logging.DEBUG)
    _LOGGER.info('Connecting to Insteon PLM')

    # pylint: disable=not-an-iterable
    conn = await MockConnection.create(loop=loop)

    cb = MockCallbacks()

    plm = conn.protocol
    plm.connection_made(conn.transport)

    _LOGGER.info('Replying with IM Info')
    _LOGGER.info('_____________________')
    cmd_sent = await wait_for_plm_command(plm, GetImInfo(), loop)
    if not cmd_sent:
        assert False
    msg = insteonplm.messages.getIMInfo.GetImInfo(address='1a2b3c',
                                                  cat=0x03,
                                                  subcat=0x20,
                                                  firmware=0x00,
                                                  acknak=MESSAGE_ACK)
    plm.data_received(msg.bytes)
    await asyncio.sleep(RECV_MSG_WAIT, loop=loop)

    _LOGGER.info('Replying with an All-Link Record NAK')
    _LOGGER.info('____________________________________')
    cmd_sent = await wait_for_plm_command(plm, GetFirstAllLinkRecord(), loop)
    if not cmd_sent:
        assert False
    msg = GetFirstAllLinkRecord(MESSAGE_NAK)
    plm.data_received(msg.bytes)
    await asyncio.sleep(RECV_MSG_WAIT, loop=loop)

    _LOGGER.info('Add X10 device and receive messages')
    _LOGGER.info('____________________________________')
    housecode = 'C'
    unitcode = 9
    plm.add_x10_device(housecode, unitcode, 'OnOff')
    x10_id = Address.x10(housecode, unitcode).id
    plm.devices[x10_id].states[0x01].register_updates(cb.callbackmethod1)

    msg = X10Received.unit_code_msg(housecode, unitcode)
    plm.data_received(msg.bytes)
    await asyncio.sleep(.1, loop=loop)
    msg = X10Received.command_msg(housecode, X10_COMMAND_ON)
    plm.data_received(msg.bytes)
    await asyncio.sleep(.1, loop=loop)
    assert cb.callbackvalue1 == 0xff

    msg = X10Received.unit_code_msg(housecode, unitcode)
    plm.data_received(msg.bytes)
    await asyncio.sleep(.1, loop=loop)
    msg = X10Received.command_msg(housecode, X10_COMMAND_OFF)
    plm.data_received(msg.bytes)
    await asyncio.sleep(.1, loop=loop)
    assert cb.callbackvalue1 == 0x00

    _LOGGER.info('Close PLM')
    _LOGGER.info('_________')

    await plm.close()
    _LOGGER.error('PLM closed in test_x10')
    await asyncio.sleep(.1, loop=loop)
    open_tasks = asyncio.Task.all_tasks(loop=loop)
    for task in open_tasks:
        if hasattr(task, 'name'):
            _LOGGER.error('Device: %s Task: %s', task.name, task)
        else:
            _LOGGER.error('Task: %s', task)