mirror of
https://github.com/cmur2/miflorad.git
synced 2024-12-22 02:54:24 +01:00
miflorad: add version
This commit is contained in:
parent
5be425040d
commit
5be4ac1a6c
3
Makefile
3
Makefile
@ -1,6 +1,7 @@
|
|||||||
.POSIX:
|
.POSIX:
|
||||||
|
|
||||||
MIFLORA_ADDR?=00:00:00:00:00:00
|
MIFLORA_ADDR?=00:00:00:00:00:00
|
||||||
|
MIFLORAD_VERSION?=master
|
||||||
|
|
||||||
RUN_COMMAND=miflorad
|
RUN_COMMAND=miflorad
|
||||||
RUN_OPTIONS=$(MIFLORA_ADDR)
|
RUN_OPTIONS=$(MIFLORA_ADDR)
|
||||||
@ -34,7 +35,7 @@ remote-run: clean
|
|||||||
|
|
||||||
.PHONY: cmd/munin-miflora/miflorad
|
.PHONY: cmd/munin-miflora/miflorad
|
||||||
cmd/munin-miflora/miflorad:
|
cmd/munin-miflora/miflorad:
|
||||||
cd cmd/miflorad && CGO_ENABLED=0 go build && cd ../..
|
cd cmd/miflorad && CGO_ENABLED=0 go build -ldflags "-X main.version=$(MIFLORAD_VERSION)" && cd ../..
|
||||||
|
|
||||||
.PHONY: cmd/munin-miflora/munin-miflora
|
.PHONY: cmd/munin-miflora/munin-miflora
|
||||||
cmd/munin-miflora/munin-miflora:
|
cmd/munin-miflora/munin-miflora:
|
||||||
|
@ -19,6 +19,9 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// program version, will be populated on build
|
||||||
|
var version string
|
||||||
|
|
||||||
var (
|
var (
|
||||||
scanTimeout = flag.Duration("scantimeout", 10*time.Second, "timeout after that a scan per peripheral will be aborted")
|
scanTimeout = flag.Duration("scantimeout", 10*time.Second, "timeout after that a scan per peripheral will be aborted")
|
||||||
interval = flag.Duration("interval", 25*time.Second, "metrics collection interval")
|
interval = flag.Duration("interval", 25*time.Second, "metrics collection interval")
|
||||||
@ -49,6 +52,14 @@ func checkTooShortInterval() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getVersion() string {
|
||||||
|
if version == "" {
|
||||||
|
return "dev"
|
||||||
|
} else {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func readData(peripheral *peripheral, client ble.Client) error {
|
func readData(peripheral *peripheral, client ble.Client) error {
|
||||||
// re-request meta data (for battery level) if last check more than 24 hours ago
|
// re-request meta data (for battery level) if last check more than 24 hours ago
|
||||||
// Source: https://github.com/open-homeautomation/miflora/blob/ffd95c3e616df8843cc8bff99c9b60765b124092/miflora/miflora_poller.py#L92
|
// Source: https://github.com/open-homeautomation/miflora/blob/ffd95c3e616df8843cc8bff99c9b60765b124092/miflora/miflora_poller.py#L92
|
||||||
@ -181,6 +192,8 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(os.Stderr, "miflorad version %s\n", getVersion())
|
||||||
|
|
||||||
device, err := dev.NewDevice("default")
|
device, err := dev.NewDevice("default")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Failed to open device, err: %s\n", err)
|
fmt.Fprintf(os.Stderr, "Failed to open device, err: %s\n", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user