diff --git a/internal/hass/hass.go b/internal/hass/hass.go index e19389af..bea80370 100644 --- a/internal/hass/hass.go +++ b/internal/hass/hass.go @@ -4,6 +4,11 @@ import ( "bytes" "encoding/json" "fmt" + "net/http" + "os" + "path" + "sync" + "github.com/AlexxIT/go2rtc/internal/api" "github.com/AlexxIT/go2rtc/internal/app" "github.com/AlexxIT/go2rtc/internal/roborock" @@ -11,10 +16,6 @@ import ( "github.com/AlexxIT/go2rtc/pkg/core" "github.com/AlexxIT/go2rtc/pkg/hass" "github.com/rs/zerolog" - "net/http" - "os" - "path" - "sync" ) func Init() { @@ -36,6 +37,21 @@ func Init() { api.HandleFunc("/streams", apiOK) api.HandleFunc("/stream/", apiStream) + streams.HandleFunc("hass", func(url string) (core.Producer, error) { + // check entity by name + if url2 := entities[url[5:]]; url2 != "" { + return streams.GetProducer(url2) + } + + // support hass://supervisor?entity_id=camera.driveway_doorbell + client, err := hass.NewClient(url) + if err != nil { + return nil, err + } + + return client, nil + }) + // load static entries from Hass config if err := importConfig(conf.Mod.Config); err != nil { log.Debug().Msgf("[hass] can't import config: %s", err) @@ -63,21 +79,6 @@ func Init() { api.ResponseStreams(w, items) }) - streams.HandleFunc("hass", func(url string) (core.Producer, error) { - // check entity by name - if url2 := entities[url[5:]]; url2 != "" { - return streams.GetProducer(url2) - } - - // support hass://supervisor?entity_id=camera.driveway_doorbell - client, err := hass.NewClient(url) - if err != nil { - return nil, err - } - - return client, nil - }) - // for Addon listen on hassio interface, so WebUI feature will work if conf.API.Listen == "127.0.0.1:1984" { if addr := HassioAddr(); addr != "" {