-
Notifications
You must be signed in to change notification settings - Fork 17
WIP: implement retrieving sw_build_id attribute from Basic cluster #23
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -310,22 +310,54 @@ class ZHANetworkCard extends HTMLElement { | |
| }); | ||
| } | ||
|
|
||
| set hass(hass) { | ||
| const config = this._config; | ||
| const root = this.shadowRoot; | ||
|
|
||
| hass | ||
| async init(hass, config, root) { | ||
| await hass | ||
| .callWS({ | ||
| type: "zha/devices", | ||
| }) | ||
| .then((devices) => { | ||
| .then(async (devices) => { | ||
| // `raw_rows` to be filled with data here, due to 'attr_as_list' it is possible to have | ||
| // multiple data `raw_rows` acquired into one cell(.raw_data), so re-iterate all rows | ||
| // to---if applicable---spawn new DataRowZHA objects for these accordingly | ||
| let raw_rows = devices.map( | ||
| const raw_rows = devices.map( | ||
| (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) => { | ||
| if (read_sw_build_id && e.device.attributes.available) { | ||
| // retrieving cluster attributes requires additional ws calls | ||
| await hass.callWS({ | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These |
||
| type: "zha/devices/clusters", | ||
| ieee: e.device.attributes.ieee | ||
| }).then(async (clusters) => { | ||
| for (const cluster of clusters) { | ||
| if (cluster["type"] == "in" && cluster["name"] == "Basic") { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be made dynamic to support other clusters. |
||
| e.device.sw_build_id = await hass.callWS({ | ||
| type: "zha/devices/clusters/attributes/value", | ||
| "ieee": e.device.attributes.ieee, | ||
| "endpoint_id": cluster.endpoint_id, | ||
| "cluster_id": cluster.id, | ||
| "cluster_type": "in", | ||
| "attribute": 0x4000, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be made dynamic to support other attributes. |
||
| }).then((value) => { | ||
| console.log("DEBUG: %s (%s) has sw_build_id %s", e.device.attributes.ieee, JSON.stringify(e.device.attributes.user_given_name || e.device.attributes.name), value) | ||
| return value | ||
| }).catch((error) => { | ||
| console.log("DEBUG: failed to retrieve sw_build_id for device %s: %s", e.device.attributes.ieee, JSON.stringify(error)) | ||
| return error.message | ||
| }); | ||
| } | ||
| } | ||
| }).catch((error) => { | ||
| console.log("DEBUG: failed to retrieve clusters for device %s: %s", e.device.attributes.ieee, JSON.stringify(error)) | ||
| return error.message | ||
| }); | ||
| } else { | ||
| console.log("DEBUG: %s", JSON.stringify(error)) | ||
| e.device.sw_build_id = "N/A" | ||
| } | ||
| e.get_raw_data(config.columns) | ||
| })); | ||
|
|
||
| // now add() the raw_data rows to the DataTableZHA | ||
| this.tbl.clear_rows(); | ||
|
|
@@ -350,6 +382,17 @@ class ZHANetworkCard extends HTMLElement { | |
| }); | ||
| } | ||
|
|
||
| set hass(hass) { | ||
| console.log("DEBUG: set hass(hass) is called") | ||
| const config = this._config; | ||
| const root = this.shadowRoot; | ||
|
|
||
| if (!this.initialized) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| this.initialized = true | ||
| this.init(hass, config, root); | ||
| } | ||
| } | ||
|
|
||
| _setCardSize(num_rows) { | ||
| this.card_height = parseInt(num_rows * 0.5); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.