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

Rename Telegram.group_address to Telegram.destination_address. #510

Merged
merged 9 commits into from
Nov 28, 2020
Merged
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
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

- Telegram: `group_address` renamed to `destination_address`, to prepare support for other APCI services.

## 0.15.6 Bugfix for StateUpater 2020-11-26

### Bugfixes
Expand Down
13 changes: 8 additions & 5 deletions home-assistant-plugin/custom_components/xknx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ async def telegram_received_cb(self, telegram):
"""Call invoked after a KNX telegram was received."""
self.hass.bus.async_fire(
"knx_event",
{"address": str(telegram.group_address), "data": telegram.payload.value},
{
"address": str(telegram.destination_address),
"data": telegram.payload.value,
},
)

async def service_send_to_knx_bus(self, call):
Expand All @@ -344,10 +347,10 @@ def calculate_payload(attr_payload):
return DPTBinary(attr_payload)
return DPTArray(attr_payload)

payload = calculate_payload(attr_payload)
address = GroupAddress(attr_address)

telegram = Telegram(group_address=address, payload=payload)
telegram = Telegram(
destination_address=GroupAddress(attr_address),
payload=calculate_payload(attr_payload),
)
await self.xknx.telegrams.put(telegram)


Expand Down
28 changes: 14 additions & 14 deletions test/core_tests/telegram_queue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def test_start(self):
xknx = XKNX()

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

self.loop.run_until_complete(xknx.telegram_queue.start())
Expand Down Expand Up @@ -76,13 +76,13 @@ async def async_none():
telegram_in = Telegram(
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
group_address=GroupAddress("1/2/3"),
destination_address=GroupAddress("1/2/3"),
)

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

self.loop.run_until_complete(xknx.telegram_queue.start())
Expand Down Expand Up @@ -118,9 +118,9 @@ async def async_telegram_received_cb(device):
xknx.telegram_queue.register_telegram_received_cb(async_telegram_received_cb)

telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
group_address=GroupAddress("1/2/3"),
)
self.loop.run_until_complete(
xknx.telegram_queue.process_telegram_incoming(telegram)
Expand All @@ -142,9 +142,9 @@ def test_unregister(self):
xknx.telegram_queue.unregister_telegram_received_cb(callback)

telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
group_address=GroupAddress("1/2/3"),
)
self.loop.run_until_complete(
xknx.telegram_queue.process_telegram_incoming(telegram)
Expand All @@ -168,9 +168,9 @@ def test_process_to_device(self, devices_by_ga_mock):
devices_by_ga_mock.return_value = [test_device]

telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
group_address=GroupAddress("1/2/3"),
)
self.loop.run_until_complete(
xknx.telegram_queue.process_telegram_incoming(telegram)
Expand All @@ -191,9 +191,9 @@ def test_process_to_callback(self, devices_process):
)

telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
group_address=GroupAddress("1/2/3"),
)
self.loop.run_until_complete(
xknx.telegram_queue.process_telegram_incoming(telegram)
Expand All @@ -213,9 +213,9 @@ def test_outgoing(self, logger_warning_mock, if_mock):
if_mock.send_telegram.return_value = async_if_send_telegram

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

# log a warning if there is no KNXIP interface instanciated
Expand Down Expand Up @@ -247,9 +247,9 @@ async def process_exception():
process_tg_in_mock.return_value = asyncio.ensure_future(process_exception())

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

xknx.telegrams.put_nowait(telegram)
Expand Down Expand Up @@ -277,14 +277,14 @@ def test_process_all_telegrams(
process_telegram_outgoing_mock.return_value = async_process_mock

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

xknx.telegrams.put_nowait(telegram_in)
Expand Down Expand Up @@ -312,9 +312,9 @@ async def async_telegram_received_cb(device):
xknx.telegram_queue.register_telegram_received_cb(async_telegram_received_cb)

telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
group_address=GroupAddress("1/2/3"),
)
xknx.telegrams.put_nowait(telegram)
self.loop.run_until_complete(xknx.telegram_queue._process_all_telegrams())
Expand All @@ -341,9 +341,9 @@ async def async_telegram_received_cb(device):
)

telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
group_address=GroupAddress("1/2/3"),
)
xknx.telegrams.put_nowait(telegram)
self.loop.run_until_complete(xknx.telegram_queue._process_all_telegrams())
Expand All @@ -370,9 +370,9 @@ async def async_telegram_received_cb(device):
)

telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
group_address=GroupAddress("1/2/3"),
)
xknx.telegrams.put_nowait(telegram)
self.loop.run_until_complete(xknx.telegram_queue._process_all_telegrams())
Expand Down
12 changes: 6 additions & 6 deletions test/core_tests/value_reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_value_reader_read_success(self, timeout_mock):
xknx = XKNX()
test_group_address = GroupAddress("0/0/0")
response_telegram = Telegram(
group_address=test_group_address,
destination_address=test_group_address,
telegramtype=TelegramType.GROUP_RESPONSE,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_value_reader_send_group_read(self):
self.assertEqual(
telegram,
Telegram(
group_address=GroupAddress("0/0/0"),
destination_address=GroupAddress("0/0/0"),
telegramtype=TelegramType.GROUP_READ,
),
)
Expand All @@ -104,25 +104,25 @@ def test_value_reader_telegram_received(self):
xknx = XKNX()
test_group_address = GroupAddress("0/0/0")
expected_telegram_1 = Telegram(
group_address=test_group_address,
destination_address=test_group_address,
telegramtype=TelegramType.GROUP_RESPONSE,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
)
expected_telegram_2 = Telegram(
group_address=test_group_address,
destination_address=test_group_address,
telegramtype=TelegramType.GROUP_WRITE,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
)
telegram_wrong_address = Telegram(
group_address=GroupAddress("0/0/1"),
destination_address=GroupAddress("0/0/1"),
telegramtype=TelegramType.GROUP_RESPONSE,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
)
telegram_wrong_type = Telegram(
group_address=test_group_address,
destination_address=test_group_address,
telegramtype=TelegramType.GROUP_READ,
direction=TelegramDirection.INCOMING,
payload=DPTBinary(1),
Expand Down
34 changes: 20 additions & 14 deletions test/devices_tests/binary_sensor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def test_process(self):
self.assertEqual(binaryinput.state, None)

telegram_on = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)
self.loop.run_until_complete(binaryinput.process(telegram_on))

self.assertEqual(binaryinput.state, True)

telegram_off = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(0)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(0)
)
self.loop.run_until_complete(binaryinput.process(telegram_off))
self.assertEqual(binaryinput.state, False)
Expand All @@ -54,7 +54,7 @@ def test_process(self):
self.assertEqual(binaryinput2.state, None)

telegram_off2 = Telegram(
group_address=GroupAddress("1/2/4"), payload=DPTBinary(0)
destination_address=GroupAddress("1/2/4"), payload=DPTBinary(0)
)
self.loop.run_until_complete(binaryinput2.process(telegram_off2))
self.assertEqual(binaryinput2.state, False)
Expand All @@ -67,14 +67,14 @@ def test_process_invert(self):
self.assertEqual(bs_invert.state, None)

telegram_on = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(0)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(0)
)
self.loop.run_until_complete(bs_invert.process(telegram_on))

self.assertEqual(bs_invert.state, True)

telegram_off = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)
self.loop.run_until_complete(bs_invert.process(telegram_off))
self.assertEqual(bs_invert.state, False)
Expand All @@ -92,7 +92,7 @@ def test_process_reset_after(self):
device_updated_cb=async_after_update_callback,
)
telegram_on = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)

self.loop.run_until_complete(binaryinput.process(telegram_on))
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_process_action(self):
self.assertEqual(switch.state, None)

telegram_on = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)
self.loop.run_until_complete(binary_sensor.process(telegram_on))
# process outgoing telegram from queue
Expand All @@ -141,7 +141,7 @@ def test_process_action(self):
self.assertEqual(switch.state, True)

telegram_off = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(0)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(0)
)
self.loop.run_until_complete(binary_sensor.process(telegram_off))
self.loop.run_until_complete(switch.process(xknx.telegrams.get_nowait()))
Expand All @@ -164,7 +164,7 @@ def test_process_action_ignore_internal_state(self):
self.assertEqual(switch.state, None)

telegram_on = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)

with patch("time.time") as mock_time, patch(
Expand Down Expand Up @@ -242,7 +242,9 @@ def test_process_callback(self):

switch.register_device_updated_cb(async_after_update_callback)

telegram = Telegram(group_address=GroupAddress("1/2/3"), payload=DPTBinary(1))
telegram = Telegram(
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)
self.loop.run_until_complete(switch.process(telegram))
# no _context_task started because ignore_internal_state is False
self.assertIsNone(switch._context_task)
Expand All @@ -268,7 +270,9 @@ def test_process_callback_ignore_internal_state(self):

switch.register_device_updated_cb(async_after_update_callback)

telegram = Telegram(group_address=GroupAddress("1/2/3"), payload=DPTBinary(1))
telegram = Telegram(
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)
self.assertEqual(switch.counter, 0)

self.loop.run_until_complete(switch.process(telegram))
Expand Down Expand Up @@ -308,7 +312,9 @@ def test_process_callback_ignore_internal_state_no_counter(self):

switch.register_device_updated_cb(async_after_update_callback)

telegram = Telegram(group_address=GroupAddress("1/2/3"), payload=DPTBinary(1))
telegram = Telegram(
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)
self.loop.run_until_complete(switch.process(telegram))
# no _context_task started because context_timeout is False
self.assertIsNone(switch._context_task)
Expand All @@ -334,10 +340,10 @@ def test_process_group_value_response(self):
switch.register_device_updated_cb(async_after_update_callback)

write_telegram = Telegram(
group_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)
response_telegram = Telegram(
group_address=GroupAddress("1/2/3"),
destination_address=GroupAddress("1/2/3"),
payload=DPTBinary(1),
telegramtype=TelegramType.GROUP_RESPONSE,
)
Expand Down
Loading