Use ruff and ruff format (#534)

Replaces the previously used linting and code formatting tools with ruff.
This commit is contained in:
Teemu R
2023-10-29 23:15:42 +01:00
committed by GitHub
parent 0061668c9f
commit c431dbb832
26 changed files with 220 additions and 174 deletions

View File

@@ -87,7 +87,7 @@ class _DiscoverProtocol(asyncio.DatagramProtocol):
req = json_dumps(Discover.DISCOVERY_QUERY)
_LOGGER.debug("[DISCOVERY] %s >> %s", self.target, Discover.DISCOVERY_QUERY)
encrypted_req = TPLinkSmartHomeProtocol.encrypt(req)
for i in range(self.discovery_packets):
for _i in range(self.discovery_packets):
self.transport.sendto(encrypted_req[4:], self.target) # type: ignore
self.transport.sendto(Discover.DISCOVERY_QUERY_2, self.target_2) # type: ignore
@@ -169,7 +169,8 @@ class Discover:
>>> [dev.alias for dev in found_devices]
['TP-LINK_Power Strip_CF69']
Discovery can also be targeted to a specific broadcast address instead of the 255.255.255.255:
Discovery can also be targeted to a specific broadcast address instead of
the default 255.255.255.255:
>>> asyncio.run(Discover.discover(target="192.168.8.255"))
@@ -207,14 +208,19 @@ class Discover:
Sends discovery message to 255.255.255.255:9999 in order
to detect available supported devices in the local network,
and waits for given timeout for answers from devices.
If you have multiple interfaces, you can use target parameter to specify the network for discovery.
If you have multiple interfaces,
you can use *target* parameter to specify the network for discovery.
If given, `on_discovered` coroutine will get awaited with a :class:`SmartDevice`-derived object as parameter.
If given, `on_discovered` coroutine will get awaited with
a :class:`SmartDevice`-derived object as parameter.
The results of the discovery are returned as a dict of :class:`SmartDevice`-derived objects keyed with IP addresses.
The devices are already initialized and all but emeter-related properties can be accessed directly.
The results of the discovery are returned as a dict of
:class:`SmartDevice`-derived objects keyed with IP addresses.
The devices are already initialized and all but emeter-related properties
can be accessed directly.
:param target: The target address where to send the broadcast discovery queries if multi-homing (e.g. 192.168.xxx.255).
:param target: The target address where to send the broadcast discovery
queries if multi-homing (e.g. 192.168.xxx.255).
:param on_discovered: coroutine to execute on discovery
:param timeout: How long to wait for responses, defaults to 5
:param discovery_packets: Number of discovery packets to broadcast
@@ -232,7 +238,7 @@ class Discover:
credentials=credentials,
timeout=timeout,
),
local_addr=("0.0.0.0", 0),
local_addr=("0.0.0.0", 0), # noqa: S104
)
protocol = cast(_DiscoverProtocol, protocol)
@@ -275,7 +281,7 @@ class Discover:
credentials=credentials,
timeout=timeout,
),
local_addr=("0.0.0.0", 0),
local_addr=("0.0.0.0", 0), # noqa: S104
)
protocol = cast(_DiscoverProtocol, protocol)
@@ -284,10 +290,10 @@ class Discover:
async with asyncio_timeout(timeout):
await event.wait()
except asyncio.TimeoutError:
except asyncio.TimeoutError as ex:
raise SmartDeviceException(
f"Timed out getting discovery response for {host}"
)
) from ex
finally:
transport.close()