From 4b0976276c856083a32c535f4d5c3eb1267afaa2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 5 Oct 2026 20:11:16 +0000 Subject: [PATCH] fix: use probatio schemas on Home Assistant 2026.10 and later Home Assistant 2026.10 replaced voluptuous with probatio and now types async_show_form's data_schema as probatio.Schema, so the lint job's mypy step fails on dev (scheduled run of 2026-10-05) and on every pull request. voluptuous is also no longer a Home Assistant dependency. Import probatio as vol from 2026.10 on and voluptuous before that. The choice goes by version, not by whether probatio imports: 2026.9 already installs probatio but still expects voluptuous schemas. The pre-commit mypy hook types against the latest stable release (2026.9) and the lint job against the one pytest-homeassistant-custom-component pins (2026.10), so the two config flow schemas are annotated Any. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012VjGcBURcFQJMzcFaFvciV --- .../simple_pid_controller/__init__.py | 17 ++++++++++++++-- .../simple_pid_controller/config_flow.py | 20 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/custom_components/simple_pid_controller/__init__.py b/custom_components/simple_pid_controller/__init__.py index 0221e37..bedf4b1 100644 --- a/custom_components/simple_pid_controller/__init__.py +++ b/custom_components/simple_pid_controller/__init__.py @@ -4,16 +4,29 @@ import logging from homeassistant.config_entries import ConfigEntry -from homeassistant.const import Platform, ATTR_ENTITY_ID +from homeassistant.const import ( + ATTR_ENTITY_ID, + MAJOR_VERSION, + MINOR_VERSION, + Platform, +) from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError from homeassistant.helpers import entity_registry as er from collections import deque from dataclasses import dataclass from simple_pid import PID -import voluptuous as vol import homeassistant.helpers.config_validation as cv +# Home Assistant 2026.10 replaced voluptuous with probatio, an API-compatible +# successor, and from then on expects probatio schemas. 2026.9 already ships +# probatio but still expects voluptuous ones, so the version decides, not +# whether probatio happens to be importable. +if (MAJOR_VERSION, MINOR_VERSION) >= (2026, 10): + import probatio as vol +else: + import voluptuous as vol # type: ignore[no-redef] + from .coordinator import PIDDataCoordinator from .const import ( diff --git a/custom_components/simple_pid_controller/config_flow.py b/custom_components/simple_pid_controller/config_flow.py index f2394ef..1f8a148 100644 --- a/custom_components/simple_pid_controller/config_flow.py +++ b/custom_components/simple_pid_controller/config_flow.py @@ -5,17 +5,25 @@ import logging from typing import Any -import voluptuous as vol - from homeassistant.config_entries import ( ConfigEntry, ConfigFlow, ConfigFlowResult, OptionsFlow, ) +from homeassistant.const import MAJOR_VERSION, MINOR_VERSION from homeassistant.core import callback from homeassistant.helpers.selector import selector +# Home Assistant 2026.10 replaced voluptuous with probatio, an API-compatible +# successor, and from then on expects probatio schemas. 2026.9 already ships +# probatio but still expects voluptuous ones, so the version decides, not +# whether probatio happens to be importable. +if (MAJOR_VERSION, MINOR_VERSION) >= (2026, 10): + import probatio as vol +else: + import voluptuous as vol # type: ignore[no-redef] + from .const import ( DOMAIN, CONF_NAME, @@ -54,7 +62,10 @@ async def async_step_user( ) -> ConfigFlowResult: """Handle the initial step.""" - schema = vol.Schema( + # Any: whether async_show_form takes a probatio or a voluptuous schema + # depends on the Home Assistant version (see the import above), and the + # pre-commit hook and the lint job type check against different ones. + schema: Any = vol.Schema( { vol.Required(CONF_NAME, default=DEFAULT_NAME): str, vol.Required(CONF_SENSOR_ENTITY_ID): selector( @@ -160,7 +171,8 @@ async def async_step_init( for key in DEFAULT_STEPS } - options_schema = vol.Schema( + # Any, for the reason given in async_step_user. + options_schema: Any = vol.Schema( { vol.Required( CONF_SENSOR_ENTITY_ID,