From c7e02b373aa7d1775b1022bd6e408aec1f254558 Mon Sep 17 00:00:00 2001 From: blazSmehov Date: Thu, 27 Nov 2025 10:20:46 +0100 Subject: [PATCH] fix: missing beacons init in context, remove redundant properties of httpRes type --- cmd/location/main.go | 24 +++++++++++------------- internal/pkg/model/types.go | 6 ------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/cmd/location/main.go b/cmd/location/main.go index ad77f52..489c02a 100644 --- a/cmd/location/main.go +++ b/cmd/location/main.go @@ -24,7 +24,7 @@ func main() { BeaconMetricSize: 30, HASendInterval: 5, HASendChangesOnly: false, - RSSIEnforceThreshold: true, + RSSIEnforceThreshold: false, RSSIMinThreshold: 100, }, }, @@ -32,6 +32,9 @@ func main() { LatestList: model.LatestBeaconsList{ LatestList: make(map[string]model.Beacon), }, + Beacons: model.BeaconsList{ + Beacons: make(map[string]model.Beacon), + }, } cfg := config.Load() @@ -83,13 +86,10 @@ func getLikelyLocations(ctx *model.AppContext, writer *kafka.Writer) { ctx.Beacons.Lock.Unlock() for _, beacon := range beacons { - fmt.Printf("beacon: %+v", beacon) - // Shrinking the model because other properties have nothing to do with the location r := model.HTTPLocation{ Method: "Standard", Distance: 999, - Name: beacon.Name, ID: beacon.ID, Location: "", LastSeen: 999, @@ -188,30 +188,28 @@ func assignBeaconToList(adv model.BeaconAdvertisement, ctx *model.AppContext) { now := time.Now().Unix() if !ok { - // handle removing from the list somewhere else, probably at the point where this is being used which is nowhere in the original code ctx.LatestList.Lock.Lock() ctx.LatestList.LatestList[id] = model.Beacon{ID: id, BeaconType: adv.BeaconType, LastSeen: now, IncomingJSON: adv, BeaconLocation: adv.Hostname, Distance: getBeaconDistance(adv)} ctx.LatestList.Lock.Unlock() return } - fmt.Println("Beacon exists: ", id) - + fmt.Println("RSSI: ", adv.RSSI) if ctx.Settings.Settings.RSSIEnforceThreshold && (int64(adv.RSSI) < ctx.Settings.Settings.RSSIMinThreshold) { return } ctx.Beacons.Lock.Lock() - beacon := ctx.Beacons.Beacons[id] + beacon, ok := ctx.Beacons.Beacons[id] + if !ok { + beacon = model.Beacon{ + ID: id, + } + } ctx.Beacons.Lock.Unlock() beacon.IncomingJSON = adv beacon.LastSeen = now - beacon.BeaconType = adv.BeaconType - beacon.HSButtonCounter = adv.HSButtonCounter - beacon.HSBattery = adv.HSBatteryLevel - beacon.HSRandomNonce = adv.HSRandomNonce - beacon.HSButtonMode = adv.HSButtonMode if beacon.BeaconMetrics == nil { beacon.BeaconMetrics = make([]model.BeaconMetric, 0, ctx.Settings.Settings.BeaconMetricSize) diff --git a/internal/pkg/model/types.go b/internal/pkg/model/types.go index 803f7d0..5ce5569 100644 --- a/internal/pkg/model/types.go +++ b/internal/pkg/model/types.go @@ -78,13 +78,7 @@ type HTTPLocation struct { Method string `json:"method"` PreviousConfidentLocation string `json:"previous_confident_location"` Distance float64 `json:"distance"` - Name string `json:"name"` - BeaconName string `json:"beacon_name"` ID string `json:"id"` - BeaconType string `json:"beacon_type"` - HSBattery int64 `json:"hs_battery"` - HSButtonMode string `json:"hs_button_mode"` - HSButtonCounter int64 `json:"hs_button_counter"` Location string `json:"location"` LastSeen int64 `json:"last_seen"` }