• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

2Fake / devolo_plc_api / 6080961227

05 Sep 2023 06:23AM UTC coverage: 97.468% (-1.1%) from 98.543%
6080961227

Pull #142

github-actions

Shutgun
Fix TCH in tests
Pull Request #142: Fix new ruff findings

14 of 14 new or added lines in 3 files covered. (100.0%)

539 of 553 relevant lines covered (97.47%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/devolo_plc_api/plcnet_api/plcnetapi.py
1
"""Implementation of the devolo plcnet API."""
2
from __future__ import annotations
1✔
3

4
from typing import TYPE_CHECKING
1✔
5

6
from devolo_plc_api.clients import Protobuf
1✔
7

8
from .getnetworkoverview_pb2 import GetNetworkOverview
1✔
9
from .identifydevice_pb2 import IdentifyDeviceResponse, IdentifyDeviceStart, IdentifyDeviceStop
1✔
10
from .pairdevice_pb2 import PairDeviceResponse, PairDeviceStart
1✔
11
from .setuserdevicename_pb2 import SetUserDeviceName, SetUserDeviceNameResponse
1✔
12

13
if TYPE_CHECKING:
1✔
14
    from httpx import AsyncClient
×
15

16
    from devolo_plc_api.zeroconf import ZeroconfServiceInfo
×
17

18

19
class PlcNetApi(Protobuf):
1✔
20
    """
21
    Implementation of the devolo plcnet API.
22

23
    :param ip: IP address of the device to communicate with
24
    :param session: HTTP client session
25
    :param info: Information collected from the mDNS query
26
    """
27

28
    def __init__(self, ip: str, session: AsyncClient, info: ZeroconfServiceInfo) -> None:
1✔
29
        """Initialize the plcnet API."""
30
        super().__init__()
1✔
31

32
        self._ip = ip
1✔
33
        self._mac = info.properties["PlcMacAddress"]
1✔
34
        self._path = info.properties["Path"]
1✔
35
        self._port = info.port
1✔
36
        self._session = session
1✔
37
        self._user = "devolo"
1✔
38
        self._version = info.properties["Version"]
1✔
39

40
        self.password = ""
1✔
41

42
    async def async_get_network_overview(self) -> GetNetworkOverview.LogicalNetwork:
1✔
43
        """
44
        Get a PLC network overview.
45

46
        :return: Network overview
47
        """
48
        self._logger.debug("Getting network overview.")
1✔
49
        network_overview = GetNetworkOverview()
1✔
50
        response = await self._async_get("GetNetworkOverview")
1✔
51
        network_overview.ParseFromString(await response.aread())
1✔
52
        return network_overview.network
1✔
53

54
    async def async_identify_device_start(self) -> bool:
1✔
55
        """
56
        Make PLC LED of a device blink to identify it.
57

58
        :return: True, if identifying was successfully started, otherwise False
59
        """
60
        self._logger.debug("Starting LED blinking.")
1✔
61
        identify_device = IdentifyDeviceStart()
1✔
62
        identify_device.mac_address = self._mac
1✔
63
        query = await self._async_post("IdentifyDeviceStart", content=identify_device.SerializeToString())
1✔
64
        response = IdentifyDeviceResponse()
1✔
65
        response.ParseFromString(await query.aread())
1✔
66
        return response.result == response.SUCCESS
1✔
67

68
    async def async_identify_device_stop(self) -> bool:
1✔
69
        """
70
        Stop the PLC LED blinking.
71

72
        :return: True, if identifying was successfully stopped, otherwise False
73
        """
74
        self._logger.debug("Stopping LED blinking.")
1✔
75
        identify_device = IdentifyDeviceStop()
1✔
76
        identify_device.mac_address = self._mac
1✔
77
        query = await self._async_post("IdentifyDeviceStop", content=identify_device.SerializeToString())
1✔
78
        response = IdentifyDeviceResponse()
1✔
79
        response.ParseFromString(await query.aread())
1✔
80
        return response.result == response.SUCCESS
1✔
81

82
    async def async_pair_device(self) -> bool:
1✔
83
        """
84
        Start pairing mode.
85

86
        :return: True, if pairing was started successfully, otherwise False
87
        """
88
        self._logger.debug("Pairing.")
1✔
89
        pair_device = PairDeviceStart()
1✔
90
        pair_device.mac_address = self._mac
1✔
91
        query = await self._async_post("PairDeviceStart", content=pair_device.SerializeToString())
1✔
92
        response = PairDeviceResponse()
1✔
93
        response.ParseFromString(await query.aread())
1✔
94
        return response.result == response.SUCCESS
1✔
95

96
    async def async_set_user_device_name(self, name: str) -> bool:
1✔
97
        """
98
        Set device name.
99

100
        :param name: Name, the device shall have
101
        :return: True, if the device was successfully renamed, otherwise False
102
        """
103
        self._logger.debug("Setting device name.")
1✔
104
        set_user_name = SetUserDeviceName()
1✔
105
        set_user_name.mac_address = self._mac
1✔
106
        set_user_name.user_device_name = name
1✔
107
        query = await self._async_post("SetUserDeviceName", content=set_user_name.SerializeToString())
1✔
108
        response = SetUserDeviceNameResponse()
1✔
109
        response.ParseFromString(await query.aread())
1✔
110
        return response.result == response.SUCCESS
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc