Exemplo n.º 1
0
 def datagram_received(self, data, addr):
     message = data.decode()
     _LOGGER.debug("RECV: %s", message)
     msg = get_ddp_message(MOCK_DDP_PROTO_STANDBY, MOCK_DDP_PROTO_RESPONSE)
     msg = msg.encode()
     _LOGGER.debug("Sent: %s to %s", msg, addr)
     self.transport.sendto(msg, addr)
Exemplo n.º 2
0
async def mock_ddp_response(hass, mock_status_data):
    """Mock raw UDP response from device."""
    mock_protocol = hass.data[PS4_DATA].protocol

    mock_code = mock_status_data.get("status_code")
    mock_status = mock_status_data.get("status")
    mock_status_header = f"{mock_code} {mock_status}"
    mock_response = get_ddp_message(mock_status_header, mock_status_data).encode()

    mock_protocol.datagram_received(mock_response, (MOCK_HOST, MOCK_RANDOM_PORT))
    await hass.async_block_till_done()
Exemplo n.º 3
0
def test_response_standby():
    """Test serialization of standby response msg."""
    creds = init_creds()
    response = credential.get_ddp_message(credential.STANDBY, creds.response).split(
        "\n"
    )

    for item in response:
        if item == "":
            continue
        assert item in STANDBY_RESPONSE
Exemplo n.º 4
0
def test_creds_handle_search():
    """Test Service handles search message."""
    mock_response = (get_ddp_search_message().encode(), MOCK_ADDRESS)
    creds = init_creds()
    mock_search = credential.get_ddp_message(
        credential.STANDBY, creds.response
    ).encode()
    creds.sock = MagicMock()
    creds.sock.recvfrom = MagicMock(return_value=mock_response)
    result = creds.listen(0.1)
    creds.sock.sendto.assert_called_with(mock_search, MOCK_ADDRESS)
    assert result is None
Exemplo n.º 5
0
async def mock_ddp_response(opp, mock_status_data):
    """Mock raw UDP response from device."""
    mock_protocol = opp.data[PS4_DATA].protocol
    assert mock_protocol.local_port == DEFAULT_UDP_PORT
    mock_code = mock_status_data.get("status_code")
    mock_status = mock_status_data.get("status")
    mock_status_header = f"{mock_code} {mock_status}"
    mock_response = get_ddp_message(mock_status_header,
                                    mock_status_data).encode()

    mock_protocol.datagram_received(mock_response,
                                    (MOCK_HOST, MOCK_RANDOM_PORT))
    await opp.async_block_till_done()
Exemplo n.º 6
0
async def mock_ddp_response(hass, mock_status_data, games=None):
    """Mock raw UDP response from device."""
    mock_protocol = hass.data[PS4_DATA].protocol

    mock_code = mock_status_data.get("status_code")
    mock_status = mock_status_data.get("status")
    mock_status_header = "{} {}".format(mock_code, mock_status)
    mock_response = get_ddp_message(mock_status_header, mock_status_data).encode()

    if games is None:
        games = {}

    with patch(MOCK_LOAD, return_value=games), patch(
        MOCK_SAVE, side_effect=MagicMock()
    ):
        mock_protocol.datagram_received(mock_response, (MOCK_HOST, MOCK_RANDOM_PORT))
        await hass.async_block_till_done()