Esempio n. 1
0
 def _register_messages(self):
     super()._register_messages()
     dim_msg = X10Received.command_msg(self.address.x10_housecode,
                                       X10_COMMAND_DIM)
     bri_msg = X10Received.command_msg(self.address.x10_housecode,
                                       X10_COMMAND_BRIGHT)
     self._message_callbacks.add(dim_msg, self._dim_message_received)
     self._message_callbacks.add(bri_msg, self._bright_message_received)
Esempio n. 2
0
    def _register_messages(self):
        on_msg = X10Received.command_msg(self.address.x10_housecode,
                                         X10_COMMAND_ON)
        off_msg = X10Received.command_msg(self.address.x10_housecode,
                                          X10_COMMAND_OFF)
        all_units_off_msg = X10Received.command_msg(self.address.x10_housecode,
                                                    X10_COMMAND_ALL_UNITS_OFF)

        self._message_callbacks.add(on_msg, self._on_message_received)
        self._message_callbacks.add(off_msg, self._off_message_received)
        self._message_callbacks.add(all_units_off_msg,
                                    self._off_message_received)
Esempio n. 3
0
    def _register_message_handlers(self):
        template_all_link_response = AllLinkRecordResponse(
            None, None, None, None, None, None)
        template_get_im_info = GetImInfo()
        template_next_all_link_rec = GetNextAllLinkRecord(acknak=MESSAGE_NAK)
        template_x10_send = X10Send(None, None, MESSAGE_ACK)
        template_x10_received = X10Received(None, None)

        # self._message_callbacks.add(
        #    template_assign_all_link,
        #    self._handle_assign_to_all_link_group)

        self._message_callbacks.add(template_all_link_response,
                                    self._handle_all_link_record_response)

        self._message_callbacks.add(template_get_im_info,
                                    self._handle_get_plm_info)

        self._message_callbacks.add(template_next_all_link_rec,
                                    self._handle_get_next_all_link_record_nak)

        self._message_callbacks.add(template_x10_send,
                                    self._handle_x10_send_receive)

        self._message_callbacks.add(template_x10_received,
                                    self._handle_x10_send_receive)
Esempio n. 4
0
def test_x10received():
    """Test X10Received."""
    rawX10 = 0x11
    flag = 0x22
    msg = X10Received(rawX10, flag)
    assert msg.hex == hexmsg(0x02, 0x52, rawX10, flag)
    assert len(msg.hex) / 2 == msg.sendSize
    assert len(msg.hex) / 2 == msg.receivedSize
Esempio n. 5
0
    def run_test(loop):
        housecode = 'C'  # byte 0x02
        unitcode = 9  # byte 0x07
        plm = MockPLM(loop)
        cb = MockCallbacks()
        device = X10Dimmable(plm, housecode, unitcode, 22)
        plm.devices[device.address.id] = device
        device.states[0x01].register_updates(cb.callbackmethod1)

        msg = X10Received.command_msg(housecode, X10_COMMAND_ON)
        device.receive_message(msg)
        yield from asyncio.sleep(.1, loop=loop)
        assert cb.callbackvalue1 == 0xff

        msg = X10Received.command_msg(housecode, X10_COMMAND_OFF)
        device.receive_message(msg)
        yield from asyncio.sleep(.1, loop=loop)
        assert cb.callbackvalue1 == 0x00
Esempio n. 6
0
    def run_test(loop):
        plm = MockPLM(loop)
        callbacks = MockCallbacks()
        all_units_off = X10AllUnitsOff(plm, 'A', 20)
        all_lights_off = X10AllLightsOff(plm, 'A', 22)
        all_lights_on = X10AllLightsOn(plm, 'A', 21)

        all_units_off.states[0x01].register_updates(callbacks.callbackmethod1)
        all_lights_off.states[0x01].register_updates(callbacks.callbackmethod2)
        all_lights_on.states[0x01].register_updates(callbacks.callbackmethod3)

        msg = X10Received.command_msg('A', X10_COMMAND_ALL_UNITS_OFF)
        plm.message_received(msg)
        _LOGGER.debug('Should have 1st callback')
        yield from asyncio.sleep(.1, loop=loop)
        assert callbacks.callbackvalue1 == 0x00
        _LOGGER.debug('Should have 2nd callback')
        yield from asyncio.sleep(2, loop=loop)
        assert callbacks.callbackvalue1 == 0xff
Esempio n. 7
0
    def _register_message_handlers(self):
        template_assign_all_link = StandardReceive.template(
            commandtuple=COMMAND_ASSIGN_TO_ALL_LINK_GROUP_0X01_NONE)
        template_all_link_response = AllLinkRecordResponse(None, None, None,
                                                           None, None, None)
        template_get_im_info = GetImInfo()
        template_next_all_link_rec = GetNextAllLinkRecord(acknak=MESSAGE_NAK)
        template_all_link_complete = AllLinkComplete(None, None, None,
                                                     None, None, None)
        template_x10_send = X10Send(None, None, MESSAGE_ACK)
        template_x10_received = X10Received(None, None)

        self._message_callbacks.add(
            template_assign_all_link,
            self._handle_assign_to_all_link_group)

        self._message_callbacks.add(
            template_all_link_response,
            self._handle_all_link_record_response)

        self._message_callbacks.add(
            template_get_im_info,
            self._handle_get_plm_info)

        self._message_callbacks.add(
            template_next_all_link_rec,
            self._handle_get_next_all_link_record_nak)

        self._message_callbacks.add(
            template_all_link_complete,
            self._handle_assign_to_all_link_group)

        self._message_callbacks.add(
            template_x10_send,
            self._handle_x10_send_receive)

        self._message_callbacks.add(
            template_x10_received,
            self._handle_x10_send_receive)
Esempio n. 8
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)
Esempio n. 9
0
 def _register_messages(self):
     all_off_msg = X10Received.command_msg(self.address.x10_housecode,
                                           X10_COMMAND_ALL_LIGHTS_OFF)
     self._message_callbacks.add(all_off_msg, self._off_message_received)