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

dasher body value automatically converted to string from dictionary #3

Open
achelius opened this issue Aug 23, 2017 · 5 comments
Open

Comments

@achelius
Copy link

achelius commented Aug 23, 2017

even with base configuration, after a restart of the addon, the body entry of every button is changed from dictionary to str

with this url:
"url": "https://domain:8123/api/services/input_boolean/toggle",

from
"body": {"entity_id": "input_boolean.dash"}
to
"body": "{'entity_id': 'input_boolean.dash'}"

causing the error:

Invalid service data for input_boolean.toggle: expected a dictionary. Got "{'entity_id': 'input_boolean.dash'}"

the schema for body has body considered as str and this I think causes the error

"schema":
  {
    "buttons": [
      {
        ...
        "body": "str",
       ...
      }
    ]
}

I tried to search for a solution from the manual but i couldn't find one right away

@stickystyle
Copy link

I think you're correct about the schema. The docs state the following...

The options dict contains all available options and their default value. Set the default value to null if the value is required to be given by the user before the add-on can start. Only non-nested arrays and dictorys are supported.

https://home-assistant.io/developers/hassio/addon_config/

@achelius
Copy link
Author

As a simple workaround for the time being, I had to fork the dasher project and change the line 64 in the lib/dasher.js (https://github.com/achelius/dasher/blob/master/lib/dasher.js)

from:
body: options.body,
To:
body: (options.json && typeof(options.body)=="string")?JSON.parse(options.body.replace(new RegExp("\'","g"),"\"")):options.body,

to make sure that the value is correctly interpreted as json dictionary if it's a string and json option is true
Also replacing every single quotes with double quotes before parsing because homeassistant changes the double quotes to single quote if a variable is a string

I don't know how to fix the problem by only changing the config.json of the homeassistant addon but this is how I fixed it for now and it works for my use case

@james-fry
Copy link
Owner

Hi guys. thanks for the testing, and apologies for the delay in response - I was away "off the net" for a few days (it was nice !).
I saw that comment in the docs about non-nested arrays, and hence tried with str... which clearly is not working and I didn't spot it. :(

I'd prefer an approach to resolve this issue via change in hass.io config rather than in the dasher code. IMO its nicer to keep the dasher code 1:1 with the master so any changes can be merged easily.

@achelius
Copy link
Author

I tried that workaround mainly because I wasn't an expert on home assistant and simply forgot the fact that I could have used events instead, those are the best solution for my usecase
Events don't need the body in the request so the problem doesn't appear for me
I agree that it isn't the solution

@james-fry
Copy link
Owner

Right now the only way we can use hass.io add-on options is to change dasher code to use an alternative JSON structure. This is not a change I'm willing to do as I want to keep the dasher code per the master.
Therefore I will roll back the change I made to use option json.

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

No branches or pull requests

3 participants