Skip to content

Commit

Permalink
Fix all checks to pass (#29)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
szibis authored May 7, 2024
1 parent 0aac175 commit beb66a4
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 23 deletions.
27 changes: 15 additions & 12 deletions aiocomfoconnect/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" aiocomfoconnect CLI application """

from __future__ import annotations

import argparse
Expand All @@ -14,7 +15,9 @@
from aiocomfoconnect.exceptions import (
AioComfoConnectNotConnected,
AioComfoConnectTimeout,
BridgeNotFoundException,
ComfoConnectNotAllowed,
UnknownActionException,
)
from aiocomfoconnect.properties import Property
from aiocomfoconnect.sensors import SENSORS
Expand Down Expand Up @@ -61,7 +64,7 @@ async def main(args):
await run_set_flow_for_speed(args.host, args.uuid, args.speed, args.flow)

else:
raise Exception("Unknown action: " + args.action)
raise UnknownActionException("Unknown action: " + args.action)


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

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

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

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

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

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

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

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

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

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

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

# Connect to the bridge
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
Expand Down
19 changes: 12 additions & 7 deletions aiocomfoconnect/bridge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" ComfoConnect Bridge API """

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -30,6 +31,10 @@
TIMEOUT = 5


class SelfDeregistrationError(Exception):
"""Exception raised when trying to deregister self."""


class EventBus:
"""An event bus for async replies."""

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

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

except AioComfoConnectNotConnected:
except AioComfoConnectNotConnected as exc:
# We have been disconnected
raise
raise AioComfoConnectNotConnected("We have been disconnected") from exc

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

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

except asyncio.exceptions.IncompleteReadError:
except asyncio.exceptions.IncompleteReadError as exc:
_LOGGER.info("The connection was closed.")
await self._disconnect()
raise AioComfoConnectNotConnected
raise AioComfoConnectNotConnected("The connection was closed.") from exc

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

# pylint: disable=no-member
return self._send(
Expand Down
5 changes: 3 additions & 2 deletions aiocomfoconnect/comfoconnect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" ComfoConnect Bridge API abstraction """

from __future__ import annotations

import asyncio
Expand All @@ -21,13 +22,13 @@
UNIT_SCHEDULE,
UNIT_TEMPHUMCONTROL,
UNIT_VENTILATIONCONFIG,
ComfoCoolMode,
PdoType,
VentilationBalance,
VentilationMode,
VentilationSetting,
VentilationSpeed,
VentilationTemperatureProfile,
ComfoCoolMode,
)
from aiocomfoconnect.exceptions import (
AioComfoConnectNotConnected,
Expand Down Expand Up @@ -111,7 +112,6 @@ async def _reconnect_loop():
except AioComfoConnectNotConnected:
# Reconnect when connection has been dropped
_LOGGER.info("We got disconnected. Reconnecting.")
pass

reconnect_task = self._loop.create_task(_reconnect_loop())
self._tasks.add(reconnect_task)
Expand All @@ -120,6 +120,7 @@ async def _reconnect_loop():
await connected

async def disconnect(self):
"""Disconnect from the bridge."""
await self._disconnect()

async def register_sensor(self, sensor: Sensor):
Expand Down
2 changes: 2 additions & 0 deletions aiocomfoconnect/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Constants """


# PDO Types
class PdoType:
"""Defines a PDO type."""
Expand Down Expand Up @@ -208,6 +209,7 @@ class VentilationSpeed:
MEDIUM = "medium"
HIGH = "high"


class ComfoCoolMode:
"""Enum for ventilation settings."""

Expand Down
5 changes: 3 additions & 2 deletions aiocomfoconnect/discovery.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
""" Bridge discovery """

from __future__ import annotations

import asyncio
import logging
from typing import Any, List, Text, Union
from typing import Any, List, Union

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

def datagram_received(self, data: Union[bytes, Text], addr: tuple[str | Any, int]):
def datagram_received(self, data: Union[bytes, str], addr: tuple[str | Any, int]):
"""Called when some datagram is received."""
if data == b"\x0a\x00":
_LOGGER.debug("Ignoring discovery request from %s:%d", addr[0], addr[1])
Expand Down
9 changes: 9 additions & 0 deletions aiocomfoconnect/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Error definitions """

from __future__ import annotations


Expand Down Expand Up @@ -47,3 +48,11 @@ class AioComfoConnectNotConnected(Exception):

class AioComfoConnectTimeout(Exception):
"""An error occurred because the bridge didn't reply in time."""


class BridgeNotFoundException(Exception):
"""Exception raised when no bridge is found."""


class UnknownActionException(Exception):
"""Exception raised when an unknown action is provided."""
1 change: 1 addition & 0 deletions aiocomfoconnect/properties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Property definitions """

from __future__ import annotations

from dataclasses import dataclass
Expand Down
1 change: 1 addition & 0 deletions aiocomfoconnect/sensors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Sensor definitions. """

from __future__ import annotations

from dataclasses import dataclass
Expand Down
1 change: 1 addition & 0 deletions aiocomfoconnect/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Helper methods. """

from __future__ import annotations

from aiocomfoconnect.const import PdoType
Expand Down

0 comments on commit beb66a4

Please sign in to comment.