- Implement tests for the Entity gRPC service, covering GetState and ListStates methods. - Create tests for the Light gRPC service, including TurnOn, TurnOff, Toggle, and ListLights methods. - Introduce mock service implementations to simulate behavior and validate interactions. - Add logging interceptor tests to ensure proper logging levels based on handler errors. - Develop application layer tests for entity and light functionalities, ensuring correct state management and error propagation.
discord-bot
discord-bot is a Discord slash-command service that talks to
ha-gateway over plaintext gRPC and exposes common Home Assistant actions in
Discord.
How It Works
Runtime flow:
- The bot starts a Discord session and registers slash commands.
- A user runs a slash command such as
/light listor/light on. - The Discord adapter routes the interaction to the app layer.
- The app layer calls
ha-gatewaythrough the secondary gRPC adapter. ha-gatewaytalks to Home Assistant and returns the result.- The bot formats the response back into a Discord message.
The service follows the same hexagonal structure as ha-gateway:
cmd/bot: process bootstrapinternal/adapters/primary/discord: slash command registration and handlersinternal/app: command orchestration and response formattinginternal/adapters/secondary/gateway: gRPC client forha-gatewayinternal/core/ports/driven: app-facing gateway interfaceinternal/config: env loadinginternal/telemetry: OpenTelemetry setup
Command Behavior
- List commands respond as regular channel messages.
- Action commands use deferred ephemeral replies, then send a follow-up result.
- Light autocomplete is backed by
ListLightsfromha-gateway. - Switch autocomplete support exists in code, but there is currently no switch action command that uses it.
Common Commands
List lights
/light list
Shows all discovered lights in a fixed-width block. Each line includes:
- state emoji:
🟢on,🔴off,⚠️unavailable or other state - friendly name
- raw state
- supported color modes
- kelvin range when available
Example output shape:
🟢 Desk Lamp on color_temp,xy 2000-6535K
🔴 Closet off hs,color_temp 2202-4000K
⚠️ Hall Group unavailable color_temp 2000-6535K hue-group
Turn on a light
/light on light:<entity> brightness:80 color_temp:3000
Options:
light: required, autocomplete enabledbrightness: optional,1-100color_temp: optional,2000-6535
The bot responds with a confirmation such as:
Turned on `Desk Lamp` (brightness 80%, 3000K).
Turn off a light
/light off light:<entity> transition:3
Options:
light: required, autocomplete enabledtransition: optional,0-30seconds
Toggle a light
/light toggle light:<entity>
Option:
light: required, autocomplete enabled
List switches
/switch list
Shows discovered switches in a fixed-width block with:
- state emoji
- friendly name
- raw state
- device class
Configuration
Environment variables:
DISCORD_TOKEN: required Discord bot tokenGUILD_ID: optional guild ID; if set, commands are registered to that guildHA_GATEWAY_ADDR: required gRPC address forha-gatewayOTEL_ENDPOINT: optional OTLP gRPC endpoint; empty disables telemetry
Example env file: .env.example
Local Run
Create an env file and fill in real values:
cp discord-bot/.env.example discord-bot/.env
Then run:
cd discord-bot
go run ./cmd/bot
Build
cd discord-bot
go build ./...
Docker
Build from the repo root:
docker build -f discord-bot/Dockerfile -t discord-bot:dev .
Current Limitations
- no switch on/off/toggle command is exposed yet
- the bot depends on
ha-gatewaybeing reachable and healthy - list formatting is optimized for monospace code blocks, not rich embeds
- authentication/authorization is whatever Discord and the internal network provide; the bot does not add another auth layer itself