Is it possible to disable or customize the "device delete" function?

My App consists of a “parent”-device and multiple “child”-devices. If possible, I would like to prevent the user from deleting the parent before all children have been deleted.

I don’t think so. I set the childs to “unavailable” with a message that is displayed in device details. So the user is pointet on this and can delete the broken devices.

Thank you for your reply. Actually my code is handling this situation today, the way you propose, by marking alla children as Unavailable, if the parent is removed. This works, but it had been a better UX to be able to prevent the user from deleting the parent of mistake. But I can live with that.

Did you try throwing an error on OnUninit?

I don’t think it will work, but i dont think i have ever tried that. Perhaps it will work?

It will not.

You know this / experimented with this?
(Just a question, no offence)

Because i, ofc., would asume it would not work.
But i have had some amazing features in f.i. H.O.O.P. version 0.1, which was approved by Athom, because of some bugs that i exploited.

So i thought, perhaps nobody (icluding athom) has ever tried it to find a/this bug to prevent the removal of a device?

Also, my way of custom capabilities in AVDs is not suppose to work like this, and i had to test and manipulate my app.json and files a lott before finding a loophole so i could create custom icons for capabilities.

This is the SDK-code that is responsible for calling onUninit:

    Promise.resolve().then(() => HomeyApp.onUninit()).catch(this.error);
    for (const driver of Object.values(ManagerDrivers.getDrivers())) {
      Promise.resolve().then(() => driver.onUninit()).catch(this.error);
      for (const device of driver.getDevices()) {
        Promise.resolve().then(() => device.onUninit()).catch(this.error);

So any errors being thrown will just get caught and logged (if onUninit gets called at all, because this code is broken).

Besides that, onUninit is the wrong method anyway since it doesn’t get called when a device is deleted (only when an app gets killed/stopped/restarted). And lastly, device deletion is done in Homey’s core, an app will only get notified that one of its devices was deleted, but it can’t prevent it.

1 Like

You’re right, silly of me, i ment the OnDelete/OnRemove method in the device.js ofc.