From: jweigele Date: Mon, 15 Jan 2024 06:07:43 +0000 (-0800) Subject: location was stomping on others in the gauges for ESP, so just hacked in the topic... X-Git-Url: http://git.hexthepla.net/?a=commitdiff_plain;h=8586852eef56cd7058031dba65afda4e42fdc706;p=rabbit_go location was stomping on others in the gauges for ESP, so just hacked in the topic instead --- diff --git a/lights/main.go b/lights/main.go index 3b2ef07..a895e50 100644 --- a/lights/main.go +++ b/lights/main.go @@ -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()) + } } } }