Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for other APCI services #253

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

- renamed "PhysicalAddress" to "IndividualAddress"
- Telegram: `group_address` renamed to `destination_address`, to prepare support for other APCI services and add `source_address`
- Telegram: remove `Telegram.telegramtype` and replace with payload object derived from `xknx.telegram.apci.APCI`.
- CEMIFrame: remove `CEMIFrame.cmd`, which can be derived from `CEMIFrame.payload`.
- Farewell Travis CI; Welcome Github Actions!

## 0.15.6 Bugfix for StateUpater 2020-11-26
Expand Down
12 changes: 9 additions & 3 deletions examples/example_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from xknx import XKNX
from xknx.dpt import DPTBinary
from xknx.io import GatewayScanner, Tunnel
from xknx.telegram import GroupAddress, IndividualAddress, Telegram
from xknx.telegram import GroupAddress, GroupValueWrite, IndividualAddress, Telegram


async def main():
Expand Down Expand Up @@ -38,11 +38,17 @@ async def main():
await tunnel.connect()

await tunnel.send_telegram(
Telegram(destination_address=GroupAddress("1/0/15"), payload=DPTBinary(1))
Telegram(
destination_address=GroupAddress("1/0/15"),
payload=GroupValueWrite(DPTBinary(1)),
)
)
await asyncio.sleep(2)
await tunnel.send_telegram(
Telegram(destination_address=GroupAddress("1/0/15"), payload=DPTBinary(0))
Telegram(
destination_address=GroupAddress("1/0/15"),
payload=GroupValueWrite(DPTBinary(0)),
)
)
await asyncio.sleep(2)

Expand Down
4 changes: 2 additions & 2 deletions home-assistant-plugin/custom_components/xknx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ async def telegram_received_cb(self, telegram):
self.hass.bus.async_fire(
"knx_event",
{
"data": telegram.payload.value,
"data": telegram.payload,
"destination": str(telegram.destination_address),
"direction": telegram.direction.value,
"source": str(telegram.source_address),
"telegramtype": telegram.telegramtype.value,
"telegramtype": telegram.payload.__class__.__name__,
},
)

Expand Down
38 changes: 21 additions & 17 deletions test/core_tests/telegram_queue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from xknx import XKNX
from xknx.dpt import DPTBinary
from xknx.exceptions import CouldNotParseTelegram
from xknx.telegram import AddressFilter, GroupAddress, Telegram, TelegramDirection
from xknx.telegram import (
AddressFilter,
GroupAddress,
GroupValueWrite,
Telegram,
TelegramDirection,
)


class AsyncMock(MagicMock):
Expand Down Expand Up @@ -40,7 +46,7 @@ def test_start(self):
telegram_in = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)

self.loop.run_until_complete(xknx.telegram_queue.start())
Expand Down Expand Up @@ -75,14 +81,12 @@ async def async_none():

telegram_in = Telegram(
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
destination_address=GroupAddress("1/2/3"),
payload=GroupValueWrite(DPTBinary(1)),
)

telegram_out = Telegram(
direction=TelegramDirection.OUTGOING,
payload=DPTBinary(1),
destination_address=GroupAddress("1/2/3"),
payload=GroupValueWrite(DPTBinary(1)),
)

self.loop.run_until_complete(xknx.telegram_queue.start())
Expand Down Expand Up @@ -120,7 +124,7 @@ async def async_telegram_received_cb(device):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
self.loop.run_until_complete(
xknx.telegram_queue.process_telegram_incoming(telegram)
Expand All @@ -144,7 +148,7 @@ def test_unregister(self):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
self.loop.run_until_complete(
xknx.telegram_queue.process_telegram_incoming(telegram)
Expand All @@ -170,7 +174,7 @@ def test_process_to_device(self, devices_by_ga_mock):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
self.loop.run_until_complete(
xknx.telegram_queue.process_telegram_incoming(telegram)
Expand All @@ -193,7 +197,7 @@ def test_process_to_callback(self, devices_process):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
self.loop.run_until_complete(
xknx.telegram_queue.process_telegram_incoming(telegram)
Expand All @@ -215,7 +219,7 @@ def test_outgoing(self, logger_warning_mock, if_mock):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.OUTGOING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)

# log a warning if there is no KNXIP interface instanciated
Expand Down Expand Up @@ -249,7 +253,7 @@ async def process_exception():
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)

xknx.telegrams.put_nowait(telegram)
Expand Down Expand Up @@ -279,12 +283,12 @@ def test_process_all_telegrams(
telegram_in = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
telegram_out = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.OUTGOING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)

xknx.telegrams.put_nowait(telegram_in)
Expand Down Expand Up @@ -314,7 +318,7 @@ async def async_telegram_received_cb(device):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
xknx.telegrams.put_nowait(telegram)
self.loop.run_until_complete(xknx.telegram_queue._process_all_telegrams())
Expand Down Expand Up @@ -343,7 +347,7 @@ async def async_telegram_received_cb(device):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
xknx.telegrams.put_nowait(telegram)
self.loop.run_until_complete(xknx.telegram_queue._process_all_telegrams())
Expand Down Expand Up @@ -372,7 +376,7 @@ async def async_telegram_received_cb(device):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
xknx.telegrams.put_nowait(telegram)
self.loop.run_until_complete(xknx.telegram_queue._process_all_telegrams())
Expand Down
27 changes: 14 additions & 13 deletions test/core_tests/value_reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from xknx import XKNX
from xknx.core import ValueReader
from xknx.dpt import DPTBinary
from xknx.telegram import GroupAddress, Telegram, TelegramDirection, TelegramType
from xknx.telegram import (
GroupAddress,
GroupValueRead,
GroupValueResponse,
GroupValueWrite,
Telegram,
TelegramDirection,
)


class TestValueReader(unittest.TestCase):
Expand All @@ -28,9 +35,8 @@ def test_value_reader_read_success(self, timeout_mock):
test_group_address = GroupAddress("0/0/0")
response_telegram = Telegram(
destination_address=test_group_address,
telegramtype=TelegramType.GROUP_RESPONSE,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueResponse(DPTBinary(1)),
)

value_reader = ValueReader(xknx, test_group_address)
Expand Down Expand Up @@ -94,8 +100,7 @@ def test_value_reader_send_group_read(self):
self.assertEqual(
telegram,
Telegram(
destination_address=GroupAddress("0/0/0"),
telegramtype=TelegramType.GROUP_READ,
destination_address=GroupAddress("0/0/0"), payload=GroupValueRead()
),
)

Expand All @@ -105,27 +110,23 @@ def test_value_reader_telegram_received(self):
test_group_address = GroupAddress("0/0/0")
expected_telegram_1 = Telegram(
destination_address=test_group_address,
telegramtype=TelegramType.GROUP_RESPONSE,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueResponse(DPTBinary(1)),
)
expected_telegram_2 = Telegram(
destination_address=test_group_address,
telegramtype=TelegramType.GROUP_WRITE,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueWrite(DPTBinary(1)),
)
telegram_wrong_address = Telegram(
destination_address=GroupAddress("0/0/1"),
telegramtype=TelegramType.GROUP_RESPONSE,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueResponse(DPTBinary(1)),
)
telegram_wrong_type = Telegram(
destination_address=test_group_address,
telegramtype=TelegramType.GROUP_READ,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
payload=GroupValueRead(),
)

value_reader = ValueReader(xknx, test_group_address)
Expand Down
Loading