dennisschroeder / glome

A home automation lib that works with Home Assistant. Created in and for Gleam Lang.
MIT License
12 stars 1 forks source link

Migration to Gleam 1.0 #9

Open jluzny opened 3 months ago

jluzny commented 3 months ago

Hi @dennisschroeder

thanks a lot for this great HA library. I just discovered Gleam lang and am excited by it so far. I'm also a hobby developer of HA-related automation (I contributed a bit to gome-assistant and I am also writing my port of it using Zig lang). I selected your lib as the way to get familiar with Gleam lang. :)

In my fork, you can see 1st attempt to migrate this lib into the latest versions of both gleam and relevant modules:

As I'm really very new to gleam/erlang/otp, some of the changes have not been tested yet - kind of a naive/best guess attempt so far.

When trying to execute the following test:

pub fn gla_test() {
  let config =
    Configuration(
      host: "SOME_IP",
      port: 8123,
      access_token: AccessToken( "SOME_TOKEN",
      ),
    )

  homeassistant.connect(config, handle_connection)
}

fn handle_connection(ha: HomeAssistant) -> HomeAssistant {
  io.debug("Connecting to Home Assistant...")
  ha
}

I get this error:

{undef,
    [{gun,ws_send,
         [{connection,#Ref<0.461272038.4283170832.260722>,<0.146.0>},
          {text,
              <<"{\"type\":\"auth\",\"access_token\":\"SOME_TOKEN">>}],
         []},
     {nerf@websocket,ws_send,2,
         [{file,
              "/home/jiri/dev/ha/gla/glome/build/dev/erlang/nerf/_gleam_artefacts/nerf@websocket.erl"},
          {line,64}]},
     {glome@core@authentication,authenticate,2,
         [{file,
              "/home/jiri/dev/ha/gla/glome/build/dev/erlang/glome/_gleam_artefacts/glome@core@authentication.erl"},
          {line,75}]},
     {glome@homeassistant,'-connect/2-fun-1-',3,
         [{file,
              "/home/jiri/dev/ha/gla/glome/build/dev/erlang/glome/_gleam_artefacts/glome@homeassistant.erl"},
          {line,216}]}]}

Any idea why gun cannot send the message to HA?

Thanks!

jluzny commented 3 months ago

It was a problem on the Nerf module side, which is being ported to the new gleam version. Can connect now when using local clone of the PR repo: https://github.com/gdamjan/nerf/tree/fixes-new-gleam