File: test_bluetooth.py

package info (click to toggle)
python-demetriek 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 544 kB
  • sloc: python: 1,400; makefile: 3
file content (69 lines) | stat: -rw-r--r-- 2,186 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Asynchronous Python client for LaMetric TIME devices."""

# pylint: disable=protected-access
import aiohttp
from aresponses import Response, ResponsesMockServer

from demetriek import LaMetricDevice

from . import load_fixture


async def test_get_bluetooth(aresponses: ResponsesMockServer) -> None:
    """Test getting bluetooth information."""
    aresponses.add(
        "127.0.0.2:4343",
        "/api/v2/device/bluetooth",
        "GET",
        aresponses.Response(
            status=200,
            headers={"Content-Type": "application/json"},
            text=load_fixture("bluetooth.json"),
        ),
    )
    async with aiohttp.ClientSession() as session:
        demetriek = LaMetricDevice(host="127.0.0.2", api_key="abc", session=session)
        bluetooth = await demetriek.bluetooth()

    assert bluetooth
    assert bluetooth.active is True
    assert bluetooth.address == "AA:BB:CC:DD:EE:FF"
    assert bluetooth.available is True
    assert bluetooth.discoverable is True
    assert bluetooth.name == "LM1234"
    assert bluetooth.pairable is True


async def test_set_audio(aresponses: ResponsesMockServer) -> None:
    """Test setting display properties."""

    async def response_handler(request: aiohttp.ClientResponse) -> Response:
        """Response handler for this test."""
        data = await request.json()
        assert data == {
            "active": False,
        }
        return aresponses.Response(
            status=200,
            headers={"Content-Type": "application/json"},
            text=load_fixture("bluetooth_set.json"),
        )

    aresponses.add(
        "127.0.0.2:4343",
        "/api/v2/device/bluetooth",
        "PUT",
        response_handler,
    )

    async with aiohttp.ClientSession() as session:
        demetriek = LaMetricDevice(host="127.0.0.2", api_key="abc", session=session)
        bluetooth = await demetriek.bluetooth(active=False)

    assert bluetooth
    assert bluetooth.active is False
    assert bluetooth.address == "AA:BB:CC:DD:EE:FF"
    assert bluetooth.available is True
    assert bluetooth.discoverable is True
    assert bluetooth.name == "LM1234"
    assert bluetooth.pairable is True