File: test_models.py

package info (click to toggle)
python-gridnet 5.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 632 kB
  • sloc: python: 302; makefile: 8; sh: 5
file content (52 lines) | stat: -rw-r--r-- 1,631 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
"""Test the models."""
from aiohttp import ClientSession
from aresponses import ResponsesMockServer

from gridnet import Device, GridNet, SmartBridge

from . import load_fixtures


async def test_device(aresponses: ResponsesMockServer) -> None:
    """Test request from the device - Device object."""
    aresponses.add(
        "127.0.0.1",
        "/info",
        "GET",
        aresponses.Response(
            text=load_fixtures("device.json"),
            status=200,
        ),
    )

    async with ClientSession() as session:
        client = GridNet(host="127.0.0.1", session=session)
        device: Device = await client.device()
        assert device
        assert device.n2g_id == "84df:0c11:9999:3795"
        assert device.model == "SBWF3102"
        assert device.batch == "SBP-HMX-210318"
        assert device.firmware == "1.6.16"
        assert device.hardware == 1
        assert device.manufacturer == "NET2GRID"


async def test_smartbridge(aresponses: ResponsesMockServer) -> None:
    """Test request from the device - SmartBridge object."""
    aresponses.add(
        "127.0.0.1",
        "/meter/now",
        "GET",
        aresponses.Response(
            text=load_fixtures("smartbridge.json"),
            status=200,
        ),
    )

    async with ClientSession() as session:
        client = GridNet(host="127.0.0.1", session=session)
        smartbridge: SmartBridge = await client.smartbridge()
        assert smartbridge
        assert smartbridge.power_flow == 338
        assert smartbridge.energy_consumption_total == 17762.1
        assert smartbridge.energy_production_total == 21214.6