chore: reformat, normalize imports

This commit is contained in:
2025-08-01 20:44:38 -05:00
parent 9b8ef545a6
commit 8fe6bc0cff
31 changed files with 94 additions and 145 deletions

View File

@@ -7,14 +7,13 @@ import (
"time"
// "example/entities" // Optional import generated entities
ga "github.com/Xevion/go-ha"
ha "github.com/Xevion/go-ha"
)
//go:generate go run github.com/Xevion/go-ha/cmd/generate
func main() {
app, err := ga.NewApp(ga.NewAppRequest{
app, err := ha.NewApp(ha.NewAppRequest{
URL: "http://192.168.86.67:8123", // Replace with your Home Assistant URL
HAAuthToken: os.Getenv("HA_AUTH_TOKEN"),
HomeZoneEntityId: "zone.home",
@@ -32,25 +31,25 @@ func main() {
slog.Info("Application shutdown complete")
}()
pantryDoor := ga.
pantryDoor := ha.
NewEntityListener().
EntityIds(entities.BinarySensor.PantryDoor). // Use generated entity constant
Call(pantryLights).
Build()
_11pmSched := ga.
_11pmSched := ha.
NewDailySchedule().
Call(lightsOut).
At("23:00").
Build()
_30minsBeforeSunrise := ga.
_30minsBeforeSunrise := ha.
NewDailySchedule().
Call(sunriseSched).
Sunrise("-30m").
Build()
zwaveEventListener := ga.
zwaveEventListener := ha.
NewEventListener().
EventTypes("zwave_js_value_notification").
Call(onEvent).
@@ -63,7 +62,7 @@ func main() {
app.Start()
}
func pantryLights(service *ga.Service, state ga.State, sensor ga.EntityData) {
func pantryLights(service *ha.Service, state ha.State, sensor ha.EntityData) {
l := "light.pantry"
// l := entities.Light.Pantry // Or use generated entity constant
if sensor.ToState == "on" {
@@ -73,18 +72,18 @@ func pantryLights(service *ga.Service, state ga.State, sensor ga.EntityData) {
}
}
func onEvent(service *ga.Service, state ga.State, data ga.EventData) {
func onEvent(service *ha.Service, state ha.State, data ha.EventData) {
// Since the structure of the event changes depending
// on the event type, you can Unmarshal the raw json
// into a Go type. If a type for your event doesn't
// exist, you can write it yourself! PR's welcome to
// the eventTypes.go file :)
ev := ga.EventZWaveJSValueNotification{}
ev := ha.EventZWaveJSValueNotification{}
json.Unmarshal(data.RawEventJSON, &ev)
slog.Info("On event invoked", "event", ev)
}
func lightsOut(service *ga.Service, state ga.State) {
func lightsOut(service *ha.Service, state ha.State) {
// always turn off outside lights
service.Light.TurnOff(entities.Light.OutsideLights)
s, err := state.Get(entities.BinarySensor.LivingRoomMotion)
@@ -99,7 +98,7 @@ func lightsOut(service *ga.Service, state ga.State) {
}
}
func sunriseSched(service *ga.Service, state ga.State) {
func sunriseSched(service *ha.Service, state ha.State) {
service.Light.TurnOn(entities.Light.LivingRoomLamps)
service.Light.TurnOff(entities.Light.ChristmasLights)
}