savdagod / ha-addons

HA add-on repository
MIT License
4 stars 2 forks source link

Transform the addon into a simple Go server #4

Closed IngmarStein closed 1 week ago

IngmarStein commented 2 weeks ago

Instead of using shell scripts invoked by the webhooks binary, use the pixlet library and the Tidbyt API directly. This has multiple advantages:

savdagod commented 1 week ago

I think this is awesome (especially how annoying it was to build the image I made). The only caveat is until I learn how this works better (which I guess I have to now lol), I will need you to help me out if I add any features in the future. If you’re alright with that, I’ll accept this PR.

IngmarStein commented 1 week ago

Sure, no problem with that!

savdagod commented 1 week ago

@IngmarStein I downloaded this to test on my machine and none of the services are working. Reverted the changes, can you do a PR into the dev version of the addon so I can test in my dev environment? Or let me know if there’s something I’m missing.

IngmarStein commented 1 week ago

Let me take a look. I've tested this container by building and running it locally and sending it HTTP requests but probably made some wrong assumptions how these requests look like when coming from the integration. I'll set up a devcontainer setup following https://developers.home-assistant.io/docs/add-ons/testing/ to facilitate local testing. This might even allow us to remove the dev copy.

savdagod commented 1 week ago

I figured it out, the integration sends requests to http://url:port/hooks/tidbyt-push. We either need to remove the hooks portion in the integration url (http://url:port/tidbyt-push) or we can add /hooks to http.HandleFunc's in main.go. Your call.

IngmarStein commented 1 week ago

Excellent! Removing the /hooks part seems cleaner to me, wdyt?

savdagod commented 1 week ago

Yeah that works for me

savdagod commented 1 week ago

I tested the text service works fine but push and publish are not working. Gonna look into it to see what's up.

IngmarStein commented 1 week ago

I've posted #6 as a take two with an improved testing infrastructure and better logging.

It's a draft until I've verified push and publish.

savdagod commented 1 week ago

Push and Publish are not working because the integration is sending a string to starargs but it’s expecting an array. If I send it from my phone using the Shortcuts app with a blank array or omit starargs altogether it works, so I will update the integration to parse out the arguments into an array and send it that way.

IngmarStein commented 1 week ago

If you're open to changing the integration, how about passing a map instead? That is, instead of

["key=value", "key2=value2"]

it would be

{
  "key": "value",
  "key2": "value2"
}

That would remove the remaining string parsing on the server side.