Skip to content

Commit

Permalink
feat(device): ✨ add an agent version sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Apr 24, 2024
1 parent 33d4108 commit 92be2e1
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/agent/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// for this device.
func runWorkers(ctx context.Context, trk SensorTracker, reg sensor.Registry) {
workerFuncs := sensorWorkers()
workerFuncs = append(workerFuncs, device.ExternalIPUpdater)
workerFuncs = append(workerFuncs, device.ExternalIPUpdater, device.VersionUpdater)

var wg sync.WaitGroup
var outCh []<-chan sensor.Details
Expand Down
66 changes: 66 additions & 0 deletions internal/device/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2024 Joshua Rich <[email protected]>
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

package device

import (
"context"

"github.com/joshuar/go-hass-agent/internal/hass/sensor"
"github.com/joshuar/go-hass-agent/internal/hass/sensor/types"
"github.com/joshuar/go-hass-agent/internal/preferences"
)

type version string

func (v *version) Name() string {
return "Go Hass Agent Version"
}

func (v *version) ID() string {
return "agent_version"
}

func (v *version) Icon() string {
return "mdi:face-agent"
}

func (v *version) SensorType() types.SensorClass {
return types.Sensor
}

func (v *version) DeviceClass() types.DeviceClass {
return 0
}

func (v *version) StateClass() types.StateClass {
return 0
}

func (v *version) State() any {
return preferences.AppVersion
}

func (v *version) Units() string {
return ""
}

func (v *version) Category() string {
return "diagnostic"
}

func (v *version) Attributes() any {
return nil
}

func VersionUpdater(_ context.Context) chan sensor.Details {
sensorCh := make(chan sensor.Details)
v := new(version)
go func() {
defer close(sensorCh)
sensorCh <- v
}()
return sensorCh
}

0 comments on commit 92be2e1

Please sign in to comment.