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,