$ show wills106/homeassistant-solax-modbus
This repository provides a Home Assistant custom component (solax_modbus) that integrates solar inverters from multiple brands (SolaX, Growatt, Sofar, Solis, SRNE, etc.) via Modbus TCP/serial/RTU. It exposes real-time sensor data, battery status, energy totals, and control entities (numbers, selects, switches, buttons, time) into Home Assistant. The component features a plugin architecture where each inverter brand has its own module defining entity descriptions, register maps, and inverter detection logic. It includes an energy dashboard virtual device that aggregates grid, solar, battery, and home consumption for the native Home Assistant Energy Dashboard. Advanced capabilities include remote power control (VPP modes), autorepeat loops, parallel master-slave support, and automatic bad-register quarantine. The codebase is well-tested with unit tests and CI/CD, but suffers from some duplication across plugins and hardcoded register maps.
The LLM identified 4 files worth highlighting for reuse:
Defines CoreModbusTransport and NativeModbusTransport as a clean abstraction layer over Home Assistant's built-in Modbus hub and the component's own async serial/tcp client. This allows seamless switching between Modbus backends without affecting the rest of the integration. The pattern is reusable for any HA integration that needs to support multiple communication backends.
Provides BinaryPayloadBuilder and BinaryPayloadDecoder factories that work across different versions of pymodbus. It handles API differences (e.g., swapped arguments, removed methods) and raises clear errors if the installed version is too old. This pattern is directly applicable to any Python library that needs to maintain backward compatibility across major versions.
Implements EnergyDashboardCoordinator and EnergyDashboardSensorMapping dataclass. The mapping defines how raw inverter sensors (grid power, solar power, battery power) are transformed into virtual sensors for the HA Energy Dashboard, with support for Riemann sum integration, invert, filter, and parallel mode corrections. This reusable pattern allows any plugin to define its own energy dashboard mappings without modifying core setup code.
A script that rewrites plugin import blocks to enforce consistent import conventions (e.g., forbid star imports, ensure imports from const module). It uses AST parsing to detect violations and automatically generates corrected import lines. This pattern is useful for any project that needs to enforce import style across a large codebase programmatically.