mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
refactor: rename module to github.com/Xevion/go-ha
This commit is contained in:
42
README.md
42
README.md
@@ -1,20 +1,18 @@
|
||||
# Gome-Assistant
|
||||
# go-ha
|
||||
|
||||
Write strongly typed [Home Assistant](https://www.home-assistant.io/) automations in Go!
|
||||
|
||||
## Disclaimer
|
||||
|
||||
Gome-Assistant is a new library, and I'm opening it up early to get some user feedback on the API and help shape the direction. I plan for it to grow to cover all Home Assistant use cases, services, and event types. So it's possible that breaking changes will happen before v1.0.0!
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Installation
|
||||
|
||||
```
|
||||
go get github.com/Xevion/gome-assistant
|
||||
```bash
|
||||
go get github.com/Xevion/go-ha
|
||||
```
|
||||
|
||||
### Generate Entity Constants
|
||||
or in `go.mod`:
|
||||
|
||||
```go
|
||||
require github.com/Xevion/go-ha
|
||||
```
|
||||
|
||||
## Generate Entity Constants
|
||||
|
||||
You can generate type-safe constants for all your Home Assistant entities using `go generate`. This makes it easier to reference entities in your code.
|
||||
|
||||
@@ -37,7 +35,7 @@ exclude_domains: ["device_tracker", "person"]
|
||||
2. Add a `//go:generate` comment in your project:
|
||||
|
||||
```go
|
||||
//go:generate go run github.com/Xevion/gome-assistant/cmd/generate
|
||||
//go:generate go run github.com/Xevion/go-ha/cmd/generate
|
||||
```
|
||||
|
||||
Optionally use the `-config` flag to customize the file path of the config file.
|
||||
@@ -72,11 +70,11 @@ Check out [`example/example.go`](./example/example.go) for an example of the 3 t
|
||||
|
||||
### Run your code
|
||||
|
||||
Keeping with the simplicity that Go is famous for, you don't need a specific environment or docker container to run Gome-Assistant. You just write and run your code like any other Go binary. So once you build your code, you can run it however you like — using `screen` or `tmux`, a cron job, a linux service, or wrap it up in a docker container if you like!
|
||||
Keeping with the simplicity that Go is famous for, you don't need a specific environment or docker container to run go-ha. You just write and run your code like any other Go binary. So once you build your code, you can run it however you like — using `screen` or `tmux`, a cron job, a linux service, or wrap it up in a docker container if you like!
|
||||
|
||||
> _❗ No promises, but I may provide a Docker image with file watching to automatically restart gome-assistant, to make it easier to use gome-assistant on a fully managed Home Assistant installation._
|
||||
> _❗ No promises, but I may provide a Docker image with file watching to automatically restart go-ha, to make it easier to use go-ha on a fully managed Home Assistant installation._
|
||||
|
||||
## gome-assistant Concepts
|
||||
## go-ha Concepts
|
||||
|
||||
### Overview
|
||||
|
||||
@@ -87,13 +85,13 @@ The general flow is
|
||||
3. Start app
|
||||
|
||||
```go
|
||||
import ga "github.com/Xevion/gome-assistant"
|
||||
import ga "github.com/Xevion/go-ha"
|
||||
|
||||
// replace with IP and port of your Home Assistant installation
|
||||
app, err := ga.NewApp(ga.NewAppRequest{
|
||||
URL: "http://192.168.1.123:8123",
|
||||
HAAuthToken: os.Getenv("HA_AUTH_TOKEN"),
|
||||
HomeZoneEntityId: "zone.home",
|
||||
URL: "http://192.168.1.123:8123",
|
||||
HAAuthToken: os.Getenv("HA_AUTH_TOKEN"),
|
||||
HomeZoneEntityId: "zone.home",
|
||||
})
|
||||
|
||||
// create automations here (see next sections)
|
||||
@@ -107,7 +105,7 @@ app.RegisterIntervals(...)
|
||||
app.Start()
|
||||
```
|
||||
|
||||
A full reference is available on [pkg.go.dev](https://pkg.go.dev/github.com/Xevion/gome-assistant), but all you need to know to get started are the four types of automations in gome-assistant.
|
||||
A full reference is available on [pkg.go.dev](https://pkg.go.dev/github.com/Xevion/go-ha), but all you need to know to get started are the four types of automations in go-ha.
|
||||
|
||||
- [Daily Schedules](#daily-schedule)
|
||||
- [Entity Listeners](#entity-listener)
|
||||
@@ -226,7 +224,7 @@ func myCallback(service *ga.Service, state ga.State, data ga.EventData) {
|
||||
}
|
||||
```
|
||||
|
||||
> 💡 Check `eventTypes.go` for pre-defined event types, or create your own struct type for custom events and contribute them back to gome-assistant with a PR.
|
||||
> 💡 Check `eventTypes.go` for pre-defined event types, or create your own struct type for custom events and contribute them back to go-ha with a PR.
|
||||
|
||||
### Interval
|
||||
|
||||
|
||||
6
app.go
6
app.go
@@ -14,9 +14,9 @@ import (
|
||||
sunriseLib "github.com/nathan-osman/go-sunrise"
|
||||
|
||||
"github.com/Workiva/go-datastructures/queue"
|
||||
internal "github.com/Xevion/gome-assistant/internal"
|
||||
"github.com/Xevion/gome-assistant/internal/parse"
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
internal "github.com/Xevion/go-ha/internal"
|
||||
"github.com/Xevion/go-ha/internal/parse"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
var ErrInvalidArgs = errors.New("invalid arguments provided")
|
||||
|
||||
@@ -3,8 +3,8 @@ package gomeassistant
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
"github.com/Xevion/gome-assistant/internal/parse"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
"github.com/Xevion/go-ha/internal/parse"
|
||||
"github.com/golang-module/carbon"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
ga "github.com/Xevion/gome-assistant"
|
||||
ga "github.com/Xevion/go-ha"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
"github.com/golang-module/carbon"
|
||||
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
"github.com/Xevion/gome-assistant/internal/parse"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
"github.com/Xevion/go-ha/internal/parse"
|
||||
)
|
||||
|
||||
type EntityListener struct {
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
"github.com/golang-module/carbon"
|
||||
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
"github.com/Xevion/gome-assistant/internal/parse"
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
"github.com/Xevion/go-ha/internal/parse"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
type EventListener struct {
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
// "example/entities" // Optional import generated entities
|
||||
|
||||
ga "github.com/Xevion/gome-assistant"
|
||||
ga "github.com/Xevion/go-ha"
|
||||
)
|
||||
|
||||
//go:generate go run github.com/Xevion/gome-assistant/cmd/generate
|
||||
//go:generate go run github.com/Xevion/go-ha/cmd/generate
|
||||
|
||||
func main() {
|
||||
app, err := ga.NewApp(ga.NewAppRequest{
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
ga "github.com/Xevion/gome-assistant"
|
||||
ga "github.com/Xevion/go-ha"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
||||
module github.com/Xevion/gome-assistant
|
||||
module github.com/Xevion/go-ha
|
||||
|
||||
go 1.21
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
"github.com/Xevion/gome-assistant/types"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
"github.com/Xevion/go-ha/types"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
type HomeAssistant struct {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
"github.com/Xevion/gome-assistant/types"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
"github.com/Xevion/go-ha/types"
|
||||
)
|
||||
|
||||
type Notify struct {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
type Number struct {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
func BuildService[
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
)
|
||||
|
||||
var ErrInvalidToken = errors.New("invalid authentication token")
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
"github.com/Xevion/gome-assistant/internal/parse"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
"github.com/Xevion/go-ha/internal/parse"
|
||||
)
|
||||
|
||||
type IntervalCallback func(*Service, State)
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/Xevion/gome-assistant/internal"
|
||||
"github.com/Xevion/gome-assistant/internal/parse"
|
||||
"github.com/Xevion/go-ha/internal"
|
||||
"github.com/Xevion/go-ha/internal/parse"
|
||||
"github.com/golang-module/carbon"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gomeassistant
|
||||
|
||||
import (
|
||||
"github.com/Xevion/gome-assistant/internal/services"
|
||||
ws "github.com/Xevion/gome-assistant/internal/websocket"
|
||||
"github.com/Xevion/go-ha/internal/services"
|
||||
ws "github.com/Xevion/go-ha/internal/websocket"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
|
||||
Reference in New Issue
Block a user