-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- example_restart.py will restart actor 1.2.3 - example_info.py will print actor information
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Example on how to read mask version and properties from a KNX actor.""" | ||
import asyncio | ||
|
||
from xknx import XKNX | ||
from xknx.core import PayloadReader | ||
from xknx.telegram import PhysicalAddress, \ | ||
PropertyRead, PropertyResponse, MaskVersionRead, MaskVersionResponse | ||
|
||
|
||
async def main(): | ||
"""Connect and read properties from KNX bus.""" | ||
xknx = XKNX() | ||
await xknx.start() | ||
|
||
reader = PayloadReader(xknx, PhysicalAddress("1.1.1")) | ||
|
||
# Read the mask version of the device (descriptor 0). | ||
payload = await reader.send(MaskVersionRead(descriptor=0), response_class=MaskVersionResponse) | ||
if payload is not None: | ||
print("Mask version: %04x" % payload.value) | ||
|
||
# Read the serial number of the device (object 0, property 11). | ||
payload = await reader.send(PropertyRead(object_index=0, property_id=11, count=1, start_index=1), response_class=PropertyResponse) | ||
if payload is not None: | ||
print("Serial number: %02x%02x:%02x%02x%02x%02x" % ( | ||
payload.data[0], payload.data[1], payload.data[2], | ||
payload.data[3], payload.data[4], payload.data[5])) | ||
|
||
# Check if the device is in programming mode (object 0, property 54). | ||
payload = await reader.send(PropertyRead(object_index=0, property_id=54, count=1, start_index=1), response_class=PropertyResponse) | ||
if payload is not None: | ||
print("Programming mode: %s" % ("ON" if payload.data[0] else "OFF")) | ||
|
||
await xknx.stop() | ||
|
||
|
||
# pylint: disable=invalid-name | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(main()) | ||
loop.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Example on how to connecto to a KNX/IP tunneling device.""" | ||
import asyncio | ||
|
||
from xknx import XKNX | ||
from xknx.io import GatewayScanner, Tunnel | ||
from xknx.telegram import PhysicalAddress, Telegram, Restart | ||
|
||
|
||
async def main(): | ||
"""Connect to a tunnel, send 2 telegrams and disconnect.""" | ||
xknx = XKNX() | ||
gatewayscanner = GatewayScanner(xknx) | ||
gateways = await gatewayscanner.scan() | ||
|
||
if not gateways: | ||
print("No Gateways found") | ||
return | ||
|
||
gateway = gateways[0] | ||
src_address = PhysicalAddress("15.15.249") | ||
|
||
print("Connecting to {}:{} from {}".format( | ||
gateway.ip_addr, | ||
gateway.port, | ||
gateway.local_ip)) | ||
|
||
tunnel = Tunnel( | ||
xknx, | ||
src_address, | ||
local_ip=gateway.local_ip, | ||
gateway_ip=gateway.ip_addr, | ||
gateway_port=gateway.port) | ||
|
||
await tunnel.connect_udp() | ||
await tunnel.connect() | ||
|
||
await tunnel.send_telegram(Telegram(PhysicalAddress('1.2.3'), payload=Restart())) | ||
await asyncio.sleep(2) | ||
|
||
await tunnel.connectionstate() | ||
await tunnel.disconnect() | ||
|
||
# pylint: disable=invalid-name | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(main()) | ||
loop.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters