diff --git a/bridge.go b/bridge.go index 8d06eb8..783c634 100644 --- a/bridge.go +++ b/bridge.go @@ -466,7 +466,10 @@ wait: if BRIDGE_DEBUG { log.Printf("received value %q (expected %q) for %s", updatedVal, expVal, key) } - if updatedVal == expVal { + if updatedVal == expVal || + // updatedVal is float64 coz that's how Z2M JSON values are, but expVal may not be + mapping.ExposesEntry.Type == "numeric" && cmpFloat64Numeric(updatedVal, expVal) { + updated = true break wait } @@ -485,6 +488,17 @@ wait: return updated, err } +// Compare float64 f to numeric value n +// Both parameters are marked as `any`. f will be type-asserted to float64, +// whereas n will be converted to float64 before doing the comparison. +func cmpFloat64Numeric(f, n any) bool { + if ff, ok := f.(float64); ok { + nn, ok := valToFloat64(n) + return ff == nn && ok + } + return false +} + // Publish to the MQTT broker for the specific device func (br *Bridge) PublishState(dev *Device, payload map[string]any) error { topic := MQTT_TOPIC_PREFIX + dev.FriendlyName + "/set"