File: test_info.py

package info (click to toggle)
python-elgato 5.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: python: 1,288; makefile: 8; sh: 5
file content (136 lines) | stat: -rw-r--r-- 4,752 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""Tests for retrieving information from the Elgato Key Light device."""

from aiohttp import ClientResponse, ClientSession
from aresponses import Response, ResponsesMockServer

from elgato import Elgato, Info

from . import load_fixture


async def test_info_key_light(aresponses: ResponsesMockServer) -> None:
    """Test getting Elgato Key Light device information."""
    aresponses.add(
        "example.com:9123",
        "/elgato/accessory-info",
        "GET",
        aresponses.Response(
            status=200,
            headers={"Content-Type": "application/json"},
            text=load_fixture("info-key-light.json"),
        ),
    )
    async with ClientSession() as session:
        elgato = Elgato("example.com", session=session)
        info: Info = await elgato.info()
        assert info
        assert info.display_name == "Frenck"
        assert info.features == ["lights"]
        assert info.firmware_build_number == 218
        assert info.firmware_version == "1.0.3"
        assert info.hardware_board_type == 53
        assert info.mac_address == "AA:BB:CC:DD:EE:FF"
        assert info.product_name == "Elgato Key Light"
        assert info.serial_number == "CN11A1A00001"
        assert info.wifi
        assert info.wifi.frequency == 2400
        assert info.wifi.rssi == -48
        assert info.wifi.ssid == "Frenck-IoT"


async def test_info_key_light_air(aresponses: ResponsesMockServer) -> None:
    """Test getting Elgato Key Light Air device information."""
    aresponses.add(
        "example.com:9123",
        "/elgato/accessory-info",
        "GET",
        aresponses.Response(
            status=200,
            headers={"Content-Type": "application/json"},
            text=load_fixture("info-key-light-air.json"),
        ),
    )
    async with ClientSession() as session:
        elgato = Elgato("example.com", session=session)
        info: Info = await elgato.info()
        assert info
        assert not info.display_name
        assert info.features == ["lights"]
        assert info.firmware_build_number == 195
        assert info.firmware_version == "1.0.3"
        assert info.hardware_board_type == 200
        assert info.mac_address is None
        assert info.product_name == "Elgato Key Light Air"
        assert info.serial_number == "CW44J2A03032"
        assert info.wifi is None


async def test_info_light_strip(aresponses: ResponsesMockServer) -> None:
    """Test getting Elgato Light Strip device information."""
    aresponses.add(
        "example.com:9123",
        "/elgato/accessory-info",
        "GET",
        aresponses.Response(
            status=200,
            headers={"Content-Type": "application/json"},
            text=load_fixture("info-light-strip.json"),
        ),
    )
    async with ClientSession() as session:
        elgato = Elgato("example.com", session=session)
        info: Info = await elgato.info()
        assert info
        assert info.display_name == "Elgato Light"
        assert info.features == ["lights"]
        assert info.firmware_build_number == 211
        assert info.firmware_version == "1.0.4"
        assert info.hardware_board_type == 70
        assert info.mac_address is None
        assert info.product_name == "Elgato Light Strip"
        assert info.serial_number == "EW52J1A00082"
        assert info.wifi is None


async def test_change_display_name(aresponses: ResponsesMockServer) -> None:
    """Test changing the display name of an Elgato Light."""

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

    aresponses.add(
        "example.com:9123",
        "/elgato/accessory-info",
        "PUT",
        response_handler,
    )

    async with ClientSession() as session:
        elgato = Elgato("example.com", session=session)
        await elgato.display_name("OMG PUPPIES")


async def test_missing_display_name(aresponses: ResponsesMockServer) -> None:
    """Test ensure we can handle a missing display name."""
    aresponses.add(
        "example.com:9123",
        "/elgato/accessory-info",
        "GET",
        aresponses.Response(
            status=200,
            headers={"Content-Type": "application/json"},
            text=load_fixture("info-light-strip.json"),
        ),
    )
    async with ClientSession() as session:
        elgato = Elgato("example.com", session=session)
        info: Info = await elgato.info()
        assert info
        assert info.display_name == "Elgato Light"