Skip to content

Commit

Permalink
Merge 541997a into 6a9be15
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio committed Mar 18, 2021
2 parents 6a9be15 + 541997a commit 1211ce8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased changes

### Internals

- Comparing GroupAddress or IndividualAddress to other types don't raise TypeError anymore.

## 0.17.3 Passive addresses 2021-03-16

### Devices
Expand Down
13 changes: 7 additions & 6 deletions test/telegram_tests/address_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def test_equal(self):
self.assertEqual(IndividualAddress("1.0.0"), IndividualAddress(4096))
self.assertNotEqual(IndividualAddress("1.0.0"), IndividualAddress("1.1.1"))
self.assertNotEqual(IndividualAddress("1.0.0"), None)
with self.assertRaises(TypeError):
IndividualAddress(
"1.0.0"
) == "example" # pylint: disable=expression-not-assigned
self.assertNotEqual(IndividualAddress("1.0.0"), "example")
self.assertNotEqual(IndividualAddress("1.1.1"), GroupAddress("1/1/1"))
self.assertNotEqual(IndividualAddress(250), GroupAddress(250))
self.assertNotEqual(IndividualAddress(250), 250)

def test_representation(self):
"""Test string representation of address."""
Expand Down Expand Up @@ -217,8 +217,9 @@ def test_equal(self):
self.assertEqual(GroupAddress("1/0"), GroupAddress(2048))
self.assertNotEqual(GroupAddress("1/1"), GroupAddress("1/1/0"))
self.assertNotEqual(GroupAddress("1/0"), None)
with self.assertRaises(TypeError):
GroupAddress("1/0") == "example" # pylint: disable=expression-not-assigned
self.assertNotEqual(GroupAddress("1/0"), "example")
self.assertNotEqual(GroupAddress(1), IndividualAddress(1))
self.assertNotEqual(GroupAddress(1), 1)

def test_representation(self):
"""Test string representation of address."""
Expand Down
15 changes: 8 additions & 7 deletions xknx/core/telegram_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ async def _telegram_consumer(self) -> None:
self.xknx.telegrams.task_done()
break

try:
if telegram.direction == TelegramDirection.INCOMING:
if telegram.direction == TelegramDirection.INCOMING:
try:
await self.process_telegram_incoming(telegram)
except XKNXException as ex:
logger.error("Error while processing incoming telegram %s", ex)
finally:
self.xknx.telegrams.task_done()
elif telegram.direction == TelegramDirection.OUTGOING:
self.outgoing_queue.put_nowait(telegram)
# self.xknx.telegrams.task_done() for outgoing is called in _outgoing_rate_limiter.
except XKNXException as ex:
logger.error("Error while processing telegram %s", ex)
elif telegram.direction == TelegramDirection.OUTGOING:
self.outgoing_queue.put_nowait(telegram)
# self.xknx.telegrams.task_done() for outgoing is called in _outgoing_rate_limiter.

async def _outgoing_rate_limiter(self) -> None:
"""Endless loop for processing outgoing telegrams."""
Expand Down
3 changes: 2 additions & 1 deletion xknx/core/value_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __init__(
async def read(self) -> Optional[Telegram]:
"""Send group read and wait for response."""
cb_obj = self.xknx.telegram_queue.register_telegram_received_cb(
self.telegram_received
self.telegram_received,
group_addresses=[self.group_address],
)
await self.send_group_read()

Expand Down
11 changes: 5 additions & 6 deletions xknx/telegram/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* 2nd level: "1/2"
* Free format: "123"
"""
from abc import ABC
from enum import Enum
from re import compile as re_compile
from typing import Optional, Tuple, Union
Expand Down Expand Up @@ -41,7 +42,7 @@ def address_tuple_to_int(address: Tuple[int, int]) -> int:
return int(address[0] * 256 + address[1])


class BaseAddress: # pylint: disable=too-few-public-methods
class BaseAddress(ABC):
"""Base class for all knx address types."""

def __init__(self) -> None:
Expand All @@ -65,11 +66,9 @@ def __eq__(self, other: Optional[object]) -> bool:
Returns `False` if we check against `None`.
"""
if other is None:
return False
if type(self) is not type(other):
raise TypeError()
return self.__hash__() == other.__hash__()
if isinstance(self, type(other)):
return self.__hash__() == other.__hash__()
return False

def __hash__(self) -> int:
"""Hash Address so it can be used as dict key."""
Expand Down

0 comments on commit 1211ce8

Please sign in to comment.