How jtechczech/mydlink-ha-integration works
This Home Assistant integration connects a Mydlink account and exposes supported DSP-series smart plugs as switch entities. The main flow is credential validation, account/device initialization, entity creation, then polling and WebSocket-backed state updates and control. The API excerpt supports token persistence/refresh, cloud device discovery, and WebSocket messaging; other capabilities are limited to those documented or visible in the sampled files.
Main entry points: api.py Mydlink API client · switch.py Plug switch entity · config_flow.py Credential flow · __init__.py Integration lifecycle
Components 10
Account setup
- Credential flow
plug/config_flow.py
HA integration
- Integration lifecycle
plug/__init__.py
Plug entities
- Switch platform
plug/switch.py - Plug switch entity
plug/switch.py
Mydlink access
- Mydlink API client
plug/api.py - WebSocket client
plug/api.py - Credential and device state
plug/api.py
Other components
- Account user
- Home Assistant
- Mydlink cloud API
Connections 17
- Account user → Credential flow: enters credentials
- Credential flow → Mydlink API client: validates login
- Mydlink API client → Mydlink cloud API: authenticates and discovers
- Mydlink API client → Credential and device state: loads and saves tokens
- Credential flow → Account user: shows setup result
- Home Assistant → Integration lifecycle: starts entry
- Integration lifecycle → Mydlink API client: initializes session
- Integration lifecycle → Switch platform: forwards platform setup
- Switch platform → Plug switch entity: creates plug entities
- Switch platform → Mydlink API client: requests periodic state
- Plug switch entity → Mydlink API client: requests initial state
- Plug switch entity → Mydlink API client: sets plug state
- Mydlink API client → WebSocket client: sends device messages
- WebSocket client → Mydlink cloud API: maintains device connection
- Mydlink cloud API → WebSocket client: delivers device updates
- WebSocket client → Mydlink API client: dispatches messages
- Mydlink API client → Plug switch entity: calls state callback