Skip to content
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

[BUG] Broken bool tags #976

Closed
lewsut opened this issue Nov 20, 2023 · 7 comments
Closed

[BUG] Broken bool tags #976

lewsut opened this issue Nov 20, 2023 · 7 comments
Labels
bug Something isn't working fixed

Comments

@lewsut
Copy link

lewsut commented Nov 20, 2023

Describe the bug
Can no longer toggle bool tags by any means from the front end. What was working before no longer works. This was an imported project but I have added a few new bool tags to test. Strings and numbers seem to work as expected...

To Reproduce
Add a bool tag in Fuxa Server
Link a toggle button
Toggle
Nothing changes

Expected behavior
A bool to change from true to false or vice versa

Environment
Docker
FUXA version: 1.1.15-1356

@unocelli unocelli added the bug Something isn't working label Nov 21, 2023
@unocelli unocelli added the fixed label Nov 21, 2023
@unocelli
Copy link
Member

Hi, Thanks for the report

@lewsut
Copy link
Author

lewsut commented Nov 22, 2023

I have checked I'm running the latest "fixed" code, this issue is not fixed at my end... same issue. no longer works with 1 / 0

image

@lewsut
Copy link
Author

lewsut commented Nov 22, 2023

I guess the problem is 1 / 0 is getting changed to true / false and nothing is expecting that as I had worked on 1/0 at the front end

Not a lot of things can be set to "true" boolean denotation so a pipe set up to stop on 0 continues to turn or flow because I assume it sees boolean false as != 0. I'm not sure how you can implement both because at the moment they don't work well with each other , setting a toggle switch to be false / 1 or true / 0 causes issues.

I had a poke around with the code and only made it worse...

Some examples below, but ultimately using 1/0 doesn't work I guess the feedback to the front end is now incorrect

image

image

@lewsut
Copy link
Author

lewsut commented Nov 22, 2023

Using
https://github.com/frangoteam/FUXA/blob/be9ee1d09b904345b7a55029bbfc3f84a0840f4e/server/runtime/devices/fuxaserver/index.js

Is the last time it works well, granted you can put any number into a bool... but at least it works as expected.

Perhaps something like the below? I am not sure what you are trying to achieve?
``

   let val = parseFloat(value);
   if (Number.isNaN(val)) {
       // maybe boolean
       val = Number(value);
       // maybe string
       if (Number.isNaN(val)) {

           val = value.toLowerCase();

           if (val === "false") {
               val = 0;
           } else {
               val = 1;
           }


       }
   } else {
       val = parseFloat(val.toFixed(5));
   }

   return val;

   }

``

@unocelli
Copy link
Member

Hi, first of all, considering that you are using fuxa server tags you can simply use number instead of boolean and it is also clearer since conditions are practically always with number.
I can't confirm your issue. can you please send me a sample project?

@lewsut
Copy link
Author

lewsut commented Nov 24, 2023

I have emailed you an example.

If I were to just use numbers what would be the point of having Boolean available? As you know it has its uses.

@zz4code
Copy link

zz4code commented Jul 14, 2024

it shoud be:
... } else if (type === 'boolean') { if (typeof value === 'string') { // return value.toLowerCase() !== 'false'; return value.toLowerCase() !== 'false' && value.toLowerCase() !== '0'; } return Boolean(value); }

because, currentTagReadings.db restore boolean value as text: '1' and '0'

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
Projects
None yet
Development

No branches or pull requests

3 participants