Skip to content

_ChargingStatusData validation fails when no active charging session (empty dict from API) #20

@gitzone83

Description

@gitzone83

When no charging session is active, the ChargePoint API returns an empty dict {} for the charging status payload. This causes a Pydantic validation error because start_time and last_update_data_timestamp are required fields with no defaults in _ChargingStatusData.

Error:
2 validation errors for _ChargingStatusData
start_time
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
last_update_data_timestamp
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing

Specific error code

Failed setup, will retry: 2 validation errors for _ChargingStatusData start_time Field required [type=missing, input_value={}, input_type=dict] For further information visit                            
  https://errors.pydantic.dev/2.12/v/missing last_update_data_timestamp Field required [type=missing, input_value={}, input_type=dict] For further information visit                                       
  https://errors.pydantic.dev/2.12/v/missing - cintinue with T/S  

Environment:

  • Home Assistant: 2026.4.3 (Container installation)
  • Python: 3.14
  • ha-chargepoint: Tested on both v1.3.1 and v1.4.0-beta.1 - same error on both
  • python-chargepoint: (see pip show python-chargepoint)
  • Pydantic: 2.12+
  • Hardware: ChargePoint CPH50-NEMA14-50-L23, firmware 5.5.4.22

Steps to reproduce:

  1. Install ChargePoint integration via HACS
  2. Configure with valid ChargePoint account credentials
  3. Have charger in idle state - cable plugged in but not actively charging (status: "Available")
  4. Integration fails to set up with the above Pydantic validation error
  5. HA retries setup indefinitely, never succeeds

Notes:

  • The issue is not in the ha-chargepoint integration itself but in the upstream python-chargepoint library, specifically python_chargepoint/session.py
  • Observed on both ha-chargepoint v1.3.1 (stable) and v1.4.0-beta.1 - the bug is in the shared dependency
  • The integration works fine when a charging session is active (API returns populated fields)
  • All other fields in _ChargingStatusData have sensible defaults - only these two datetime fields are required

Workaround:

In python_chargepoint/session.py, make the two fields optional:

Before:

start_time: datetime
last_update_data_timestamp: datetime

After:

start_time: Optional[datetime] = None
last_update_data_timestamp: Optional[datetime] = None

And update the validator to handle None:

@field_validator("start_time", "last_update_data_timestamp", mode="before")
@classmethod 
def parse_ms_timestamp(cls, v: Optional[float]) -> Optional[datetime]:
  if v is None:
    return None
  return datetime.fromtimestamp(v / 1000, tz=timezone.utc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions