|
| 1 | +# Replace deprecated setStateAsync with setState |
| 2 | + |
| 3 | +The `setStateAsync` method has been deprecated in favor of the `setState` method. Newly created adapters will now use the current recommended API. If you have an existing adapter using `setStateAsync`, you should update it to use `setState` instead. |
| 4 | + |
| 5 | +## What changed |
| 6 | + |
| 7 | +The adapter template generation was updated to use `await this.setState()` instead of `await this.setStateAsync()` for setting states. |
| 8 | + |
| 9 | +## Manual migration for existing adapters |
| 10 | + |
| 11 | +If you have an existing adapter that uses `setStateAsync`, you should replace all occurrences with the `setState` method: |
| 12 | + |
| 13 | +```diff |
| 14 | +// Before (deprecated) |
| 15 | +- await this.setStateAsync("testVariable", true); |
| 16 | +- await this.setStateAsync("testVariable", { val: true, ack: true }); |
| 17 | +- await this.setStateAsync("testVariable", { val: true, ack: true, expire: 30 }); |
| 18 | + |
| 19 | +// After (current) |
| 20 | ++ await this.setState("testVariable", true); |
| 21 | ++ await this.setState("testVariable", { val: true, ack: true }); |
| 22 | ++ await this.setState("testVariable", { val: true, ack: true, expire: 30 }); |
| 23 | +``` |
| 24 | + |
| 25 | +## Why this change |
| 26 | + |
| 27 | +The `setStateAsync` method was deprecated in favor of the simpler `setState` method: |
| 28 | +- `setState` when called without a callback returns a Promise and should be awaited |
| 29 | +- `setState` when called with a callback is synchronous |
| 30 | +- Using `setState` aligns with current ioBroker adapter development best practices |
| 31 | + |
| 32 | +## No functional changes |
| 33 | + |
| 34 | +This change does not affect the functionality of your adapter - both methods perform the same operation. The only difference is using the current recommended API instead of the deprecated one. |
0 commit comments