Skip to content

Commit

Permalink
XBee: Use named arguments for cluster commands (#1902)
Browse files Browse the repository at this point in the history
* xbee: use named arguments for cluster params

* add a note for zigpy_znp

* more named params

* black

* use struct names instead of indexes
  • Loading branch information
Shulyaka authored Nov 11, 2022
1 parent 3a27959 commit d6bdb39
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 76 deletions.
12 changes: 7 additions & 5 deletions tests/test_xbee.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ async def test_receive_serial_data(zigpy_device_from_quirk):
None,
b"2\x00\x02\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe%V",
b"\x01%V\x00\x0C\xE4",
"%v_command_response",
"percentv_command_response",
3300,
),
# Write uint16_t argument
Expand All @@ -278,7 +278,7 @@ async def test_receive_serial_data(zigpy_device_from_quirk):
2700,
b"2\x00\x02\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfeV+\x0A\x8C",
b"\x01V+\x00",
"v+_command_response",
"vplus_command_response",
None,
),
# Read uint8_t argument
Expand Down Expand Up @@ -319,7 +319,7 @@ async def test_receive_serial_data(zigpy_device_from_quirk):
),
# Command with no arguments
(
94,
93,
None,
b"2\x00\x02\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfeAS",
b"\x01AS\x00",
Expand Down Expand Up @@ -417,7 +417,7 @@ def mock_at_response(*args, **kwargs):
# Write bool argument
(31, "PM", True, None),
# Command with no arguments
(94, "AS", None, None),
(93, "AS", None, None),
),
)
async def test_remote_at_native(
Expand Down Expand Up @@ -457,7 +457,9 @@ async def test_remote_at_native(
)
assert status == foundation.Status.SUCCESS
listener.zha_send_event.assert_called_once_with(
command.lower() + "_command_response", {"response": response_value}
command.replace("%V", "PercentV").replace("V+", "VPlus").lower()
+ "_command_response",
{"response": response_value},
)


Expand Down
35 changes: 34 additions & 1 deletion xbee.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
This document describes how to use Digi XBee device as a router or end device.

## Using with non-XBee coordinator

You may need to configure zigpy to listen to the appropriate additional endpoints which it ignores by default. This is an example config for HA ZHA:

```
zha:
zigpy_config:
additional_endpoints:
- endpoint: 0xE6
profile: 0xC105
device_type: 0x0000
device_version: 0b0000
input_clusters: [0xA1]
output_clusters: [0x21]
- endpoint: 0xE8
profile: 0xC105
device_type: 0x0000
device_version: 0b0000
input_clusters: [0x11, 0x92]
output_clusters: [0x11]
```
If you are using `zigpy_znp`, you might also need need to add
```
znp_config:
prefer_endpoint_1: false
```
to the `zigpy_config:` section.
Please note that not all coordinators have been tested yet.

## Digital GPIO

Digital input/output pins are exposed as switches.
Expand Down Expand Up @@ -58,7 +89,8 @@ automation:
cluster_type: in
command: 0
command_type: server
args: Assistant
params:
data: Assistant
```

## Remote AT Commands
Expand Down Expand Up @@ -98,4 +130,5 @@ automation:
command_type: server
cluster_type: out
cluster_id: 33
params: {}
```
2 changes: 1 addition & 1 deletion zhaquirks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def handle_cluster_request(
):
self.listener_event(
ZHA_SEND_EVENT,
self.server_commands.get(hdr.command_id, (hdr.command_id))[0],
self.server_commands.get(hdr.command_id, (hdr.command_id)).name,
args,
)

Expand Down
Loading

0 comments on commit d6bdb39

Please sign in to comment.