File: test_monitor.py

package info (click to toggle)
python-aioemonitor 1.0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: xml: 495; python: 265; makefile: 66
file content (45 lines) | stat: -rw-r--r-- 1,543 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pytest
import os
from aioemonitor import Emonitor
from aioemonitor.monitor import STATUS_ENDPOINT
from aioresponses import aioresponses

from aiohttp import ClientSession


def load_fixture(filename):
    """Load a fixture."""
    path = os.path.join(os.path.dirname(__file__), "data", filename)
    with open(path) as fptr:
        return fptr.read()


@pytest.mark.asyncio
async def test_async_get_status():
    session = ClientSession()
    emonitor = Emonitor("1.2.3.4", session)
    with aioresponses() as m:
        m.get(f"http://1.2.3.4{STATUS_ENDPOINT}", body=load_fixture("status.xml"))
        status = await emonitor.async_get_status()
        assert status.hardware.serial_number == "1234"
        assert status.hardware.firmware_version == "16513"
        assert status.network.mac_address == "1190C2111111"
        assert status.network.ip_address == "192.168.1.2"
        channel_one = status.channels[1]
        assert channel_one.number == 1
        assert channel_one.active is True
        assert channel_one.label == "Main"
        assert channel_one.ct_size == 150
        assert channel_one.paired_with_channel == 2
        assert channel_one.input == 1
        assert channel_one.max_power == 69.0
        assert channel_one.avg_power == 29.0
        assert channel_one.inst_power == 25.0
        channel_forty_eight = status.channels[48]
        assert channel_forty_eight.number == 48
        assert channel_forty_eight.active is False

    await session.close()