Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: implement retrieving sw_build_id attribute from Basic cluster #23

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pdecat
Copy link

@pdecat pdecat commented Nov 25, 2020

This is marked as WIP as it works but retrieving cluster attributes is slow for unreachable devices (mostly battery powered ones),
and this blocks the rendering of the table.

I'd like to alter the way the table rendering is done to accept Promises from get_raw_data() and update the tables cells asynchronously when the promises are fulfilled.

Submitted early as draft PR to get feedback if something like this would be accepted, and if so to get advice on how to improve this.

Sample configuration for ui-lovelace.yaml:

          - id: zigbee-zha-network
            type: "custom:zha-network-card"
            clickable: true
            sort_by: last_seen-
            columns:
              - name: Name
                prop: name
              - attr: available
                id: available
                modify: x || "false"
                name: Online
              - attr: manufacturer
                name: Manufacturer
              - attr: model
                name: Model
              - attr: ieee
                name: IEEE
              - name: NWK
                prop: nwk
              - attr: rssi
                name: RSSI
              - attr: lqi
                name: LQI
              - attr: last_seen
                name: Last Seen
              - attr: power_source
                name: Power Source
              - attr: quirk_class
                name: Quirk
              - prop: sw_build_id
                name: SW

Resulting output:

image

const config = this._config;
const root = this.shadowRoot;

if (!this.initialized) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary to avoid hammering the zigbee devices with actual cluster attribute requests as set hass(hass) is invoked very often.

(e) => new DataRowZHA({ attributes: e }, config.strict)
);
raw_rows.forEach((e) => e.get_raw_data(config.columns));
const read_sw_build_id = config.columns.filter((col) => col.prop == "sw_build_id");
await Promise.allSettled(raw_rows.map(async (e) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blocks the rendering of the table until all cluster attribute requests are done (successes and fails).

This is needed as the rendering currently does not accept promises, only actual values.

await Promise.allSettled(raw_rows.map(async (e) => {
if (read_sw_build_id && e.device.attributes.available) {
// retrieving cluster attributes requires additional ws calls
await hass.callWS({
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These hass.callWS() invocations of zha/devices/clusters and zha/devices/clusters/attributes/value types could probably be cached to avoid hammering the zigbee network and devices.

"endpoint_id": cluster.endpoint_id,
"cluster_id": cluster.id,
"cluster_type": "in",
"attribute": 0x4000,
Copy link
Author

@pdecat pdecat Nov 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be made dynamic to support other attributes.

ieee: e.device.attributes.ieee
}).then(async (clusters) => {
for (const cluster of clusters) {
if (cluster["type"] == "in" && cluster["name"] == "Basic") {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be made dynamic to support other clusters.

@rasmusbe
Copy link

rasmusbe commented Nov 3, 2021

Any more progress with this? Do you need any help finishing it?

@pdecat
Copy link
Author

pdecat commented Nov 3, 2021

Well, it works for me, but I'm unsure there's any hope to see this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants