From 2ad7abbf8908dc606d61ea4249ca355bb8e1ed0f Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Fri, 12 May 2023 00:33:07 +0200 Subject: [PATCH 1/4] Remove some redundancy --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d7af7a..ae7f835 100644 --- a/README.md +++ b/README.md @@ -303,8 +303,8 @@ endpoint ID (a byte), the cluster ID (a two byte word), and the attribute ID (a two byte word as well). Attributes have different types, such as boolean, unsigned and signed byte, -arrays, timestamps, and more. Most of the time, the attribute type can be -generally determined automatically by tools like zha-toolkit and ZHA. +arrays, timestamps, and more. In most cases, the attribute type can be +determined automatically by tools like zha-toolkit and ZHA. The Zigbee Cluster Library (ZCL) document defines standard attributes and their organization in clusters. Manufacturers also have the freedom to add From f475115f8ed2a8c841f719c98777ba9d8b809494 Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Fri, 26 May 2023 23:18:54 +0200 Subject: [PATCH 2/4] zha_devices: optional filter on ieee address to limit output --- README.md | 2 ++ custom_components/zha_toolkit/__init__.py | 6 +++++- custom_components/zha_toolkit/services.yaml | 11 ++++++++++- custom_components/zha_toolkit/zha.py | 5 +++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae7f835..3acfb2b 100644 --- a/README.md +++ b/README.md @@ -1709,6 +1709,8 @@ allows you to get information about endpoints and services as well. ```yaml service: zha_toolkit.zha_devices data: + # Optional: Device to report on, by default all devices are in the report + ieee: sensor.my_zha_sensor # Optional list of fields to write to the CSV, all non-list fields by default. command_data: [name, ieee, rssi, lqi] # Optional, field the list is sorted by (example: sort by signal strength) diff --git a/custom_components/zha_toolkit/__init__.py b/custom_components/zha_toolkit/__init__.py index 4d04f46..de70cf5 100644 --- a/custom_components/zha_toolkit/__init__.py +++ b/custom_components/zha_toolkit/__init__.py @@ -343,7 +343,11 @@ extra=vol.ALLOW_EXTRA, ), S.ZHA_DEVICES: vol.Schema( - {}, + { + vol.Optional(ATTR_IEEE): vol.Any( + cv.entity_id_or_uuid, t.EUI64.convert + ), + }, extra=vol.ALLOW_EXTRA, ), S.HANDLE_JOIN: vol.Schema( diff --git a/custom_components/zha_toolkit/services.yaml b/custom_components/zha_toolkit/services.yaml index addb8ef..c56c992 100644 --- a/custom_components/zha_toolkit/services.yaml +++ b/custom_components/zha_toolkit/services.yaml @@ -2142,8 +2142,17 @@ znp_backup: selector: boolean: zha_devices: - description: Export IEEE device information to CSV file or Event + description: Export device information to CSV file or Event fields: + ieee: + description: >- + Optional Entity name,\ndevice name, or IEEE address of the device to + provide details for. By dfault: all devices + example: 00:0d:6f:00:05:7d:2d:34 + required: false + selector: + entity: + integration: zha command_data: description: List of columns for csv file example: [ieee, lqi, name] diff --git a/custom_components/zha_toolkit/zha.py b/custom_components/zha_toolkit/zha.py index 44610ac..2c1b77c 100644 --- a/custom_components/zha_toolkit/zha.py +++ b/custom_components/zha_toolkit/zha.py @@ -46,6 +46,11 @@ async def zha_devices( # 'endpoints' devices = [device.zha_device_info for device in listener.devices.values()] + + if ieee is not None: + # Select only the device with the given address + devices = [d for d in devices if d["ieee"] == ieee] + # Set default value for 'devices' in event_data, # may be slimmed down. Ensures that devices is set in case # an exception occurs. From 8b4b106343c4c4a4c9dead71a02c8724dea1053e Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Sat, 10 Jun 2023 23:58:42 +0200 Subject: [PATCH 3/4] Adapt expression to test if IEEE is coordinator (zigpy changes?) --- custom_components/zha_toolkit/binds.py | 5 +++-- custom_components/zha_toolkit/zha.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/custom_components/zha_toolkit/binds.py b/custom_components/zha_toolkit/binds.py index fcb0fa1..14913fd 100644 --- a/custom_components/zha_toolkit/binds.py +++ b/custom_components/zha_toolkit/binds.py @@ -219,10 +219,11 @@ async def bind_ieee( # when command_data is set to 0 or false, bind to coordinator data = app.ieee - isCoordinatorTarget = str(data) == str(app.ieee) - dst_dev = await u.get_device(app, listener, data) + # Coordinator has nwk address 0 + isCoordinatorTarget = dst_dev.nwk == 0x0000 + zdo = src_dev.zdo src_out_clusters = BINDABLE_OUT_CLUSTERS src_in_clusters = BINDABLE_IN_CLUSTERS diff --git a/custom_components/zha_toolkit/zha.py b/custom_components/zha_toolkit/zha.py index 2c1b77c..2c02268 100644 --- a/custom_components/zha_toolkit/zha.py +++ b/custom_components/zha_toolkit/zha.py @@ -48,8 +48,9 @@ async def zha_devices( devices = [device.zha_device_info for device in listener.devices.values()] if ieee is not None: + ieee = str(ieee) # Select only the device with the given address - devices = [d for d in devices if d["ieee"] == ieee] + devices = [d for d in devices if str(d['ieee']) == ieee ] # Set default value for 'devices' in event_data, # may be slimmed down. Ensures that devices is set in case From 1227d274e45b46667f37a3b48ce4656c2a053780 Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Sun, 11 Jun 2023 00:02:05 +0200 Subject: [PATCH 4/4] Small formatting fix --- custom_components/zha_toolkit/zha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/zha_toolkit/zha.py b/custom_components/zha_toolkit/zha.py index 2c02268..aff7a42 100644 --- a/custom_components/zha_toolkit/zha.py +++ b/custom_components/zha_toolkit/zha.py @@ -50,7 +50,7 @@ async def zha_devices( if ieee is not None: ieee = str(ieee) # Select only the device with the given address - devices = [d for d in devices if str(d['ieee']) == ieee ] + devices = [d for d in devices if str(d["ieee"]) == ieee] # Set default value for 'devices' in event_data, # may be slimmed down. Ensures that devices is set in case