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>
This commit is contained in:
2025-12-30 06:52:41 +01:00
parent c5381b7112
commit 1640754df8
6 changed files with 153 additions and 8 deletions

View File

@@ -1,7 +1,11 @@
# Codex created 2025-12-29_0224
# Configuration example for Pilot v2
# Special variables:
# $hostname - Will be replaced by the system hostname at runtime
device:
name: pilot-device
identifiers: ["pilot-device"]
name: $hostname # Use $hostname for automatic hostname, or a custom name like "my-pc"
identifiers: ["$hostname"]
mqtt:
host: "127.0.0.1"
@@ -10,7 +14,7 @@ mqtt:
password: ""
base_topic: "pilot"
discovery_prefix: "homeassistant"
client_id: "pilot-device"
client_id: "$hostname" # MQTT client ID - use $hostname or a custom ID
keepalive_s: 60
qos: 0
retain_states: true