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

**URL:** <https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004>\
**Category:** Developers\
**Tags:** app\
**Created:** [November 10, 2022, 5:56pm UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004 "2022-11-10T17:56:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gol](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gol/32/34726_2.png) [@gol](https://community.homey.app/u/gol)\
**Post date:** [November 10, 2022, 5:56pm UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004/1 "2022-11-10T17:56:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [November 10, 2022, 6:23pm UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004/2 "2022-11-10T18:23:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gol](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gol/32/34726_2.png) [@gol](https://community.homey.app/u/gol)\
**Post date:** [November 10, 2022, 6:52pm UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004/3 "2022-11-10T18:52:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [November 13, 2022, 10:34am UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004/4 "2022-11-13T10:34:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 13, 2022, 10:37am UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004/5 "2022-11-13T10:37:02Z")

</div>

> [@Arie\_J\_Godschalk](#):
>
> Perhaps it will work?

It will not.

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [November 13, 2022, 3:00pm UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004/6 "2022-11-13T15:00:50Z")

</div>

> [@robertklep](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 13, 2022, 3:15pm UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004/7 "2022-11-13T15:15:03Z")

</div>

> [@Arie\_J\_Godschalk](#):
>
> You know this / experimented with this?

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

```auto
    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](https://github.com/athombv/homey-apps-sdk-issues/issues/259)).

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.

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [November 13, 2022, 6:02pm UTC](https://community.homey.app/t/is-it-possible-to-disable-or-customize-the-device-delete-function/72004/8 "2022-11-13T18:02:55Z")

</div>

> [@robertklep](#):
>
> 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)

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