From: jweigele Date: Wed, 14 Dec 2022 02:41:32 +0000 (-0800) Subject: Couple bugfixes X-Git-Url: http://git.hexthepla.net/?a=commitdiff_plain;h=65cb39fa339e524355d565f6669023d3cbd85773;p=rabbit_go Couple bugfixes * stairway_pico was added twice in reprocess, fixed * Being unable to process action as a map (which sometimes happens in zigbee) resulted in a panic in reprocess from time to time, just printed and continued for now, though more changes might be needed elsewhere * Very large gaping hole in the pico relayData code - it basically just set the RGB values then turned around and set them all to 0 (lol!). So uhh, I added back in the } else { part of that block and now it seems fine. --- diff --git a/lights/main.go b/lights/main.go index 9c2e499..3f0e95f 100644 --- a/lights/main.go +++ b/lights/main.go @@ -449,6 +449,7 @@ func (relayData PicoRelayData) getRelayData(red, green, blue float64) (map[strin actionMap["red"] = red actionMap["green"] = green actionMap["blue"] = blue + } else { actionMap["red"] = 0.0 actionMap["green"] = 0.0 actionMap["blue"] = 0.0 diff --git a/reprocess/main.go b/reprocess/main.go index 8a36cc0..077031c 100644 --- a/reprocess/main.go +++ b/reprocess/main.go @@ -147,6 +147,7 @@ func newpowerdevice(friendlyName, powerName string, queryNeeded bool) *powerdevi func handleTemp(obj map[string]interface{}) { logger.V(1).Info("Temperature received", "obj", obj) + // these should both probably be checked for existence and type but oh well celsius := obj["celsius"].(float64) location := obj["location"].(string) now := time.Now().UTC() @@ -165,42 +166,46 @@ func handleDIY(obj map[string]interface{}, sendChannel chan helper.RabbitSend) { _, isAction := obj["action"] if isAction { // this should also already be decoded for us - data := obj["action"].(map[string]interface{}) - var senseType string + data, castSuccess := obj["action"].(map[string]interface{}) + if castSuccess { + var senseType string - _, isTemp := data["celsius"] - if isTemp { - senseType = "temperature" - } else { - _, hasType := data["type"] - if hasType { - senseType = data["type"].(string) + _, isTemp := data["celsius"] + if isTemp { + senseType = "temperature" } else { - logger.Info("Did not find any sense type, just returning") - return + _, hasType := data["type"] + if hasType { + senseType = data["type"].(string) + } else { + logger.Info("Did not find any sense type, just returning") + return + } + } + // should have the senseType setup correctly now, if we're still here + dataMap := make(map[string]interface{}, 0) + + if senseType == "temperature" { + // these should all exist properly + dataMap["fahrenheit"] = data["celsius"].(float64)*9/5 + 32 + dataMap["celsius"] = data["celsius"].(float64) + dataMap["location"] = data["location"].(string) + logger.V(2).Info("Sending reprocessed temperature") + // hardcoded temp routingKey for this type of measurement + sendThis := helper.RabbitSend{Data: dataMap, RoutingKey: "temp", IncludeDate: true} + sendChannel <- sendThis + } else if senseType == "motion" { + dataMap["motion_detected"] = data["state"].(bool) + // copied from above, but it might change later so shrug + dataMap["location"] = data["location"].(string) + logger.V(2).Info("Sending reprocessed motion") + sendThis := helper.RabbitSend{Data: dataMap, RoutingKey: "motion", IncludeDate: true} + sendChannel <- sendThis + } else { + logger.Info("Sense type not detected, ignoring") } - } - // should have the senseType setup correctly now, if we're still here - dataMap := make(map[string]interface{}, 0) - - if senseType == "temperature" { - // these should all exist properly - dataMap["fahrenheit"] = data["celsius"].(float64)*9/5 + 32 - dataMap["celsius"] = data["celsius"].(float64) - dataMap["location"] = data["location"].(string) - logger.V(2).Info("Sending reprocessed temperature") - // hardcoded temp routingKey for this type of measurement - sendThis := helper.RabbitSend{Data: dataMap, RoutingKey: "temp", IncludeDate: true} - sendChannel <- sendThis - } else if senseType == "motion" { - dataMap["motion_detected"] = data["state"].(bool) - // copied from above, but it might change later so shrug - dataMap["location"] = data["location"].(string) - logger.V(2).Info("Sending reprocessed motion") - sendThis := helper.RabbitSend{Data: dataMap, RoutingKey: "motion", IncludeDate: true} - sendChannel <- sendThis } else { - logger.Info("Sense type not detected, ignoring") + logger.Error(nil, "Unable to cast action key to map ignoring this delivery", "action", obj["action"]) } } else { @@ -389,7 +394,6 @@ func main() { // DIY devices devices = append(devices, newdiydevice("office_pico")) devices = append(devices, newdiydevice("stairway_pico")) - devices = append(devices, newdiydevice("stairway_pico")) devices = append(devices, newdiydevice("downstairs_stairway_pico")) devices = append(devices, newdiydevice("upstairs_pico")) devices = append(devices, newdiydevice("data_closet_pico"))