Implemented better config system
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -10,9 +10,10 @@ type computer struct {
|
||||
macAddress string
|
||||
name string
|
||||
room string
|
||||
url string
|
||||
}
|
||||
|
||||
func NewComputer(macAddress string, name string, room string) *computer {
|
||||
func NewComputer(macAddress string, name string, room string, url string) *computer {
|
||||
c := &computer{macAddress: macAddress, name: name, room: room}
|
||||
|
||||
return c
|
||||
@@ -46,10 +47,7 @@ func (c *computer) Execute(execution google.Execution, updateState *google.Devic
|
||||
switch execution.Name {
|
||||
case google.CommandActivateScene:
|
||||
if !execution.ActivateScene.Deactivate {
|
||||
// @NOTE For now just call the webhook, that way we do not have to give this docker container network_mode: host
|
||||
// @TODO Add wake on lan support
|
||||
|
||||
http.Get("https://webhook.huizinga.dev/start-pc?token=7!$8bmjfZsT606Rmw5IrfIXhQWt6clTY")
|
||||
http.Get(c.url)
|
||||
}
|
||||
default:
|
||||
errCode = "actionNotAvailable"
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/kr/pretty"
|
||||
"google.golang.org/api/homegraph/v1"
|
||||
@@ -38,17 +37,22 @@ type Provider struct {
|
||||
manualDevices map[string]DeviceInterface
|
||||
}
|
||||
|
||||
func NewProvider(m *mqtt.MQTT) *Provider {
|
||||
credentials64, _ := os.LookupEnv("GOOGLE_CREDENTIALS")
|
||||
credentials, err := base64.StdEncoding.DecodeString(credentials64)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
type credentials []byte
|
||||
type Config struct {
|
||||
Credentials credentials `yaml:"credentials" envconfig:"GOOGLE_CREDENTIALS"`
|
||||
}
|
||||
|
||||
func (c *credentials) Decode(value string) error {
|
||||
b, err := base64.StdEncoding.DecodeString(value)
|
||||
*c = b
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func NewProvider(config Config, m *mqtt.MQTT) *Provider {
|
||||
provider := &Provider{userID: "Dreaded_X", devices: make(map[string]DeviceInterface), manualDevices: make(map[string]DeviceInterface)}
|
||||
|
||||
homegraphService, err := homegraph.NewService(context.Background(), option.WithCredentialsJSON(credentials))
|
||||
homegraphService, err := homegraph.NewService(context.Background(), option.WithCredentialsJSON(config.Credentials))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user