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

feat: add api for device re-interview #22788

Merged
merged 4 commits into from
May 30, 2024
Merged

Conversation

justfalter
Copy link
Contributor

@justfalter justfalter commented May 26, 2024

  • Adds an API that allows for the re-interview of a device. This can be useful a device firmware upgrade adds new device endpoints (as is the case when upgrading an Inovelli VZM31-SN to 2.18). Without the ability to re-interview, one must remove and re-add the device.

Notes:

  • I have only really tested performing device re-interviews via a hand-crafted extension (see gist). It was as simple as await someDevice.interview(). I have not had a chance to this changeset on my system (it's sunday morning and the kids are running around).
  • As far as I can tell, this seems to require restarting z2m in order for the UI to reflect any changes picked up by the re-interview. I feel like this might be a matter of having whatever drives the frontend be responsive to device interview events?
  • As mentioned, this eliminated the need for me to remove and re-add 18 Inovelli VZM31-SN switches. I reinterviewed the devices, restarted z2m, and all was good in the world.

@justfalter
Copy link
Contributor Author

  • I have only really tested performing device re-interviews via a hand-crafted extension (see gist). It was as simple as await someDevice.interview(). I have not had a chance to this changeset on my system (it's sunday morning and the kids are running around).

FWIW, I've had a chance to test out a version of the hass addon from my branch, and it seems to be working.

  1. Publish {"id":"study_light_switch"} to the zigbee2mqtt/bridge/request/device/reinterview topic
  2. I see debug-level messages indicating that it is interviewing the device associated with study_light_switch:
  • zh:controller:device: Interview - start device '0xb43a....'
  • zh:controller:device: Interview - skip node descriptor request for '0xb43a....', already got it
  • zh:controller:device: Interview - got simple descriptor for endpoint '1' device '0xb43a....'
  • zh:controller:device: Interview - got simple descriptor for endpoint '2' device '0xb43a....'
  • zh:controller:device: Interview - got simple descriptor for endpoint '3' device '0xb43a....'
  • zh:controller:device: Interview - got simple descriptor for endpoint '242' device '0xb43a....'
  • zh:controller:device: Interview - completed for device '0xb43a....'
  • zh:controller:database: Writing database to '/config/zigbee2mqtt/database.db'
  • z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/bridge/response/device/reinterview', payload '{"data":{"id":"study_light_switch"},"status":"ok"}'
  1. I receive {"data":{"id":"study_light_switch"},"status":"ok"} on the zigbee2mqtt/bridge/response/device/reinterview topic.

I suspect the reason that a restart is required after the interview is because calling device.interview() doesn't result in any events being emitted on its own, so zigbee2mqtt doesn't actually know that the device had been re-interviewed.
It appears that this is wrapped up as part of an onDeviceJoined handler: https://github.com/Koenkk/zigbee-herdsman/blob/25b583f9087f1700c3a59192f7f20a3607aec67f/src/controller/controller.ts#L606-L620 . Perhaps herdsman could be modified so that any device.interview() leads to the proper events being emitted.

lib/extension/bridge.ts Outdated Show resolved Hide resolved
@Koenkk
Copy link
Owner

Koenkk commented May 27, 2024

  • I think it would be handy to also have a button in the frontend, maybe next to the yellow refresh icon?
  • When interview failed, I think it would be good to show to button there (so that people can easily trigger a re-interview)

@justfalter
Copy link
Contributor Author

  • I think it would be handy to also have a button in the frontend, maybe next to the yellow refresh icon?
  • When interview failed, I think it would be good to show to button there (so that people can easily trigger a re-interview)

We might be agreeing, but I think there should always be an interview button somewhere in the Device page... its presence will eliminate a lot of "upgrade firmware, delete and rejoin the device" that I see on the Inovelli forums.

I was thinking the fa-exchange icon, if you don't think it looks too similar to the re-configure icon (fa-retweet).

justfalter added a commit to justfalter/zigbee2mqtt-frontend that referenced this pull request May 27, 2024
* Adds an "interview" button which starts an interview for the
  associated device. See Koenkk/zigbee2mqtt#22788
* The icon is [fa-info](https://fontawesome.com/v6/icons/info?f=classic&s=solid).
@justfalter
Copy link
Contributor Author

PR to add an "interview" button.

@justfalter justfalter requested a review from Koenkk May 27, 2024 21:50
@Koenkk
Copy link
Owner

Koenkk commented May 28, 2024

Agree, thanks! Reviewed both PRs and all is OK, could you also make a PR for the docs? Then this can be merged.

throw new Error(`Invalid payload`);
}

const device = this.zigbee.resolveEntityAndEndpoint(message.id).entity as Device;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Koenkk I just realized that I am using resolveEntityAndEndpoint, which is a little weird since interviewing is a device-level thing. I'll change it to using getEntity('device', ....)

- Adds an API that allows for the re-interview of a device. This can be
  useful a device firmware upgrade adds new device endpoints (as is the case
  when upgrading an Inovelli VZM31-SN to 2.18). Without the ability to
  re-interview, one must remove and re-add the device.
@justfalter
Copy link
Contributor Author

Agree, thanks! Reviewed both PRs and all is OK, could you also make a PR for the docs? Then this can be merged.

Doc PR: Koenkk/zigbee2mqtt.io#2777

@Koenkk Koenkk merged commit b6ad641 into Koenkk:dev May 30, 2024
11 checks passed
@Koenkk
Copy link
Owner

Koenkk commented May 30, 2024

Thanks!

@Koenkk Koenkk mentioned this pull request May 30, 2024
@justfalter justfalter deleted the device-re-interview branch May 31, 2024 01:39
Koenkk pushed a commit to nurikk/zigbee2mqtt-frontend that referenced this pull request May 31, 2024
* feat(DeviceControlGroup): add interview button

* Adds an "interview" button which starts an interview for the
  associated device. See Koenkk/zigbee2mqtt#22788
* The icon is [fa-info](https://fontawesome.com/v6/icons/info?f=classic&s=solid).

* feat(DeviceControlGroup): make things pretty
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