Пример #1
0
 async def test_other_status(self):
     """Test other status command and confirm first handler does not handle."""
     status_type = 1
     status_1_command = StatusRequestCommand(self._address,
                                             status_type=status_type)
     status_1_command.subscribe(self.set_status_1)
     cmd1 = 0x19
     cmd2 = 0x01
     db_version = 0x66
     status = 0x77
     topics = [
         TopicItem(self.ack_topic, {
             "cmd1": cmd1,
             "cmd2": cmd2,
             "user_data": None
         }, 0.5),
         TopicItem(
             self.direct_ack_topic,
             {
                 "cmd1": db_version,
                 "cmd2": status,
                 "target": "112233",
                 "user_data": None,
                 "hops_left": 3,
             },
             0.5,
         ),
     ]
     send_topics(topics)
     assert await status_1_command.async_send()
     await asyncio.sleep(1)
     assert self._db_version_1 == db_version
     assert self._status_1 == status
     assert self._db_version is None
     assert self._status is None
Пример #2
0
 def setUp(self):
     """Set up the test."""
     self._address = random_address()
     self._db_version = None
     self._status = None
     self._db_version_1 = None
     self._status_1 = None
     self.status_command = StatusRequestCommand(self._address, status_type=0)
     self.status_command.subscribe(self.set_status)
     self.ack_topic = "ack.{}.status_request.direct".format(self._address.id)
     self.direct_ack_topic = "{}.any_topic.direct_ack".format(self._address.id)
     set_log_levels(
         logger="info",
         logger_pyinsteon="info",
         logger_messages="info",
         logger_topics=False,
     )
Пример #3
0
    async def test_status_with_fast_direct_ack(self):
        """Test STATUS REQUEST with fast direct ack response."""
        response_called = False

        def handle_status_response(db_version, status):
            """Handle the ON command response."""
            nonlocal response_called
            response_called = True

        set_log_levels(logger_topics=True)

        address = random_address()
        target = random_address()
        status_type = randint(0, 10)
        cmd = StatusRequestCommand(address, status_type)
        cmd.subscribe(handle_status_response)
        ack_topic = build_topic(STATUS_REQUEST, "ack", address, None,
                                MessageFlagType.DIRECT)
        direct_ack_topic = build_topic(ON, None, address, None,
                                       MessageFlagType.DIRECT_ACK)
        ack_topic_item = TopicItem(
            topic=ack_topic,
            kwargs={
                "cmd1": 0x19,
                "cmd2": status_type,
                "user_data": None
            },
            delay=0.1,
        )
        direct_ack_topic_item = TopicItem(
            topic=direct_ack_topic,
            kwargs={
                "cmd1": 0x11,
                "cmd2": 0x02,
                "target": target,
                "user_data": None,
                "hops_left": 0,
            },
            delay=0,
        )
        send_topics([ack_topic_item, direct_ack_topic_item])
        await asyncio.sleep(0.2)
        assert response_called
Пример #4
0
    async def test_status_request_hub(self):
        """Test a status request coming from the Hub.

        This starts with an ACK message rather than a send() command.
        """
        self.status_command = StatusRequestCommand(self._address,
                                                   status_type=0)
        self.status_command.subscribe(self.set_status)
        cmd1 = 0x19
        cmd2 = 0x00
        db_version = 0x44
        status = 0x55
        topics = [
            TopicItem(
                self.ack_topic,
                {
                    "cmd1": cmd1,
                    "cmd2": cmd2,
                    "user_data": None
                },
                0.1,
            ),
            TopicItem(
                self.direct_ack_topic,
                {
                    "cmd1": db_version,
                    "cmd2": status,
                    "target": "aabbcc",
                    "user_data": None,
                    "hops_left": 3,
                },
                0.2,
            ),
        ]
        send_topics(topics)
        await asyncio.sleep(0.5)
        assert self._db_version == db_version
        assert self._status == status
Пример #5
0
 async def test_status_command(self):
     """Test Status Request command."""
     self.status_command = StatusRequestCommand(self._address,
                                                status_type=0)
     self.status_command.subscribe(self.set_status)
     cmd1 = 0x19
     cmd2 = 0x00
     db_version = 0x22
     status = 0x33
     topics = [
         TopicItem(
             self.ack_topic,
             {
                 "cmd1": cmd1,
                 "cmd2": cmd2,
                 "user_data": None
             },
             0.5,
         ),
         TopicItem(
             self.direct_ack_topic,
             {
                 "cmd1": db_version,
                 "cmd2": status,
                 "target": "112233",
                 "user_data": None,
                 "hops_left": 3,
             },
             0.5,
         ),
     ]
     send_topics(topics)
     assert await self.status_command.async_send()
     await asyncio.sleep(1)
     assert self._db_version == db_version
     assert self._status == status
Пример #6
0
class TestStatusRequest(unittest.TestCase):
    """Test the id_request command handler."""
    def setUp(self):
        """Set up the test."""
        self._address = random_address()
        self._db_version = None
        self._status = None
        self._db_version_1 = None
        self._status_1 = None
        self.ack_topic = f"ack.{self._address.id}.status_request.direct"
        self.direct_ack_topic = f"{self._address.id}.any_topic.direct_ack"
        set_log_levels(
            logger="debug",
            logger_pyinsteon="info",
            logger_messages="info",
            logger_topics=True,
        )

    def set_status(self, db_version, status):
        """Handle callback to on_level direct_ack."""
        self._db_version = db_version
        self._status = status

    def set_status_1(self, db_version, status):
        """Handle callback to on_level direct_ack."""
        self._db_version_1 = db_version
        self._status_1 = status

    @async_case
    async def test_status_command(self):
        """Test Status Request command."""
        self.status_command = StatusRequestCommand(self._address,
                                                   status_type=0)
        self.status_command.subscribe(self.set_status)
        cmd1 = 0x19
        cmd2 = 0x00
        db_version = 0x22
        status = 0x33
        topics = [
            TopicItem(
                self.ack_topic,
                {
                    "cmd1": cmd1,
                    "cmd2": cmd2,
                    "user_data": None
                },
                0.5,
            ),
            TopicItem(
                self.direct_ack_topic,
                {
                    "cmd1": db_version,
                    "cmd2": status,
                    "target": "112233",
                    "user_data": None,
                    "hops_left": 3,
                },
                0.5,
            ),
        ]
        send_topics(topics)
        assert await self.status_command.async_send()
        await asyncio.sleep(1)
        assert self._db_version == db_version
        assert self._status == status

    @async_case
    async def test_status_request_hub(self):
        """Test a status request coming from the Hub.

        This starts with an ACK message rather than a send() command.
        """
        self.status_command = StatusRequestCommand(self._address,
                                                   status_type=0)
        self.status_command.subscribe(self.set_status)
        cmd1 = 0x19
        cmd2 = 0x00
        db_version = 0x44
        status = 0x55
        topics = [
            TopicItem(
                self.ack_topic,
                {
                    "cmd1": cmd1,
                    "cmd2": cmd2,
                    "user_data": None
                },
                0.1,
            ),
            TopicItem(
                self.direct_ack_topic,
                {
                    "cmd1": db_version,
                    "cmd2": status,
                    "target": "aabbcc",
                    "user_data": None,
                    "hops_left": 3,
                },
                0.2,
            ),
        ]
        send_topics(topics)
        await asyncio.sleep(0.5)
        assert self._db_version == db_version
        assert self._status == status

    @async_case
    async def test_other_status(self):
        """Test other status command and confirm first handler does not handle."""
        self.status_command = StatusRequestCommand(self._address,
                                                   status_type=0)
        self.status_command.subscribe(self.set_status)
        status_type = 1
        status_1_command = StatusRequestCommand(self._address,
                                                status_type=status_type)
        status_1_command.subscribe(self.set_status_1)
        cmd1 = 0x19
        cmd2 = 0x01
        db_version = 0x66
        status = 0x77
        topics = [
            TopicItem(
                self.ack_topic,
                {
                    "cmd1": cmd1,
                    "cmd2": cmd2,
                    "user_data": None
                },
                0.1,
            ),
            TopicItem(
                self.direct_ack_topic,
                {
                    "cmd1": db_version,
                    "cmd2": status,
                    "target": "112233",
                    "user_data": None,
                    "hops_left": 3,
                },
                0.1,
            ),
        ]
        self.set_status(-1, -1)
        self.set_status_1(-2, -2)
        send_topics(topics)
        assert await status_1_command.async_send()

        assert self._db_version_1 == db_version
        assert self._status_1 == status

        # Confirm status 1 did not respond.
        assert self._status == -1
        assert self._db_version == -1