arrays in call_service on the java side dont get correctly translated in rundash.py
for some service calls it is needed to send a list to HA. for example the lightcolors (which are now comma seperated lists in the dashboard) but also for other services like remote. instead of using comma seperated lists for those cases we should use a more general way. or we end up with a list of lists that need to be translated.
porting an array in JS to a dict or list in python can be done like this: JSON.stringify(arr) on the JS side and then on the python side json.loads(json_string)
json is already in use in rundash, so i think it shouldnt be a big impact. the only thing i dont know is if all "normal" strings that we now move from the JS to python also need to be stringified. if not then the change will be small.
Yes, should be a much better solution! You may close my PR. Looking into the current call_service there are two parameters that the function extracts from the original json and didn't pass as "**args" to plugin.call_service: service and namespace.
service is also taken out of the widget yaml.
but i cannot close a PR. only you and Andrew can do that.
Hi,
Finally I had some time to look into this. The rundash receives the js args by calling aiohttp request.post() which returns a MultiDictProxy object. If we change the js part to use JSON.stringify then we could use request.json on rundash part, but this would break all the other widgets. I couldn't find a easy way to test if the rundash is receiving a multidictproxy or a json. A intermediate solution is to encode the especial json parameters in a especial key of the multidict. Rundash would look for a "json" key and knows that it should "unpack" the value of this key. Compability with the already existing widgets would be maintained. Is this acceptable?
at this moment i dont have much time to try that out, but it seems like a workable solution. the most important parts from the solution:
- no breaking changes
- it is more general, so it can be used for other stuff as well.
when i get the time i will take a closer look.
Hi,
Ok, the change is small and does not break other things. Please take a look when you have time.
Rene - the JSON support has been added into call_service - does this address your issue?
Hi,
If I may, it works somewhat but not fully. The patch was made to be minimally invasive and do not touch what was already working, for example, it didn't touch the text for the rgb_color or xy_color nor the regular expressions inside call_service() of rundash.py. Ideally, I think, this function should receive everything as a json, but this could break other widgets. The default ones shouldn't be a problem because they may be modified but the users custom_widgets would break too.
On Sat, Nov 10, 2018 at 6:10 PM Andrew Cockburn [email protected] wrote:
Rene - the JSON support has been added into call_service - does this address your issue?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/home-assistant/appdaemon/issues/334#issuecomment-437617740, or mute the thread https://github.com/notifications/unsubscribe-auth/AEjpGpEomM_wjVUNwsWeSvQR47jM3CdEks5utzKYgaJpZM4U37fb .
-- Christian Lyra PoP-PR/RNP