Coder Social home page Coder Social logo

Comments (9)

alexylem avatar alexylem commented on May 28, 2024

@Oliv4945 you are right there is a bug, and not a small one 😄

I noticed that in the browser (with GET parameters) it's not working:

http://192.168.1.20:8080/?order=bonjour&mute=false&verbose=false
# will be mute and verbose

Need to fix this.

However, Jarvis-UI sends true or false in the parameters and it works. I think this is because the data is sent with POST and in the python code evaluates that boolean with the parenthesis (with POST it is apparently not a string but a real boolean):

jarvis.mute_mode = ("mute" in data) and (data ["mute"])
jarvis.verbose = ("verbose" in data) and (data ["verbose"])

As a workaround for your App, can you make the requests with POST ? If not, is "true" and "false" as values for GET ok for you?

from jarvis-api.

Oliv4945 avatar Oliv4945 commented on May 28, 2024

think this is because the data is sent with POST and in the python code evaluates that boolean with the parenthesis (with POST it is apparently not a string but a real boolean):

With a GET request you can only send strings. With POST request, Python parse data as a JSON object, so a boolean:
{"key": "testkey", "mute": true, "verbose":false}

As a workaround for your App, can you make the requests with POST

Already published here, I am not sending "mute" if not required.
By the way I already use a POST request but I was sending a string instead of a Boolean :$

from jarvis-api.

alexylem avatar alexylem commented on May 28, 2024

Okay. I will hardcode a check if string and not equal "false".

from jarvis-api.

Oliv4945 avatar Oliv4945 commented on May 28, 2024

So a way to go might be (not tested)

mute = data.get("mute", False)
if isinstance(mute, str)
    if mute.lower() == 'true':
        mute = True
    else:
        mute = False
jarvis.mute_mode = mute

from jarvis-api.

alexylem avatar alexylem commented on May 28, 2024

I did more or less the same (saw your message after commit):

if "mute" in data:
        mute=data["mute"]
        jarvis.mute_mode=mute if isinstance(mute, bool) else (mute != "false")

from jarvis-api.

Oliv4945 avatar Oliv4945 commented on May 28, 2024

Ok, you should put lower() in case somebody send the string False

if "mute" in data:
        mute=data["mute"]
        jarvis.mute_mode=mute if isinstance(mute, bool) else (mute.lower() != "false")

Just by curiosity, why don't you put mute == 'true' instead ?

from jarvis-api.

alexylem avatar alexylem commented on May 28, 2024

@Oliv4945 yes I could but the API docs says "true", and I always prefer to keep the code as simple as possible. But I could change here no big deal if it's easier for you.
Now why != false and not == true I think it's more of a philosophical question 😄
Maybe coding influence where everything that is not really "false" is true.

from jarvis-api.

Oliv4945 avatar Oliv4945 commented on May 28, 2024

@Oliv4945 yes I could but the API docs says "true", and I always prefer to keep the code as simple as possible. But I could change here no big deal if it's easier for you.

It does not change anything for me but be prepared to have an issue one day or another, always take the place of a fool and see what can go wrong :p

Maybe coding influence where everything that is not really "false" is true.

Ok, funny thing because for me what is not explicitly true is false :-)

from jarvis-api.

alexylem avatar alexylem commented on May 28, 2024

You won 😄

from jarvis-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.