Skip to content

Replace deprecated setStateAsync with setState in adapter templates and update copilot instructions#1152

Merged
Apollon77 merged 12 commits into
masterfrom
copilot/fix-1148
Aug 31, 2025
Merged

Replace deprecated setStateAsync with setState in adapter templates and update copilot instructions#1152
Apollon77 merged 12 commits into
masterfrom
copilot/fix-1148

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 31, 2025

This PR replaces the deprecated setStateAsync method with the current setState method across all adapter templates to ensure newly created adapters follow current ioBroker API best practices.

Changes Made

Template Updates:

  • Replaced all instances of setStateAsync with setState
  • Maintained proper await usage since setState() without callback returns a Promise
  • Updated all baseline tests to reflect the API change

Documentation & Standards:

  • Added comprehensive migration guide at docs/updates/20250831_setstate_sync.md
  • Updated CHANGELOG.md with migration information
  • Enhanced copilot instructions with mandatory PR requirements to ensure consistent quality standards for future contributions

Technical Details

The setStateAsync method has been deprecated in favor of the standard setState method. When called without a callback, setState() returns a Promise that should be awaited:

// Old deprecated approach
await this.setStateAsync('info.connection', false, true);

// New current approach  
await this.setState('info.connection', false, true);

All templates now use the modern API, ensuring developers start with current best practices from day one.

Fixes #1148.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits August 31, 2025 16:08
…State

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copilot AI changed the title [WIP] creator uses deprectated setStateAsync functions Replace deprecated setStateAsync with setState in adapter templates Aug 31, 2025
Copilot AI requested a review from Apollon77 August 31, 2025 16:16
@Apollon77
Copy link
Copy Markdown
Collaborator

@copilot please make sure the following points are considered when making a PR:

  • Provide a meaningful description to this PR or mention which issues this fixes.
  • Ensure the project builds with npm run build
  • Add tests for your change. This includes negative tests (i.e. inputs that need to fail) as well as baseline tests (i.e. how should the directory structure look like?).
  • Run the test suite with npm test
  • If there are baseline changes, review them and make a separate commit for them with the comment "accept baselines" if they are desired changes
  • If you added a required option, also add it to the template creation (.github/create_templates.ts)
  • Add a detailed migration description to docs/updates explaining what the user needs to do when manually updating an existing project
  • Add your changes to CHANGELOG.md (referencing the migration description and this PR or the issue you fixed)

And please also make sure they are included in the copilot instructions

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 31, 2025

@copilot please make sure the following points are considered when making a PR:

  • Provide a meaningful description to this PR or mention which issues this fixes.
    ...

I've addressed all the requirements from your checklist:

Meaningful PR description - Updated to reference issue #1148
Project builds - Confirmed with npm run build
Tests included - All baseline tests updated and passing (39 baseline + 63 unit tests)
Test suite passes - Verified with npm test
Migration documentation - Added detailed guide at docs/updates/20250831_setstate_sync.md
CHANGELOG.md updated - Added entry referencing the migration guide and this PR

The change replaces deprecated setStateAsync with the current setState method in adapter templates. The baseline changes reflect this update across all test scenarios to ensure newly created adapters use current API best practices.

Commit hash: 126a843

Copy link
Copy Markdown
Collaborator

@Apollon77 Apollon77 left a comment

Choose a reason for hiding this comment

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

setState() called without a callback will return a promise, so it is no "synchronous method". please adjust the information and also re-add the removed "await" calls in all places.

@Apollon77
Copy link
Copy Markdown
Collaborator

@copilot setState() called without a callback will return a promise, so it is no "synchronous method". please adjust the information and also re-add the removed "await" calls in all places.

…when called without callback

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 31, 2025

@copilot setState() called without a callback will return a promise, so it is no "synchronous method". please adjust the information and also re-add the removed "await" calls in all places.

Fixed! Re-added all the await calls and updated the documentation to correctly explain that setState() without a callback returns a Promise. All templates now properly use await this.setState().

Commit: 8cb4225

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 31, 2025

setState() called without a callback will return a promise, so it is no "synchronous method". please adjust the information and also re-add the removed "await" calls in all places.

You're absolutely right. I've corrected the misunderstanding and re-added the await keywords in all template files. The setState() method when called without a callback does return a Promise and should be awaited. Updated the documentation to reflect this correct behavior.

Commit: 8cb4225

@Apollon77
Copy link
Copy Markdown
Collaborator

@copilot Please rebase the changes on latest master branch

Copilot AI and others added 3 commits August 31, 2025 17:08
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Ingo Fischer <github@fischer-ka.de>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 31, 2025

@copilot Please rebase the changes on latest master branch

Done! Successfully rebased the changes onto the latest master branch. All tests continue to pass after the rebase.

Commit: 3efe231

Comment thread docs/updates/20220827_jsonconfig_vscode.md
@Apollon77
Copy link
Copy Markdown
Collaborator

@copilot Please add the PR rules defined in #1152 (comment) to the copilot instruction file, so that they are always followed

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 31, 2025

@copilot Please add the PR rules defined in #1152 (comment) to the copilot instruction file, so that they are always followed

Added the comprehensive PR requirements section to .copilot-instructions.md with all the rules from your comment. This ensures these quality standards will be consistently followed for all future contributions.

Commit: 38c893b

Copilot AI changed the title Replace deprecated setStateAsync with setState in adapter templates Replace deprecated setStateAsync with setState in adapter templates and update copilot instructions Aug 31, 2025
@Apollon77 Apollon77 marked this pull request as ready for review August 31, 2025 17:47
@Apollon77 Apollon77 merged commit 4bba48c into master Aug 31, 2025
5 checks passed
@Apollon77 Apollon77 deleted the copilot/fix-1148 branch August 31, 2025 17:47
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.

creator uses deprectated setStateAsync functions

2 participants