Skip to content

Commit

Permalink
Include formattedPredictions in default MQTT message
Browse files Browse the repository at this point in the history
Fixes #181
  • Loading branch information
neilenns committed Jun 12, 2020
1 parent 40cce9a commit 1eb1d59
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/MustacheFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}%)`;
Expand Down
1 change: 1 addition & 0 deletions src/handlers/mqttManager/MqttManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ async function publishDetectionMessage(
fileName,
basename: path.basename(fileName),
predictions,
formattedPredictions: mustacheFormatter.formatPredictions(predictions),
state: "on",
});

Expand Down

0 comments on commit 1eb1d59

Please sign in to comment.