joshuar / go-hass-agent

A Home Assistant, native app for desktop/laptop devices.
MIT License
135 stars 11 forks source link

BUG: D-Bus custom commands not working #252

Open joshuar opened 2 weeks ago

joshuar commented 2 weeks ago
          Hi @joshuar,

Thanks for resolving the issue so quickly. I've reviewed the changes made to the code and I see that the topic has changed when publishing a command to D-Bus. I'm trying to send a notification from HAss, but I'm unable to do so—I get the following error:

WARN Error dispatching D-Bus command. linux.controller=mqtt controller=dbus_command bus=session destination=org.freedesktop.Notifications path=/org/freedesktop/Notifications method=org.freedesktop.Notifications.Notify error="SessionBus: call could not retrieve object (No such method 'Notify' in interface 'org.freedesktop.Notifications' at object path '/org/freedesktop/Notifications' (signature 'sdsssava{sv}d'))"

And this is the JSON message I'm publishing in the gohassagent/<my-computer-name>/dbuscommand topic:

{
  "bus": "session",
  "path": "/org/freedesktop/Notifications",
  "method": "org.freedesktop.Notifications.Notify",
  "destination": "org.freedesktop.Notifications",
  "args": [
    "my-app-name",
    0,
    "my-icon",
    "summary",
    "body",
    [],
    {},
    5000
  ],
  "use_session_path": false
}

I think it might be that I'm not correctly typing the parameters for the Notify method. It works fine from a D-Bus explorer on my system.

Is it due to my incompetence, or could there be an issue mapping JSON values to Go's native types?

Thanks a lot, and sorry if I went off-topic too much.

Originally posted by @eleektro in https://github.com/joshuar/go-hass-agent/issues/249#issuecomment-2307081070

joshuar commented 2 weeks ago

Hey @eleektro,

Firstly thanks for trying out Go Hass Agent!

Now, I believe that the custom D-Bus command code is non-functional right now, some regressions have crept in. For example, the code currently won't pass any arguments you give to the D-Bus method you call. So I think that is likely, at least part of your problem.

I am working on fixing this, it likely won't make it into the next release (v10.1) but in a subsequent patch release (likely 10.1.1).

In the meantime, if you are looking to send notifications through Go Hass Agent, it should already support it OOTB. The agent exposes a notify.mobile_app_HOSTNAME (replace HOSTNAME with the short hostname of the device running the agent) service in Home Assistant you can use. For example in Developer Tools->Services in Home Assistant:

image

joshuar commented 1 week ago

Hey @eleektro, so I've spent some time looking into this issue. It took me down a rabbit hold of D-Bus internals and introspection, and I believe I've come out the other side with a fix to this issue. The next version of the agent will have the fix (v10.2).

For background, there is nothing wrong with your inputs or invocation. There was a regression in Go Hass Agent whereby specified arguments to a command were not being passed to D-Bus. Fixed. There was also a subtle issue in the way the arguments are converted from what is provided over MQTT to what is needed by D-Bus. Also fixed.

Thank you for reporting this issue, that was a fun one to look into :p

joshuar commented 12 hours ago

Hey @eleektro, I've just released v10.2 which contains a fix for your problem with the custom D-Bus command feature. For me, your example of sending a notification works, as as should any other D-Bus command you throw in there. Please try it out when you get a chance and report back!