Skip to content

Commit

Permalink
Merge pull request #17 from mdeweerd/dev
Browse files Browse the repository at this point in the history
Add binds_get
  • Loading branch information
mdeweerd authored Feb 18, 2022
2 parents 99583c3 + 269b171 commit 245975c
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 17 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,22 @@ data:
```

## `binds_get`: Get binding table from the device

Get the bindings from the device.\
Listen to the event, or enable debug and
check the log to get the information.\
Current limitation: only one request
is made, if the binding table is long, the reply will be partial only. The
reply is provided as given by zigpy.

```yaml
service: zha_toolkit.binds_get
data:
ieee: 00:15:8d:00:04:7b:83:69
event_done: event_binds_get_done
```

## `handle_join`: Handle join - rediscover device

```yaml
Expand Down
40 changes: 30 additions & 10 deletions custom_components/zha_toolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
),
S.ATTR_READ: vol.Schema(
{
vol.Required(ATTR_IEEE): cv.string,
vol.Required(ATTR_IEEE): vol.Any(
cv.entity_id_or_uuid, t.EUI64.convert
),
vol.Optional(P.ENDPOINT): vol.Range(0, 255),
vol.Required(P.CLUSTER): vol.Range(0, 0xFFFF),
vol.Required(P.ATTRIBUTE): vol.Any(
Expand All @@ -104,7 +106,9 @@
),
S.ATTR_WRITE: vol.Schema(
{
vol.Required(ATTR_IEEE): cv.string,
vol.Required(ATTR_IEEE): vol.Any(
cv.entity_id_or_uuid, t.EUI64.convert
),
vol.Optional(P.ENDPOINT): vol.Range(0, 255),
vol.Required(P.CLUSTER): vol.Range(0, 0xFFFF),
vol.Required(P.ATTRIBUTE): vol.Any(
Expand Down Expand Up @@ -143,14 +147,24 @@
),
S.BIND_IEEE: vol.Schema(
{
vol.Required(ATTR_IEEE): cv.string,
vol.Required(ATTR_IEEE): vol.Any(
cv.entity_id_or_uuid, t.EUI64.convert
),
vol.Required(ATTR_COMMAND_DATA): cv.string,
vol.Optional(P.CLUSTER): vol.Any(
vol.Range(0, 0xFFFF), [vol.Range(0, 0xFFFF)]
),
},
extra=vol.ALLOW_EXTRA,
),
S.BINDS_GET: vol.Schema(
{
vol.Required(ATTR_IEEE): vol.Any(
cv.entity_id_or_uuid, t.EUI64.convert
),
},
extra=vol.ALLOW_EXTRA,
),
S.CONF_REPORT: vol.Schema(
{
vol.Required(ATTR_IEEE): vol.Any(
Expand Down Expand Up @@ -253,26 +267,34 @@
),
S.HANDLE_JOIN: vol.Schema(
{
vol.Optional(ATTR_IEEE): cv.string,
vol.Optional(ATTR_IEEE): vol.Any(
cv.entity_id_or_uuid, t.EUI64.convert
),
vol.Optional(ATTR_COMMAND_DATA): vol.Range(0, 0xFFFF),
},
extra=vol.ALLOW_EXTRA,
),
S.IEEE_PING: vol.Schema(
{
vol.Optional(ATTR_IEEE): cv.string,
vol.Required(ATTR_IEEE): vol.Any(
cv.entity_id_or_uuid, t.EUI64.convert
),
},
extra=vol.ALLOW_EXTRA,
),
S.LEAVE: vol.Schema(
{
vol.Optional(ATTR_IEEE): cv.string,
vol.Required(ATTR_IEEE): vol.Any(
cv.entity_id_or_uuid, t.EUI64.convert
),
},
extra=vol.ALLOW_EXTRA,
),
S.MISC_REINITIALIZE: vol.Schema(
{
vol.Optional(ATTR_IEEE): cv.string,
vol.Required(ATTR_IEEE): vol.Any(
cv.entity_id_or_uuid, t.EUI64.convert
),
},
extra=vol.ALLOW_EXTRA,
),
Expand All @@ -287,9 +309,7 @@
extra=vol.ALLOW_EXTRA,
),
S.REGISTER_SERVICES: vol.Schema(
{
vol.Optional(ATTR_IEEE): cv.string,
},
{},
extra=vol.ALLOW_EXTRA,
),
S.REMOVE_ALL_GROUPS: vol.Schema(
Expand Down
22 changes: 22 additions & 0 deletions custom_components/zha_toolkit/binds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from zigpy.zdo.types import ZDOCmd

from . import utils as u
from .params import INTERNAL_PARAMS as p

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -322,3 +323,24 @@ async def unbind_coordinator(
LOGGER.debug(
"0x%04x: unbinding 0x%04x: %s", src_dev.nwk, cluster_id, res
)


async def binds_get(
app, listener, ieee, cmd, data, service, params, event_data
):
"""
Get bindings from device.
"""

if ieee is None:
LOGGER.error("missing ieee")
return
src_dev = app.get_device(ieee=ieee)

zdo = src_dev.zdo

# Todo: continue when reply is incomplete (update start index)
result = await zdo.request(ZDOCmd.Mgmt_Bind_req, 0, tries=params[p.TRIES])
LOGGER.debug("0x%04x: bindings ieee {ieee!r}: %s", result)

event_data["result"] = result
1 change: 1 addition & 0 deletions custom_components/zha_toolkit/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SERVICE_consts:
BACKUP = "backup"
BIND_GROUP = "bind_group"
BIND_IEEE = "bind_ieee"
BINDS_GET = "binds_get"
CONF_REPORT = "conf_report"
CONF_REPORT_READ = "conf_report_read"
EZSP_ADD_KEY = "ezsp_add_key"
Expand Down
60 changes: 53 additions & 7 deletions custom_components/zha_toolkit/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ execute:
- backup
- bind_group
- bind_ieee
- binds_get
- conf_report
- conf_report_read
- ezsp_add_key
Expand Down Expand Up @@ -59,9 +60,8 @@ execute:
- znp_nvram_restore
- znp_restore
ieee:
description: >-
Entity name,\ndevice name, or\nIEEE address of the node to execute
command
description: "Entity name,\ndevice name, or\nIEEE address of the node to execute\n\
command"
example: 00:0d:6f:00:05:7d:2d:34
selector:
entity:
Expand Down Expand Up @@ -561,6 +561,53 @@ bind_ieee:
description: Wait for/expect a reply (not used yet)
selector:
boolean:
binds_get:
description: >-
Get binding table from device. Note: very basic implementation,
return not decoded.
fields:
ieee:
description: >-
Entity name,\ndevice name, or\nIEEE address of the node to execute
command
example: 00:0d:6f:00:05:7d:2d:34
required: true
selector:
entity:
integration: zha
tries:
description: Number of times the zigbee packet should be attempted
selector:
number:
min: 0
max: 255
mode: box
event_success:
description: Event name in case of success
example: my_read_success_trigger_event
selector:
text:
event_fail:
description: Event name in case of failure
example: my_read_fail_trigger_event
selector:
text:
event_done:
description: >-
Event name when the service call did all its work (either success
or failure). Has event data with relevant attributes.
example: my_read_done_trigger_event
selector:
text:
fail_exception:
description: >-
Throw exception when success==False, useful to stop scripts, automations
selector:
boolean:
expect_reply:
description: Wait for/expect a reply (not used yet)
selector:
boolean:
conf_report:
description: >-
Configure attribute reporting\nYou can set a high value for tries
Expand Down Expand Up @@ -949,10 +996,9 @@ zha_devices:
example: lqi
selector:
select:
options: [ieee, nwk, manufacturer, model, name, quirk_applied,
quirk_class, manufacturer_code, power_source, lqi, rssi,
last_seen, available, device_type, user_given_name,
device_reg_id, area_id]
options: [ieee, nwk, manufacturer, model, name, quirk_applied, quirk_class,
manufacturer_code, power_source, lqi, rssi, last_seen, available, device_type,
user_given_name, device_reg_id, area_id]
event_success:
description: Event name in case of success
example: my_read_success_trigger_event
Expand Down

0 comments on commit 245975c

Please sign in to comment.