This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Home Assistant integration for Volvo On Call CN (China version), which connects to Volvo vehicles and exposes their data and controls as Home Assistant entities. The integration uses the Chinese version of Volvo's API to fetch vehicle data and send commands.
- Home Assistant Integration: Custom integration using the standard Home Assistant integration structure
- API Implementation:
- Uses gRPC to communicate with Volvo's backend services via auto-generated proto files
- Core API layer in
volvooncall_cn.pyimplements vehicle data retrieval and commands - Authentication and REST API calls handled in
volvooncall_base.py
- Data Management:
- Follows the Home Assistant
DataUpdateCoordinatorpattern for efficient polling - Entity definitions in platform-specific files (sensor.py, binary_sensor.py, etc.)
- Configuration flow implemented in
config_flow.py
- Follows the Home Assistant
-
Authentication & API:
VehicleBaseAPIclass: Handles authentication, token management, and REST API callsVehicleAPIclass: Extends base API with gRPC communication for vehicle dataVehicleclass: Represents a vehicle with properties and methods for data and controls
-
Proto Files & gRPC:
- Proto files in
/proto/define the service interfaces for Volvo's gRPC API - Generated Python modules in
/proto/contain stubs and message classes - Key services: exterior, health, fuel, invocation, odometer, location, etc.
- Proto files in
-
Home Assistant Integration:
VolvoCoordinator: Central data coordinator that fetches and caches vehicle data- Entity platforms: Expose vehicle data as Home Assistant entities (sensors, switches, etc.)
metaMapin__init__.py: Defines entity metadata for all exposed vehicle properties
-
Configuration:
config_flow.py: Implements the config flow for adding the integration via UI- Supports username/password authentication with scan interval configuration
# Clone repository
git clone https://github.com/idreamshen/hass-volvooncall-cn.git
# Install required Python packages
pip install grpcio>=1.67.1 grpcio-tools>=1.67.1
# Install for development in Home Assistant
# Copy to config/custom_components/ directory of your Home Assistant installationIf you need to update proto files or regenerate Python code:
# From the proto directory
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. *.proto- Make changes to the code
- Test within a Home Assistant development environment
- Verify with actual Volvo vehicles if possible
- Add entity metadata to
metaMapin__init__.py - Add property to
Vehicleclass involvooncall_cn.py - Update the appropriate platform file (e.g.,
sensor.py,binary_sensor.py) - Add data parsing in the corresponding
_parse_*method inVehicleclass
- Add method to
Vehicleclass involvooncall_cn.py - Add corresponding API method in
VehicleAPIclass - Expose via appropriate entity (button, switch, etc.)
- Enable debug logging for the component in Home Assistant configuration:
logger:
default: info
logs:
custom_components.volvooncall_cn: debugTesting is primarily done manually through Home Assistant. No automated testing framework exists.
- Install via HACS as a custom repository:
- URL: https://github.com/idreamshen/hass-volvooncall-cn
- Category: Integration
- Add integration through Home Assistant UI
- Configure with Volvo account credentials (phone number and password)
The integration supports a wide range of vehicle data and controls, including:
- Vehicle lock status and control
- Door, window, sunroof, tailgate status
- Engine status and remote start/stop
- Fuel level and consumption
- Odometer reading
- Vehicle position (with WGS84 coordinates)
- Honk and flash commands
- Various vehicle warnings (fluid levels, tire pressure, service warnings)
- the README.md of this repo should use zh_CN