Exemple #1
0
    async def test_message_to_topic(self):
        """Test converting a message to a topic."""
        async with async_protocol_manager() as protocol:
            tests = await import_commands()

            for test_info in tests:
                self._topic = None
                address = repr(random_address())
                curr_test = tests[test_info]
                if curr_test.get("address"):
                    curr_test["address"] = address
                msgs = [create_message(curr_test)]
                curr_topic = curr_test["topic"].format(address)
                pub.subscribe(self.capture_topic, curr_topic)
                send_data(msgs, protocol.read_queue)
                await sleep(0.07)
                try:
                    assert self._topic.name == curr_topic
                except (AssertionError, AttributeError):
                    raise AssertionError(
                        "Failed test {} with message topic {} and test topic {}".format(
                            test_info, self._topic.name, curr_test.get("topic")
                        )
                    )
                finally:
                    pub.unsubscribe(self.capture_topic, curr_topic)
Exemple #2
0
def set_log_levels(
    logger="info", logger_pyinsteon="info", logger_messages="info", logger_topics=False
):
    """Set the log levels of the three logs."""
    _setup_logger(_LOGGER, logger)
    _setup_logger(_LOGGER_PYINSTEON, logger_pyinsteon)
    _setup_logger(_LOGGER_MESSAGES, logger_messages)
    if logger_topics:
        _setup_logger(_LOGGER_TOPICS, "info")
        pub.subscribe(_log_all_topics, pub.ALL_TOPICS)
    else:
        _setup_logger(_LOGGER_TOPICS, "fatal")
        pub.unsubscribe(_log_all_topics, pub.ALL_TOPICS)
    async def test_load_empty(self):
        """Test loading an empty modem ALDB."""
        async with LOCK:
            mgr = pub.getDefaultTopicMgr()
            mgr.delTopic(ALL_LINK_RECORD_RESPONSE)
            aldb = ModemALDB(random_address())
            pub.subscribe(send_nak_response, SEND_FIRST_TOPIC)

            response = await aldb.async_load()
            _LOGGER.debug("Done LOAD function.")
            _LOGGER.debug("Status: %s", response.name)
            assert aldb.is_loaded
            _LOGGER.debug("ALDB Record Count: %d", len(aldb))
            assert len(aldb) == 0
            pub.unsubscribe(send_nak_response, SEND_FIRST_TOPIC)
Exemple #4
0
    async def test_all_lights_on(self):
        """Test the All Lights On command."""
        call_received = False

        def check_x10_call(raw_x10, x10_flag):
            """Check the X10 call params."""
            nonlocal call_received
            call_received = True
            assert raw_x10 == 0x61
            assert x10_flag == 0x80

        topic = "send.x10_send"
        pub.subscribe(check_x10_call, topic)
        await async_x10_all_lights_on(housecode="a")
        await asyncio.sleep(0.05)
        assert call_received
        pub.unsubscribe(check_x10_call, topic)
    async def test_load_8_records_eeprom(self):
        """Test loading 8 records into the modem ALDB."""
        async with LOCK:
            mgr = pub.getDefaultTopicMgr()
            mgr.delTopic(ALL_LINK_RECORD_RESPONSE)
            pub.subscribe(self.send_eeprom_response, SEND_READ_EEPROM_TOPIC)

            aldb = ModemALDB(random_address())
            aldb.read_write_mode = ReadWriteMode.EEPROM
            response = await aldb.async_load()
            await asyncio.sleep(0.01)
            _LOGGER.debug("Done LOAD function.")
            _LOGGER.debug("Status: %s", response.name)
            assert aldb.is_loaded
            _LOGGER.debug("ALDB Record Count: %d", len(aldb))
            assert len(aldb) == 9  # Includes HWM record
            pub.unsubscribe(self.send_standard_response,
                            SEND_READ_EEPROM_TOPIC)
Exemple #6
0
def set_log_levels(logger="info",
                   logger_pyinsteon="info",
                   logger_messages="info",
                   logger_topics=False):
    """Set the log levels of the three logs."""
    try:
        assert os.environ["ALLOW_LOGGING"].lower() == "y"
    except (AssertionError, KeyError):
        return

    _setup_logger(_LOGGER, logger)
    _setup_logger(_LOGGER_PYINSTEON, logger_pyinsteon)
    _setup_logger(_LOGGER_MESSAGES, logger_messages)
    if logger_topics:
        _setup_logger(_LOGGER_TOPICS, "info")
        pub.subscribe(_log_all_topics, pub.ALL_TOPICS)
    else:
        _setup_logger(_LOGGER_TOPICS, "fatal")
        pub.unsubscribe(_log_all_topics, pub.ALL_TOPICS)