# Versioning whan adding a new capability

**URL:** <https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636>\
**Category:** Developers\
**Created:** [April 24, 2021, 6:16am UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636 "2021-04-24T06:16:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BufferOverflow](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bufferoverflow/32/12568_2.png) [@BufferOverflow](https://community.homey.app/u/BufferOverflow)\
**Post date:** [April 24, 2021, 6:16am UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636/1 "2021-04-24T06:16:16Z")

</div>

Hi,

What is the best way to add a new capability to an app device when it comes to versioning?

My initial testing shows that adding a capability does not break the current device or flows. But the code with result in an exception trying to set the new capability before the user removes the old device and adds it again.

Are there any best practices when it comes to this? Any way to add a capability without the user having to remove/add the device? Some kind of migration?

Thanks for any advice or examples here 🙂

---

<div class="post-metadata">

**Author:** ![TedTolboom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tedtolboom/32/12081_2.png) [@TedTolboom](https://community.homey.app/u/TedTolboom)\
**Post date:** [April 24, 2021, 6:20am UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636/2 "2021-04-24T06:20:37Z")

</div>

Yes, check the developer documentation on the ‘addCapability’ method.

Adds the capability without the need to remove and add the device again.

---

<div class="post-metadata">

**Author:** ![BufferOverflow](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bufferoverflow/32/12568_2.png) [@BufferOverflow](https://community.homey.app/u/BufferOverflow)\
**Post date:** [April 24, 2021, 8:53am UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636/3 "2021-04-24T08:53:53Z")

</div>

> [@TedTolboom](#):
>
> Adds the capability without the need to remove and add the device again.

Ok, thanks! Will read up on that. I guess i would just check if it exist first.

---

<div class="post-metadata">

**Author:** ![TedTolboom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tedtolboom/32/12081_2.png) [@TedTolboom](https://community.homey.app/u/TedTolboom)\
**Post date:** [April 24, 2021, 9:53am UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636/4 "2021-04-24T09:53:32Z")

</div>

> [@BufferOverflow](#):
>
> I guess i would just check if it exist first

That wouldn’t be fun right 😉

---

<div class="post-metadata">

**Author:** ![Edwin\_D](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/edwin_d/32/136417_2.png) [@Edwin\_D](https://community.homey.app/u/Edwin_D)\
**Post date:** [April 24, 2021, 9:54am UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636/5 "2021-04-24T09:54:34Z")

</div>

Yes, you need to check for it’s existence first, because adding/removing capabilities is not a cheap operation. But it is very useful for upgrades indeed. Wish Athom would do the same with the tado test version 😄

---

<div class="post-metadata">

**Author:** ![Joolee](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/joolee/32/3064_2.png) [@Joolee](https://community.homey.app/u/Joolee)\
**Post date:** [February 9, 2022, 11:29am UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636/6 "2022-02-09T11:29:55Z")

</div>

Just include some lines like this in the onInit part of device.js:

```auto
		if (!this.getCapabilities().includes("measure_uptime")) {
			this.addCapability("measure_uptime");
			this.setCapabilityOptions("unit_uptime", {
				"preventInsights": true,
				"preventTag ": true
			});
		}

```

The setCapabilityOption call is optional of course

---

<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:** [February 9, 2022, 12:04pm UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636/7 "2022-02-09T12:04:59Z")

</div>

> [@Joolee](#):
>
> `if (!this.getCapabilities().includes("measure_uptime")) { … }`

Or:

```auto
if (! this.hasCapability('measure_uptime')) { … }

```

---

<div class="post-metadata">

**Author:** ![Joolee](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/joolee/32/3064_2.png) [@Joolee](https://community.homey.app/u/Joolee)\
**Post date:** [February 9, 2022, 12:11pm UTC](https://community.homey.app/t/versioning-whan-adding-a-new-capability/46636/8 "2022-02-09T12:11:37Z")

</div>

> [@robertklep](#):
>
> `hasCapability`

Thanks! That should be faster.
