Added debug mode for more verbose logging

Also had to rename the existing DEBUG consts to DEVMODE, so as to not
confuse the two. DEVMODE is meant for developers and cannot be enabled
on-the-fly, whereas debug mode is for users to check that the bridge is
working, MQTT messages are received etc.

Update logging is throttled to avoid spurious messages for uncoalesced
MQTT updates and motion sensors. On my network with 10 devices, an
update is logged every 1-2 minutes on average.
This commit is contained in:
Darell Tan
2023-08-03 21:32:14 +08:00
parent 54aa0795c3
commit 3cfc3f68b0
3 changed files with 49 additions and 16 deletions

7
z2m.go
View File

@@ -13,7 +13,8 @@ import (
"github.com/brutella/hap/service"
)
const Z2M_DEBUG = false
// show more messages for developers
const Z2M_DEVMODE = false
// exposed properties to ignore
var IgnoreProperties = map[string]bool{
@@ -47,7 +48,7 @@ func createAccessory(dev *Device) (*accessory.A, []*ExposeMapping, error) {
return nil, nil, ErrMalfomedDevice
}
if Z2M_DEBUG {
if Z2M_DEVMODE {
fmt.Printf("%s %s %d\n", dev.Definition.Model, dev.Definition.Vendor, dev.NetworkAddress)
for _, exp := range dev.Definition.Exposes {
ignored := ""
@@ -90,7 +91,7 @@ func createAccessory(dev *Device) (*accessory.A, []*ExposeMapping, error) {
panic(err)
}
if Z2M_DEBUG {
if Z2M_DEVMODE {
f := runtime.FuncForPC(reflect.ValueOf(createFunc).Pointer())
fmt.Printf("----- %s -----\n", f.Name())