Ecovacs in Home Assistant Part8 - Create a complete Home Assistant integration for the Ecovacs X5 Pro(skills)
I'll analyze these https://github.com/mslycn/vacumm-ecovacs-deebot/blob/main/references/api.md#cloudctl-clean to understand the Ecovacs API.I've created a complete Home Assistant integration for the Ecovacs X5 Pro.
Repository Structure
custom_components/ecovacs_x5pro/
├── __init__.py (setup integration)
├── manifest.json (metadata)
├── const.py (constants)
├── config_flow.py (configuration UI)
├── api.py (API client)
└── vacuum.py (vacuum entity)
api.py GetWorkState

api.py
the actual API returns:
JSON response from api.py: {'msg': 'OK', 'code': 0, 'data': {'code': 0, 'msg': 'success', 'data': {'ctl': {'data': {'ret': 'ok', 'cleanSt': 'h', 'chargeSt': 'charging', 'stationSt': 'dust'}}}}}
JSON response from api.py: {'msg': 'OK', 'code': 0, 'data': {'code': 0, 'msg': 'success', 'data': {'ctl': {'data': {'ret': 'ok', 'cleanSt': 'wash', 'chargeSt': 'charging', 'stationSt': 'i'}}}}}
JSON response from api.py: {'msg': 'OK', 'code': 0, 'data': {'code': 0, 'msg': 'success', 'data': {'ctl': {'data': {'ret': 'ok', 'cleanSt': 'washpause', 'chargeSt': 'charging', 'stationSt': 'i'}}}} Your API response has one extra level of nesting that wasn't accounted for.So you need to go one level deeper:
ctl = (
data.get("data", {}) # First data level
.get("data", {}) # ← SECOND data level (was missing!)
.get("ctl", {}) # Then ctl
.get("data", {}) # Then final data
)
vacuum.py
Comments
Be the first to post a comment