Support hass source without hass config #541
This commit is contained in:
+20
-19
@@ -4,6 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/internal/api"
|
"github.com/AlexxIT/go2rtc/internal/api"
|
||||||
"github.com/AlexxIT/go2rtc/internal/app"
|
"github.com/AlexxIT/go2rtc/internal/app"
|
||||||
"github.com/AlexxIT/go2rtc/internal/roborock"
|
"github.com/AlexxIT/go2rtc/internal/roborock"
|
||||||
@@ -11,10 +16,6 @@ import (
|
|||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/hass"
|
"github.com/AlexxIT/go2rtc/pkg/hass"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@@ -36,6 +37,21 @@ func Init() {
|
|||||||
api.HandleFunc("/streams", apiOK)
|
api.HandleFunc("/streams", apiOK)
|
||||||
api.HandleFunc("/stream/", apiStream)
|
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
|
// load static entries from Hass config
|
||||||
if err := importConfig(conf.Mod.Config); err != nil {
|
if err := importConfig(conf.Mod.Config); err != nil {
|
||||||
log.Debug().Msgf("[hass] can't import config: %s", err)
|
log.Debug().Msgf("[hass] can't import config: %s", err)
|
||||||
@@ -63,21 +79,6 @@ func Init() {
|
|||||||
api.ResponseStreams(w, items)
|
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
|
// for Addon listen on hassio interface, so WebUI feature will work
|
||||||
if conf.API.Listen == "127.0.0.1:1984" {
|
if conf.API.Listen == "127.0.0.1:1984" {
|
||||||
if addr := HassioAddr(); addr != "" {
|
if addr := HassioAddr(); addr != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user