Ejemplo n.º 1
0
    def send_eeprom_response(self, mem_hi, mem_low):
        """Send a response."""
        pub.sendMessage(ACK_EEPROM_TOPIC, mem_hi=mem_hi, mem_low=mem_low)

        rec_item = self.topics_eeprom[self.record]
        pub.sendMessage(rec_item.topic, **rec_item.kwargs)
        self.record += 1
Ejemplo n.º 2
0
 async def test_no_flags(self):
     """Test send standard without flags."""
     pub.sendMessage(f"send.{SEND_STANDARD}",
                     address="010203",
                     cmd1=0x11,
                     cmd2=0xAB)
     assert self.msg.cmd2 == 0xAB
Ejemplo n.º 3
0
 async def test_brighten(self):
     """Test brighten."""
     address = create("D", 9)
     topic = f"{address.id}.{str(X10Commands.BRIGHT)}"
     manager = X10DimBrightenManager(address)
     manager.subscribe(self.handle_on_off)
     pub.sendMessage(topic)
     assert self._last_value == 1
Ejemplo n.º 4
0
 def test_dim(self):
     """Test dimming."""
     address = create("D", 9)
     topic = f"{address.id}.{str(X10Commands.DIM)}"
     manager = X10DimBrightenManager(address)
     manager.subscribe(self.handle_on_off)
     pub.sendMessage(topic)
     assert self._last_value == -1
Ejemplo n.º 5
0
 async def test_all_units_off_manager(self):
     """Test all units off."""
     # Housecode B unitcode 3
     address = create("A", 7)
     topic = "x10{}.{}".format(address.housecode.lower(),
                               str(X10Commands.ALL_UNITS_OFF))
     manager = X10AllUnitsOffManager(address)
     manager.subscribe(self.handle_on_off)
     pub.sendMessage(topic)
     assert self._last_value == 0x00
Ejemplo n.º 6
0
 async def test_all_lights_on_manager(self):
     """Test all lights on manager."""
     address = create("C", 5)
     topic = "x10{}.{}".format(address.housecode.lower(),
                               str(X10Commands.ALL_LIGHTS_ON))
     manager = X10AllLightsOnOffManager(address)
     manager.subscribe(self.handle_on_off)
     manager.subscribe_on(self.handle_on)
     manager.subscribe_off(self.handle_off)
     pub.sendMessage(topic)
     assert self._last_value == 0xFF
     assert self._on_event
     assert not self._off_event
Ejemplo n.º 7
0
 async def test_off(self):
     """Test off command."""
     address = create("F", 1)
     topic = "x10_received"
     manager = X10OnOffManager(address)
     manager.subscribe(self.handle_on_off)
     manager.subscribe_on(self.handle_on)
     manager.subscribe_off(self.handle_off)
     address_bytes = bytes(address)
     pub.sendMessage(topic,
                     raw_x10=int.from_bytes(address_bytes, byteorder="big"),
                     x10_flag=0x00)
     command = (address.housecode_byte << 4) + int(X10Commands.OFF)
     pub.sendMessage(topic, raw_x10=command, x10_flag=0x80)
     assert self._last_value == 0x00
     assert not self._on_event
     assert self._off_event
async def test_notify_on_aldb_status(hass, hass_ws_client, aldb_data):
    """Test getting an Insteon device's All-Link Database."""
    ws_client, devices = await _setup(hass, hass_ws_client, aldb_data)

    with patch.object(insteon.api.aldb, "devices", devices):
        await ws_client.send_json({
            ID: 2,
            TYPE: "insteon/aldb/notify",
            DEVICE_ADDRESS: "33.33.33",
        })
        msg = await ws_client.receive_json()
        assert msg["success"]

        pub.sendMessage(f"333333.{ALDB_STATUS_CHANGED}")
        msg = await ws_client.receive_json()
        assert msg["event"]["type"] == "status_changed"
        assert not msg["event"]["is_loading"]
Ejemplo n.º 9
0
 def base_setup(self, message_id, bytes_data, **kwargs):
     """Init the OutboundBase class."""
     set_log_levels(
         logger="info",
         logger_pyinsteon="debug",
         logger_messages="debug",
         logger_topics=False,
     )
     register_outbound_handlers()
     self.msg = None
     self.message_id = message_id
     self.bytes_data = bytes_data
     pub.subscribe(self.receive_message, "send_message")
     topic = self.message_id.name.lower()
     if (topic == "send_standard" and kwargs.get("flags")
             and kwargs.get("flags").is_extended):
         topic = "send_extended"
     pub.sendMessage("send.{}".format(topic), **kwargs)
Ejemplo n.º 10
0
    def send_standard_response(self):
        """Send a response."""
        if self.record == 0:
            pub.sendMessage(ACK_FIRST_TOPIC)
        elif self.record < 8:
            pub.sendMessage(ACK_NEXT_TOPIC)
        else:
            pub.sendMessage(NAK_NEXT_TOPIC)
            return

        rec_item = self.topics_standard[self.record]
        pub.sendMessage(rec_item.topic, **rec_item.kwargs)
        self.record += 1
async def test_notify_on_aldb_record_added(hass, hass_ws_client, aldb_data):
    """Test getting an Insteon device's All-Link Database."""
    ws_client, devices = await _setup(hass, hass_ws_client, aldb_data)

    with patch.object(insteon.api.aldb, "devices", devices):
        await ws_client.send_json({
            ID: 2,
            TYPE: "insteon/aldb/notify",
            DEVICE_ADDRESS: "33.33.33",
        })
        msg = await ws_client.receive_json()
        assert msg["success"]

        pub.sendMessage(
            f"{DEVICE_LINK_CONTROLLER_CREATED}.333333",
            controller=Address("11.11.11"),
            responder=Address("33.33.33"),
            group=100,
        )
        msg = await ws_client.receive_json()
        assert msg["event"]["type"] == "record_loaded"
Ejemplo n.º 12
0
 async def test_cmd2(self):
     """Test cmd2."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.cmd2 == self.cmd2
Ejemplo n.º 13
0
 async def async_send_topics(topic_items):
     for item in topic_items:
         await asyncio.sleep(item.delay)
         _LOGGER_MESSAGES.debug("RX: %s  %s", item.topic, item.kwargs)
         pub.sendMessage(item.topic, **item.kwargs)
Ejemplo n.º 14
0
 async def test_target(self):
     """Test target."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.target == self.target
Ejemplo n.º 15
0
 async def test_data3(self):
     """Test data3."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.data3 == self.data3
Ejemplo n.º 16
0
 async def test_flags(self):
     """Test flags."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.flags == self.flags
Ejemplo n.º 17
0
 async def test_group(self):
     """Test group."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.group == self.group
Ejemplo n.º 18
0
 async def test_user_data(self):
     """Test user_data."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.user_data == self.user_data
Ejemplo n.º 19
0
 async def test_action(self):
     """Test action."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.action == self.action
Ejemplo n.º 20
0
def send_nak_response():
    """Send a NAK response."""
    pub.sendMessage(NAK_FIRST_TOPIC)
Ejemplo n.º 21
0
 async def test_address(self):
     """Test address."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.address == self.address
Ejemplo n.º 22
0
 async def test_raw_x10(self):
     """Test the raw x10 byte."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.raw_x10 == self.raw_x10
Ejemplo n.º 23
0
 async def test_subcat(self):
     """Test subcat."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.subcat == self.subcat
Ejemplo n.º 24
0
 async def test_x10_flag(self):
     """Test the x10 flag byte."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.x10_flag == self.x10_flag
Ejemplo n.º 25
0
 async def test_id(self):
     """Test the message ID matches the expected message."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.message_id == self.message_id
Ejemplo n.º 26
0
 async def test_bytes(self):
     """Test the byte representation matches the expected value."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert bytes(self.msg) == self.bytes_data
Ejemplo n.º 27
0
 async def test_firmware(self):
     """Test firmware."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.firmware == self.firmware
Ejemplo n.º 28
0
 async def test_mode(self):
     """Test link_mode."""
     pub.sendMessage("send.{}".format(self.topic), **self.kwargs)
     assert self.msg.link_mode == self.link_mode