Skip to content

State value to set for "resol.0.0022110010.8721.000010221110010002220" has to be type "number" but received type "string" #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Grizzelbee opened this issue May 11, 2021 · 3 comments
Labels
bug Something isn't working Fixed Already fixed in current developent branch

Comments

@Grizzelbee
Copy link
Owner

Grizzelbee commented May 11, 2021

Would be much easier to detect whether it's a number by testing whether item.type is 'number' since this info is used to create the data point.

                        this.createOrExtendObject(resolId + actionPath + item.dpName, {
                            type: 'state',
                            common: {
                                name: item.dpName,
                                type: item.type,
                                min: item.min,
                                max: item.max,
                                states: item.states,
                                role: thisRole,
                                read: true,
                                write: true
                            },

grafik

@Grizzelbee Grizzelbee added the bug Something isn't working label May 11, 2021
@Grizzelbee Grizzelbee assigned Grizzelbee and unassigned Grizzelbee May 11, 2021
@SurfGargano
Copy link
Contributor

Definiert wird der Type im Setup File, also warum der Check ? Ich denke die Warnung kam wo anders her.

@Grizzelbee
Copy link
Owner Author

Grizzelbee commented May 12, 2021

Naja, der Fehler wird ja immer dann geworfen, wenn ein Datenpunkt mit Typ "number" definiert wurde und beim setState() ein String übergeben wird. JS konvertiert das durch die lose Typisierung zwar in aller Regel richtig, aber sauber ist das nicht. Deshalb meine Aussage: Am besten auf item.type==='number' des Zieldatenpunktes testen (und nicht ob der value zufällig wie eine Zahl aussieht) und dann den value für setState() mit einem Number.parseFloat(value)/.parseInt(value) korrekt konvertieren. Das ist dann sauber weil der geschriebene Value zur Erwartung des Datenpunktes passt. Sollte bei der Konvertierung des Values etwas schief gehen (exception) muss ggf. vorher noch weiter geprüft oder die Erwartungshaltung überdacht weden.

@SurfGargano
Copy link
Contributor

fixed in 0.3.1

@Grizzelbee Grizzelbee added the Fixed Already fixed in current developent branch label Sep 16, 2021
Grizzelbee added a commit that referenced this issue Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Already fixed in current developent branch
Projects
None yet
Development

No branches or pull requests

2 participants