Skip to content

Commit beb66a4

Browse files
author
Slawomir Skowron
authored
Fix all checks to pass (#29)
* First part of fixes for checks to pass * Second part of fixes for checks to pass * Third part of fixes for checks to pass * 3.11 - remove Text and replace by str * Add python 3.12 tests * Revert "Add python 3.12 tests" This reverts commit 9ce60cb.
1 parent 0aac175 commit beb66a4

9 files changed

Lines changed: 47 additions & 23 deletions

File tree

aiocomfoconnect/__main__.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" aiocomfoconnect CLI application """
2+
23
from __future__ import annotations
34

45
import argparse
@@ -14,7 +15,9 @@
1415
from aiocomfoconnect.exceptions import (
1516
AioComfoConnectNotConnected,
1617
AioComfoConnectTimeout,
18+
BridgeNotFoundException,
1719
ComfoConnectNotAllowed,
20+
UnknownActionException,
1821
)
1922
from aiocomfoconnect.properties import Property
2023
from aiocomfoconnect.sensors import SENSORS
@@ -61,7 +64,7 @@ async def main(args):
6164
await run_set_flow_for_speed(args.host, args.uuid, args.speed, args.flow)
6265

6366
else:
64-
raise Exception("Unknown action: " + args.action)
67+
raise UnknownActionException("Unknown action: " + args.action)
6568

6669

6770
async def run_discover(host: str = None):
@@ -78,7 +81,7 @@ async def run_register(host: str, uuid: str, name: str, pin: int):
7881
# Discover bridge so we know the UUID
7982
bridges = await discover_bridges(host)
8083
if not bridges:
81-
raise Exception("No bridge found")
84+
raise BridgeNotFoundException("No bridge found")
8285

8386
# Connect to the bridge
8487
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
@@ -117,7 +120,7 @@ async def run_deregister(host: str, uuid: str, uuid2: str):
117120
# Discover bridge so we know the UUID
118121
bridges = await discover_bridges(host)
119122
if not bridges:
120-
raise Exception("No bridge found")
123+
raise BridgeNotFoundException("No bridge found")
121124

122125
# Connect to the bridge
123126
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
@@ -145,7 +148,7 @@ async def run_set_speed(host: str, uuid: str, speed: Literal["away", "low", "med
145148
# Discover bridge so we know the UUID
146149
bridges = await discover_bridges(host)
147150
if not bridges:
148-
raise Exception("No bridge found")
151+
raise BridgeNotFoundException("No bridge found")
149152

150153
# Connect to the bridge
151154
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
@@ -165,7 +168,7 @@ async def run_set_mode(host: str, uuid: str, mode: Literal["auto", "manual"]):
165168
# Discover bridge so we know the UUID
166169
bridges = await discover_bridges(host)
167170
if not bridges:
168-
raise Exception("No bridge found")
171+
raise BridgeNotFoundException("No bridge found")
169172

170173
# Connect to the bridge
171174
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
@@ -185,7 +188,7 @@ async def run_set_comfocool(host: str, uuid: str, mode: Literal["auto", "off"]):
185188
# Discover bridge so we know the UUID
186189
bridges = await discover_bridges(host)
187190
if not bridges:
188-
raise Exception("No bridge found")
191+
raise BridgeNotFoundException("No bridge found")
189192

190193
# Connect to the bridge
191194
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
@@ -205,7 +208,7 @@ async def run_set_boost(host: str, uuid: str, mode: Literal["on", "off"], timeou
205208
# Discover bridge so we know the UUID
206209
bridges = await discover_bridges(host)
207210
if not bridges:
208-
raise Exception("No bridge found")
211+
raise BridgeNotFoundException("No bridge found")
209212

210213
# Connect to the bridge
211214
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
@@ -225,7 +228,7 @@ async def run_show_sensors(host: str, uuid: str):
225228
# Discover bridge so we know the UUID
226229
bridges = await discover_bridges(host)
227230
if not bridges:
228-
raise Exception("No bridge found")
231+
raise BridgeNotFoundException("No bridge found")
229232

230233
def alarm_callback(node_id, errors):
231234
"""Print alarm updates."""
@@ -277,7 +280,7 @@ async def run_show_sensor(host: str, uuid: str, sensor: int, follow=False):
277280
# Discover bridge so we know the UUID
278281
bridges = await discover_bridges(host)
279282
if not bridges:
280-
raise Exception("No bridge found")
283+
raise BridgeNotFoundException("No bridge found")
281284

282285
def sensor_callback(sensor_, value):
283286
"""Print sensor update."""
@@ -331,7 +334,7 @@ async def run_get_property(host: str, uuid: str, node_id: int, unit: int, subuni
331334
# Discover bridge so we know the UUID
332335
bridges = await discover_bridges(host)
333336
if not bridges:
334-
raise Exception("No bridge found")
337+
raise BridgeNotFoundException("No bridge found")
335338

336339
# Connect to the bridge
337340
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
@@ -351,7 +354,7 @@ async def run_get_flow_for_speed(host: str, uuid: str, speed: Literal["away", "l
351354
# Discover bridge so we know the UUID
352355
bridges = await discover_bridges(host)
353356
if not bridges:
354-
raise Exception("No bridge found")
357+
raise BridgeNotFoundException("No bridge found")
355358

356359
# Connect to the bridge
357360
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
@@ -371,7 +374,7 @@ async def run_set_flow_for_speed(host: str, uuid: str, speed: Literal["away", "l
371374
# Discover bridge so we know the UUID
372375
bridges = await discover_bridges(host)
373376
if not bridges:
374-
raise Exception("No bridge found")
377+
raise BridgeNotFoundException("No bridge found")
375378

376379
# Connect to the bridge
377380
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)

aiocomfoconnect/bridge.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" ComfoConnect Bridge API """
2+
23
from __future__ import annotations
34

45
import asyncio
@@ -30,6 +31,10 @@
3031
TIMEOUT = 5
3132

3233

34+
class SelfDeregistrationError(Exception):
35+
"""Exception raised when trying to deregister self."""
36+
37+
3338
class EventBus:
3439
"""An event bus for async replies."""
3540

@@ -95,7 +100,7 @@ async def _connect(self, uuid: str):
95100
self._reader, self._writer = await asyncio.wait_for(asyncio.open_connection(self.host, self.PORT), TIMEOUT)
96101
except asyncio.TimeoutError as exc:
97102
_LOGGER.warning("Timeout while connecting to bridge %s", self.host)
98-
raise AioComfoConnectTimeout from exc
103+
raise AioComfoConnectTimeout("Timeout while connecting to bridge") from exc
99104

100105
self._reference = 1
101106
self._local_uuid = uuid
@@ -111,9 +116,9 @@ async def _read_messages():
111116
# We are shutting down. Return to stop the background task
112117
return False
113118

114-
except AioComfoConnectNotConnected:
119+
except AioComfoConnectNotConnected as exc:
115120
# We have been disconnected
116-
raise
121+
raise AioComfoConnectNotConnected("We have been disconnected") from exc
117122

118123
read_task = self._loop.create_task(_read_messages())
119124
_LOGGER.debug("Connected to bridge %s", self.host)
@@ -169,7 +174,7 @@ async def _send(self, request, request_type, params: dict = None, reply: bool =
169174
except asyncio.TimeoutError as exc:
170175
_LOGGER.warning("Timeout while waiting for response from bridge")
171176
await self._disconnect()
172-
raise AioComfoConnectTimeout from exc
177+
raise AioComfoConnectTimeout("Timeout while waiting for response from bridge") from exc
173178

174179
async def _read(self) -> Message:
175180
# Read packet size
@@ -241,10 +246,10 @@ async def _process_message(self):
241246
else:
242247
_LOGGER.warning("Unhandled message type %s: %s", message.cmd.type, message)
243248

244-
except asyncio.exceptions.IncompleteReadError:
249+
except asyncio.exceptions.IncompleteReadError as exc:
245250
_LOGGER.info("The connection was closed.")
246251
await self._disconnect()
247-
raise AioComfoConnectNotConnected
252+
raise AioComfoConnectNotConnected("The connection was closed.") from exc
248253

249254
except ComfoConnectError as exc:
250255
if exc.message.cmd.reference:
@@ -300,7 +305,7 @@ def cmd_deregister_app(self, uuid: str) -> Awaitable[Message]:
300305
"""Remove the specified app from the registration list."""
301306
_LOGGER.debug("DeregisterAppRequest")
302307
if uuid == self._local_uuid:
303-
raise Exception("You should not deregister yourself.")
308+
raise SelfDeregistrationError("You should not deregister yourself.")
304309

305310
# pylint: disable=no-member
306311
return self._send(

aiocomfoconnect/comfoconnect.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" ComfoConnect Bridge API abstraction """
2+
23
from __future__ import annotations
34

45
import asyncio
@@ -21,13 +22,13 @@
2122
UNIT_SCHEDULE,
2223
UNIT_TEMPHUMCONTROL,
2324
UNIT_VENTILATIONCONFIG,
25+
ComfoCoolMode,
2426
PdoType,
2527
VentilationBalance,
2628
VentilationMode,
2729
VentilationSetting,
2830
VentilationSpeed,
2931
VentilationTemperatureProfile,
30-
ComfoCoolMode,
3132
)
3233
from aiocomfoconnect.exceptions import (
3334
AioComfoConnectNotConnected,
@@ -111,7 +112,6 @@ async def _reconnect_loop():
111112
except AioComfoConnectNotConnected:
112113
# Reconnect when connection has been dropped
113114
_LOGGER.info("We got disconnected. Reconnecting.")
114-
pass
115115

116116
reconnect_task = self._loop.create_task(_reconnect_loop())
117117
self._tasks.add(reconnect_task)
@@ -120,6 +120,7 @@ async def _reconnect_loop():
120120
await connected
121121

122122
async def disconnect(self):
123+
"""Disconnect from the bridge."""
123124
await self._disconnect()
124125

125126
async def register_sensor(self, sensor: Sensor):

aiocomfoconnect/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Constants """
22

3+
34
# PDO Types
45
class PdoType:
56
"""Defines a PDO type."""
@@ -208,6 +209,7 @@ class VentilationSpeed:
208209
MEDIUM = "medium"
209210
HIGH = "high"
210211

212+
211213
class ComfoCoolMode:
212214
"""Enum for ventilation settings."""
213215

aiocomfoconnect/discovery.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
""" Bridge discovery """
2+
23
from __future__ import annotations
34

45
import asyncio
56
import logging
6-
from typing import Any, List, Text, Union
7+
from typing import Any, List, Union
78

89
from .bridge import Bridge
910
from .protobuf import zehnder_pb2
@@ -35,7 +36,7 @@ def connection_made(self, transport: asyncio.transports.DatagramTransport):
3536
_LOGGER.debug("Sending discovery request to broadcast:%d", Bridge.PORT)
3637
self.transport.sendto(b"\x0a\x00", ("<broadcast>", Bridge.PORT))
3738

38-
def datagram_received(self, data: Union[bytes, Text], addr: tuple[str | Any, int]):
39+
def datagram_received(self, data: Union[bytes, str], addr: tuple[str | Any, int]):
3940
"""Called when some datagram is received."""
4041
if data == b"\x0a\x00":
4142
_LOGGER.debug("Ignoring discovery request from %s:%d", addr[0], addr[1])

aiocomfoconnect/exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" Error definitions """
2+
23
from __future__ import annotations
34

45

@@ -47,3 +48,11 @@ class AioComfoConnectNotConnected(Exception):
4748

4849
class AioComfoConnectTimeout(Exception):
4950
"""An error occurred because the bridge didn't reply in time."""
51+
52+
53+
class BridgeNotFoundException(Exception):
54+
"""Exception raised when no bridge is found."""
55+
56+
57+
class UnknownActionException(Exception):
58+
"""Exception raised when an unknown action is provided."""

aiocomfoconnect/properties.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" Property definitions """
2+
23
from __future__ import annotations
34

45
from dataclasses import dataclass

aiocomfoconnect/sensors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" Sensor definitions. """
2+
23
from __future__ import annotations
34

45
from dataclasses import dataclass

aiocomfoconnect/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" Helper methods. """
2+
23
from __future__ import annotations
34

45
from aiocomfoconnect.const import PdoType

0 commit comments

Comments
 (0)