Files
pilot/scripts/test_command.sh
Gilles Soulier 1640754df8 Add $hostname variable substitution in config
This commit adds support for automatic hostname substitution in configuration files.
Users can now use $hostname in device.name, device.identifiers, and mqtt.client_id
to automatically use the system's hostname.

Changes:
- Add hostname crate dependency (v0.4)
- Implement expand_variables() to replace $hostname with actual hostname
- Add get_hostname() helper function
- Update config.example.yaml to demonstrate $hostname usage
- Add test for hostname substitution
- Update config.yaml to use $hostname by default
- Add test_command.sh script for testing MQTT commands

This makes deployment easier across multiple machines without manual config changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-30 06:52:41 +01:00

45 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Script simple pour tester les commandes MQTT avec Pilot v2
# Usage: ./test_command.sh <action> <value>
# Exemple: ./test_command.sh screen OFF
MQTT_HOST="10.0.0.3"
MQTT_PORT="1883"
DEVICE="asus"
if [ $# -ne 2 ]; then
echo "Usage: $0 <action> <value>"
echo "Actions: shutdown, reboot, sleep, screen"
echo "Values: ON, OFF"
echo "Exemple: $0 screen OFF"
exit 1
fi
ACTION=$1
VALUE=$2
TOPIC="pilot/${DEVICE}/cmd/${ACTION}/set"
# Vérifier si mosquitto_pub est installé
if ! command -v mosquitto_pub &> /dev/null; then
echo "❌ mosquitto_pub n'est pas installé"
echo "Installer avec: sudo apt install mosquitto-clients"
exit 1
fi
echo "📡 Envoi commande MQTT:"
echo " Topic: $TOPIC"
echo " Message: $VALUE"
echo ""
mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -t "$TOPIC" -m "$VALUE"
if [ $? -eq 0 ]; then
echo "✅ Commande envoyée avec succès!"
echo ""
echo "Vérifiez les logs de Pilot pour voir le résultat:"
echo " En dry-run mode, la commande sera loggée mais pas exécutée"
else
echo "❌ Erreur lors de l'envoi de la commande"
exit 1
fi