location was stomping on others in the gauges for ESP, so just hacked in the topic...
authorjweigele <jweigele@local>
Mon, 15 Jan 2024 06:07:43 +0000 (22:07 -0800)
committerjweigele <jweigele@local>
Mon, 15 Jan 2024 06:07:43 +0000 (22:07 -0800)
lights/main.go

index 3b2ef07ade2cd838a2dc70ecbf75789a6b8e64d0..a895e50a095239c58774bedc6f6abb1df5ab513d 100644 (file)
@@ -191,6 +191,10 @@ type IRGBFriendly interface {
        getFriendlyName() string
 }
 
+type ITopicRelay interface {
+       getTopic() string
+}
+
 type IRelayData interface {
        getRelayData(red, green, blue float64) (map[string]interface{}, string)
 }
@@ -589,6 +593,10 @@ func (relay *ESPRelay) getRoutingKey() string {
        return relay.Topic
 }
 
+func (relay *ESPRelay) getTopic() string {
+       return relay.Topic
+}
+
 // RGBPico defs
 type PicoRelayData struct {
        parent *RGBPico
@@ -787,12 +795,18 @@ func (manager *RGBManager) updateMetrics() {
                time.Sleep(time.Duration(1) * time.Second)
                for _, relay := range manager.relays {
                        // did we get a friendly name capable relay?
-                       curZig, ok := relay.(IRGBFriendly)
+                       curZig, zigOk := relay.(IRGBFriendly)
                        // this should give us a fairly unique value, location is friendlyname where enabled, otherwise location is location
-                       if ok {
+                       if zigOk {
                                lightGauge.With(prometheus.Labels{"location": curZig.getFriendlyName()}).Set(curZig.getMetricValue())
                        } else {
-                               lightGauge.With(prometheus.Labels{"location": relay.getLocation()}).Set(relay.getMetricValue())
+                               curTopic, topicOk := relay.(ITopicRelay)
+                               if topicOk {
+                                       lightGauge.With(prometheus.Labels{"location": curTopic.getTopic()}).Set(relay.getMetricValue())
+                               } else {
+
+                                       lightGauge.With(prometheus.Labels{"location": relay.getLocation()}).Set(relay.getMetricValue())
+                               }
                        }
                }
        }