-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructured to distinguish "bridge" and "proxy" code
- Loading branch information
1 parent
9c65399
commit 1db512f
Showing
15 changed files
with
559 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package bridge | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/home2mqtt/hass" | ||
) | ||
|
||
func AttachSensor[T any](runtime hass.IPubSubRuntime, stateTopic string, valueTemplate string, sensor hass.ISensor[T]) { | ||
go func() { | ||
for v := range sensor.Events() { | ||
runtime.Send(stateTopic, []byte(fmt.Sprint(v))) | ||
} | ||
}() | ||
} | ||
|
||
func AttachField[T any](runtime hass.IPubSubRuntime, stateTopic string, commandTopic string, field hass.IField[T]) { | ||
runtime.Receive(commandTopic, func(topic string, payload []byte) { | ||
field.SetValue(field.ParseValue(payload)) | ||
}) | ||
AttachSensor[T](runtime, stateTopic, "", field) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package proxy | ||
|
||
import "github.com/home2mqtt/hass" | ||
|
||
type baseActuator struct { | ||
client hass.IPubSubRuntime | ||
topic string | ||
} | ||
|
||
func (b *baseActuator) init(context hass.IPubSubRuntime, topic string) { | ||
b.topic = topic | ||
b.client = context | ||
} | ||
|
||
func (s *baseActuator) send(action string) { | ||
s.client.Send(s.topic, []byte(action)) | ||
} |
Oops, something went wrong.