Abstraction Layer
The abstraction layer is an asyncio-based worker that manages device communication through MQTT.
Features
- Configuration Loading: Reads device configuration from
config/devices.yaml - MQTT Integration: Connects to MQTT broker for real-time device communication
- Async Design: Built with asyncio for efficient concurrent operations
- Message Subscription: Listens to
home/#topics for device events - Logging: Structured logging at INFO level
Running
Local Development
# Start the abstraction worker
poetry run python -m apps.abstraction.main
Docker Container
Build Image
docker build -t abstraction:dev -f apps/abstraction/Dockerfile .
Run Container
docker run --rm \
-v $(pwd)/config:/app/config:ro \
-e MQTT_BROKER=172.23.1.102 \
-e MQTT_PORT=1883 \
-e REDIS_HOST=172.23.1.116 \
-e REDIS_PORT=6379 \
-e REDIS_DB=8 \
abstraction:dev
Environment Variables
| Variable | Default | Description |
|---|---|---|
MQTT_BROKER |
172.16.2.16 |
MQTT broker hostname/IP |
MQTT_PORT |
1883 |
MQTT broker port |
REDIS_HOST |
localhost |
Redis server hostname/IP |
REDIS_PORT |
6379 |
Redis server port |
REDIS_DB |
0 |
Redis database number |
What the Worker Does
The worker will:
- Load configuration from
config/devices.yaml - Connect to MQTT broker (172.16.2.16:1883)
- Subscribe to topic
home/# - Log "Abstraction worker started" at INFO level
- Keep running and processing MQTT messages until interrupted
Configuration
The worker reads configuration from config/devices.yaml. Example structure:
mqtt:
broker: "172.16.2.16"
port: 1883
client_id: "home-automation-abstraction"
keepalive: 60
devices:
- id: "light_living_room"
type: "light"
name: "Living Room Light"
mqtt_topic: "home/living_room/light"
MQTT Broker
The worker connects to a real MQTT broker at:
- Host: 172.16.2.16
- Port: 1883
- Authentication: None required
Topics subscribed:
home/#- All home automation topics
Dependencies
- PyYAML: Configuration file parsing
- aiomqtt: Modern async MQTT client
- asyncio: Asynchronous I/O
Stopping
Press Ctrl+C to gracefully stop the worker.