Skip to content

Name the datapoint in the counter type error (#320) - #570

Merged
GermanBluefox merged 1 commit into
masterfrom
fix/counter-type-message
Oct 2, 2026
Merged

GermanBluefox merged 1 commit into
masterfrom
fix/counter-type-message

Conversation

@GermanBluefox

Copy link
Copy Markdown
Contributor

Fixes #320.

Counter must have type "number"! said nothing about which datapoint it meant. The reporter asked for the ID in 2023; a second user commented that they had been living with it for over a year without being able to find the misconfigured datapoint, and a third eventually located theirs by reading the raw object JSON for "counter": true.

Before / after

Counter must have type "number"!
Counter must have type "number", but "modbus.5.inputRegisters.30536_Quellentemperatur"
is stored as "String". Change the storage type of this datapoint to "Number",
or switch the counter option off.

The ID is what makes it searchable; the actual type and the two ways out are what make it actionable without guessing.

Logged once per datapoint, not once per value

The check sits in pushHistory, so the old message fired for every value of the misconfigured datapoint — the screenshot in the issue is a wall of the same line. Adding the ID without throttling would only have made that wall wider, so a counterTypeReported flag on the datapoint reports it once. The flag lives on the per-datapoint config, which objectChange rebuilds, so correcting the configuration lets it report again if it is still wrong.

Two siblings in the same path

No Connection to database appeared twice with the datapoint ID available right there and unused:

  • prepareTaskCheckTypeAndDbId() → No connection to the database, cannot store the value of "<id>"
  • #readIdIndexAndType() → No connection to the database, cannot look up "<id>"

Verification

The text is built by counterTypeMismatch() in src/lib/errors.ts rather than inline, so it is unit testable without importing main.ts — which pulls in @iobroker/adapter-core and exits the process when js-controller cannot be resolved (the constraint #567 established). Two cases added to test/testErrors.js, which the CI unit list already runs: that the ID, the current type, the target type and the alternative all appear and stay on one line, and that an unmapped storage type does not produce "undefined".

144 unit tests pass; check:ts and prettier --check are clean on the changed files. (prettier --check README.md reports findings already present on master, so the file is left as it is apart from the changelog line.)

🤖 Generated with Claude Code

`Counter must have type "number"!` said nothing about which datapoint it meant.
One reporter searched for the misconfigured one for over a year, and a second
confirmed the same. The message now carries the ID and the type the datapoint
actually has, and says what to change:

  Counter must have type "number", but "modbus.5.inputRegisters.30536_Quelle"
  is stored as "String". Change the storage type of this datapoint to "Number",
  or switch the counter option off.

It is also logged once per datapoint instead of once per value. The repetition
was half of the problem - the screenshot in the issue is a wall of the same
line - and adding the ID without throttling would only have made that wall
wider.

Two warnings in the same path had the same flaw and the ID right at hand:
`No Connection to database` in prepareTaskCheckTypeAndDbId() and in
#readIdIndexAndType() now say which datapoint could not be stored or looked up.

The text is built by counterTypeMismatch() in src/lib/errors.ts rather than
inline, so it can be unit tested without importing main.ts - which pulls in
@iobroker/adapter-core and exits when js-controller cannot be resolved. Covered
in test/testErrors.js, which the CI unit list already runs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@GermanBluefox
GermanBluefox merged commit 4fcc211 into master Oct 2, 2026
17 checks passed
@GermanBluefox
GermanBluefox deleted the fix/counter-type-message branch October 2, 2026 18:38
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.

Error Message

1 participant