Skip to content

Commit

Permalink
Promising snapcast, but needs lots of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
claes committed Dec 9, 2024
1 parent abb082a commit c959a92
Show file tree
Hide file tree
Showing 9 changed files with 478 additions and 5 deletions.
21 changes: 21 additions & 0 deletions cmd/regelverk-tmp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
internal "github.com/claes/regelverk/internal"
)

func main() {

config, debug, dryRun := internal.ParseConfig()

loops := []internal.ControlLoop{
&internal.SnapcastLoop{},
}

bridgeWrappers := []internal.BridgeWrapper{
&internal.SnapcastBridgeWrapper{},
&internal.PulseaudioBridgeWrapper{},
}

internal.StartRegelverk(config, loops, &bridgeWrappers, dryRun, debug)
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

buildInputs = [pkgs.libcec pkgs.libcec_platform];

vendorHash = "sha256-BdzFcBx5Se0acPCwhMol2EGCD3AxCuv/gI+thUKCoaI=";
vendorHash = "sha256-Ucs+T6gdaVUAh5LjvnckjnlO9ekCC9ZQ8Tbqr1LHiAM=";
};
});

Expand Down
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/claes/cec v0.0.0-20240820185959-6db0712de894
github.com/claes/cec-mqtt v0.0.0-20241117210133-9685c24250c0
github.com/claes/mpd-mqtt v0.0.0-20241117211350-5c216a578a24
github.com/claes/pulseaudio-mqtt v0.0.0-20241117205947-6a36f61c1560
github.com/claes/pulseaudio-mqtt v0.0.0-20241207101230-d8f01a653ffc
github.com/claes/rotel-mqtt v0.0.0-20241117210930-508800a2173f
github.com/claes/routeros-mqtt v0.0.0-20241120202123-a86f39417801
github.com/claes/samsung-mqtt v0.0.0-20241117210402-2bf065d544e3
Expand All @@ -19,12 +19,15 @@ require (
)

require (
github.com/ConnorsApps/snapcast-go v0.2.0 // indirect
github.com/claes/snapcast-mqtt v0.0.0-20241204191410-562224f67682 // indirect
github.com/fhs/gompd/v2 v2.3.0 // indirect
github.com/go-routeros/routeros/v3 v3.0.0 // indirect
github.com/jfreymuth/pulse v0.1.1 // indirect
github.com/qmuntal/stateless v1.7.1 // indirect
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/time v0.5.0 // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/ConnorsApps/snapcast-go v0.2.0 h1:KBESELR+5aq+yfofh3JKeDdnT8JWHQTrXr23owzjU1o=
github.com/ConnorsApps/snapcast-go v0.2.0/go.mod h1:/UP8u37AdEwdmfZjtbbr76Wzorq7z/fEjpQWy0IVTtk=
github.com/bendahl/uinput v1.7.0 h1:nA4fm8Wu8UYNOPykIZm66nkWEyvxzfmJ8YC02PM40jg=
github.com/bendahl/uinput v1.7.0/go.mod h1:Np7w3DINc9wB83p12fTAM3DPPhFnAKP0WTXRqCQJ6Z8=
github.com/claes/cec v0.0.0-20240820185959-6db0712de894 h1:cZOiacVo+F8/VV+dEfqzNoqzbZVWiPbEDZ6rCKPK9uo=
Expand All @@ -14,6 +16,8 @@ github.com/claes/pulseaudio-mqtt v0.0.0-20241117140819-d43e31611f50 h1:xmtP03YiF
github.com/claes/pulseaudio-mqtt v0.0.0-20241117140819-d43e31611f50/go.mod h1:NbLAajteKoKa/m1YqSaJj/X6RCMUADqW2SovdFemRJA=
github.com/claes/pulseaudio-mqtt v0.0.0-20241117205947-6a36f61c1560 h1:yEQ16G4a762kAuBqsggoOMY0ARgY6dhNefLmOF0tvxw=
github.com/claes/pulseaudio-mqtt v0.0.0-20241117205947-6a36f61c1560/go.mod h1:NbLAajteKoKa/m1YqSaJj/X6RCMUADqW2SovdFemRJA=
github.com/claes/pulseaudio-mqtt v0.0.0-20241207101230-d8f01a653ffc h1:vL2+JfHmQMutbstu/GaXr5epmPbYw5mX11aLGEeDP0A=
github.com/claes/pulseaudio-mqtt v0.0.0-20241207101230-d8f01a653ffc/go.mod h1:NbLAajteKoKa/m1YqSaJj/X6RCMUADqW2SovdFemRJA=
github.com/claes/rotel-mqtt v0.0.0-20240606131203-59f7974c7ca3 h1:I+xs3PivUxXv2yYCYt6CsjRTju/tMz49Pd+PTMA/fS0=
github.com/claes/rotel-mqtt v0.0.0-20240606131203-59f7974c7ca3/go.mod h1:DXNpasrX+83LQrnnPGJmTIOexwA9XkeyU22atNDevD4=
github.com/claes/rotel-mqtt v0.0.0-20241117210930-508800a2173f h1:GAyguJRdXwm6/ruS6B+DiYMDHU1DJo/1lpT2yg5IK7E=
Expand All @@ -26,6 +30,8 @@ github.com/claes/samsung-mqtt v0.0.0-20241117142225-c52df5c2aa93 h1:u3L4jMhjmFrR
github.com/claes/samsung-mqtt v0.0.0-20241117142225-c52df5c2aa93/go.mod h1:0rHVPioCmrVMl9tOe2jVXGr6a8myw4jw0ijXlZjwKbQ=
github.com/claes/samsung-mqtt v0.0.0-20241117210402-2bf065d544e3 h1:7VTrwjgqAT7xwOkgLo9xqUn41b2rHsiSO7xglHeEqx4=
github.com/claes/samsung-mqtt v0.0.0-20241117210402-2bf065d544e3/go.mod h1:0rHVPioCmrVMl9tOe2jVXGr6a8myw4jw0ijXlZjwKbQ=
github.com/claes/snapcast-mqtt v0.0.0-20241204191410-562224f67682 h1:n9dYEqsHoeAhNbeH1YnV6349KYuwa/6BXiRm8pWRn4c=
github.com/claes/snapcast-mqtt v0.0.0-20241204191410-562224f67682/go.mod h1:a1wlHTrQhBN+mNV9zpQBd2/fgJU3SST0mTaP1Vs3Rmk=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o=
Expand All @@ -50,9 +56,17 @@ github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUY
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
29 changes: 29 additions & 0 deletions internal/bridge-snapcast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package regelverk

import (
"log/slog"

snapcastmqtt "github.com/claes/snapcast-mqtt/lib"
mqtt "github.com/eclipse/paho.mqtt.golang"
)

type SnapcastBridgeWrapper struct {
bridge *snapcastmqtt.SnapcastMQTTBridge
}

func (l *SnapcastBridgeWrapper) InitializeBridge(mqttClient mqtt.Client, config Config) error {
var err error
snapConfig := snapcastmqtt.SnapClientConfig{SnapServerAddress: config.SnapcastServer}
l.bridge, err = snapcastmqtt.NewSnapcastMQTTBridge(snapConfig, mqttClient, config.MQTTTopicPrefix)
if err != nil {
slog.Error("Could not create snapcast bridge", "error", err)
return err
}
return nil
}

func (l *SnapcastBridgeWrapper) Run() error {
go l.bridge.MainLoop()
slog.Info("Snapcast bridge started")
return nil
}
2 changes: 2 additions & 0 deletions internal/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func ParseConfig() (Config, *bool, *bool) {
httpListenAddress := flag.String("httpListenAddress", ":8080", "HTTP listen address")
rotelSerialPort := flag.String("rotelSerialPort", "", "Rotel serial port")
samsungTVAddress := flag.String("samsungTVAddress", "", "Samsung TV address")
snapcastServer := flag.String("snapcastServer", "", "Snapcast server address")
pulseServer := flag.String("pulseServer", "", "Pulse server")
mpdServer := flag.String("mpdServer", "", "MPD server")
mpdPasswordFile := flag.String("mpdPasswordFile", "", "MPD password file")
Expand Down Expand Up @@ -51,6 +52,7 @@ func ParseConfig() (Config, *bool, *bool) {
WebAddress: *httpListenAddress,
RotelSerialPort: *rotelSerialPort,
SamsungTvAddress: *samsungTVAddress,
SnapcastServer: *snapcastServer,
MpdServer: *mpdServer,
MpdPasswordFile: *mpdPasswordFile,
RouterAddress: *routerAddress,
Expand Down
Loading

0 comments on commit c959a92

Please sign in to comment.