Skip to content

Commit

Permalink
Add source_address to Telegram() (#516)
Browse files Browse the repository at this point in the history
* use keyword arguments for Telegram() in tests

for readability

* add source_address to Telegram()

* add source to knx_event

* add telegram source

* cleaner log messages

- reordered Telegram.__str__()
- use strings for telegramtype and direction

* update HA knx_event

* forgot print statement

* telegramtype instead of type

* use keyword arguments for Telegram()
  • Loading branch information
farmio authored Nov 29, 2020
1 parent 6b2e8d7 commit 825ea63
Show file tree
Hide file tree
Showing 34 changed files with 591 additions and 231 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## Unreleased changes

### HA integration

- knx_event: renamed `address` to `destination` and added `source`, `telegramtype`, `direction` attributes.

### Internals

- Telegram: `group_address` renamed to `destination_address`, to prepare support for other APCI services.
- Telegram: `group_address` renamed to `destination_address`, to prepare support for other APCI services and add `source_address`
- Farewell Travis CI; Welcome Github Actions!

## 0.15.6 Bugfix for StateUpater 2020-11-26
Expand Down
8 changes: 6 additions & 2 deletions examples/example_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ async def main():
await tunnel.connect_udp()
await tunnel.connect()

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

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

Expand Down
4 changes: 3 additions & 1 deletion test/devices_tests/binary_sensor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def test_process_wrong_payload(self):
"""Test process wrong telegram (wrong payload type)."""
xknx = XKNX()
binary_sensor = BinarySensor(xknx, "Warning", group_address_state="1/2/3")
telegram = Telegram(GroupAddress("1/2/3"), payload=DPTArray((0x1, 0x2, 0x3)))
telegram = Telegram(
destination_address=GroupAddress("1/2/3"), payload=DPTArray((0x1, 0x2, 0x3))
)
with self.assertRaises(CouldNotParseTelegram):
self.loop.run_until_complete(binary_sensor.process(telegram))

Expand Down
Loading

0 comments on commit 825ea63

Please sign in to comment.