From 1eb1d59b14232ebd74c3d6b01e63be4c7cbebb80 Mon Sep 17 00:00:00 2001 From: Neil Enns Date: Fri, 12 Jun 2020 07:17:20 -0700 Subject: [PATCH] Include formattedPredictions in default MQTT message Fixes #181 --- CHANGELOG.md | 2 ++ src/MustacheFormatter.ts | 2 +- src/handlers/mqttManager/MqttManager.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9b1aa1..0d724e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- MQTT detection messages now include a friendly formatted version of the predictions, + for example: `"formattedPredictions": "dog (98%)"`. Resolves [issue 181](https://github.com/danecreekphotography/node-deepstackai-trigger/issues/181). - MQTT `online` and `offline` status messages are now sent when the service starts or fails to start. This, combined the LWT message, makes it easy to set up MQTT binary sensors in Home Assistant to track the status of the system and send notifications to people if the system goes down diff --git a/src/MustacheFormatter.ts b/src/MustacheFormatter.ts index 0ee0ed7..cd3f962 100644 --- a/src/MustacheFormatter.ts +++ b/src/MustacheFormatter.ts @@ -9,7 +9,7 @@ import path from "path"; import Trigger from "./Trigger"; import IDeepStackPrediction from "./types/IDeepStackPrediction"; -function formatPredictions(predictions: IDeepStackPrediction[]): string { +export function formatPredictions(predictions: IDeepStackPrediction[]): string { return predictions .map(prediction => { return `${prediction.label} (${(prediction.confidence * 100).toFixed(0)}%)`; diff --git a/src/handlers/mqttManager/MqttManager.ts b/src/handlers/mqttManager/MqttManager.ts index e624a84..12a2f1c 100644 --- a/src/handlers/mqttManager/MqttManager.ts +++ b/src/handlers/mqttManager/MqttManager.ts @@ -148,6 +148,7 @@ async function publishDetectionMessage( fileName, basename: path.basename(fileName), predictions, + formattedPredictions: mustacheFormatter.formatPredictions(predictions), state: "on", });