diff --git a/homeassistant/components/alarm_control_panel/__init__.py b/homeassistant/components/alarm_control_panel/__init__.py index 9c53f2b7fd0b..45e1d63e0c2d 100644 --- a/homeassistant/components/alarm_control_panel/__init__.py +++ b/homeassistant/components/alarm_control_panel/__init__.py @@ -24,6 +24,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.config_validation import make_entity_service_schema from homeassistant.helpers.deprecation import ( + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -52,12 +53,6 @@ else: from homeassistant.backports.functools import cached_property -# As we import constants of the cost module here, we need to add the following -# functions to check for deprecated constants again -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - _LOGGER: Final = logging.getLogger(__name__) SCAN_INTERVAL: Final = timedelta(seconds=30) @@ -249,3 +244,13 @@ def state_attributes(self) -> dict[str, Any] | None: ATTR_CHANGED_BY: self.changed_by, ATTR_CODE_ARM_REQUIRED: self.code_arm_required, } + + +# As we import constants of the const module here, we need to add the following +# functions to check for deprecated constants again +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/alarm_control_panel/const.py b/homeassistant/components/alarm_control_panel/const.py index 90bbcba1314b..fe4be649e195 100644 --- a/homeassistant/components/alarm_control_panel/const.py +++ b/homeassistant/components/alarm_control_panel/const.py @@ -5,6 +5,7 @@ from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -60,10 +61,6 @@ class AlarmControlPanelEntityFeature(IntFlag): AlarmControlPanelEntityFeature.ARM_VACATION, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - CONDITION_TRIGGERED: Final = "is_triggered" CONDITION_DISARMED: Final = "is_disarmed" CONDITION_ARMED_HOME: Final = "is_armed_home" @@ -71,3 +68,10 @@ class AlarmControlPanelEntityFeature(IntFlag): CONDITION_ARMED_NIGHT: Final = "is_armed_night" CONDITION_ARMED_VACATION: Final = "is_armed_vacation" CONDITION_ARMED_CUSTOM_BYPASS: Final = "is_armed_custom_bypass" + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 4e6fa477ed2b..efad44b15ef3 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -58,6 +58,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.deprecation import ( DeprecatedConstant, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -147,10 +148,6 @@ def __call__(self, variables: Mapping[str, Any] | None = None) -> bool: TriggerInfo, "TriggerInfo", "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - @bind_hass def is_on(hass: HomeAssistant, entity_id: str) -> bool: @@ -1108,3 +1105,11 @@ def websocket_config( "config": automation.raw_config, }, ) + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index 3a32a1afb57c..061854894194 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -19,6 +19,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -218,10 +219,6 @@ class BinarySensorDeviceClass(StrEnum): BinarySensorDeviceClass.WINDOW, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - # mypy: disallow-any-generics @@ -303,3 +300,11 @@ def state(self) -> Literal["on", "off"] | None: if (is_on := self.is_on) is None: return None return STATE_ON if is_on else STATE_OFF + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index 7a56292f7bb7..ce75f064d476 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -54,6 +54,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -123,10 +124,6 @@ class CameraEntityFeature(IntFlag): CameraEntityFeature.STREAM, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - RTSP_PREFIXES = {"rtsp://", "rtsps://", "rtmp://"} DEFAULT_CONTENT_TYPE: Final = "image/jpeg" @@ -1082,3 +1079,11 @@ async def async_handle_record_service( duration=service_call.data[CONF_DURATION], lookback=service_call.data[CONF_LOOKBACK], ) + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/camera/const.py b/homeassistant/components/camera/const.py index da41c0b9fabc..09c4c7c1fb21 100644 --- a/homeassistant/components/camera/const.py +++ b/homeassistant/components/camera/const.py @@ -5,6 +5,7 @@ from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -47,6 +48,9 @@ class StreamType(StrEnum): _DEPRECATED_STREAM_TYPE_WEB_RTC = DeprecatedConstantEnum(StreamType.WEB_RTC, "2025.1") -# Both can be removed if no deprecated constant are in this module anymore +# These can be removed if no deprecated constant are in this module anymore __getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index 78cb92944cbf..c315765925f4 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -28,6 +28,7 @@ make_entity_service_schema, ) from homeassistant.helpers.deprecation import ( + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -141,12 +142,6 @@ ), ) -# As we import deprecated constants from the const module, we need to add these two functions -# otherwise this module will be logged for using deprecated constants and not the custom component -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals()) - # mypy: disallow-any-generics @@ -734,3 +729,13 @@ async def async_service_temperature_set( kwargs[value] = temp await entity.async_set_temperature(**kwargs) + + +# As we import deprecated constants from the const module, we need to add these two functions +# otherwise this module will be logged for using deprecated constants and not the custom component +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = ft.partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/climate/const.py b/homeassistant/components/climate/const.py index 615dc7d48dde..9c9153d9f632 100644 --- a/homeassistant/components/climate/const.py +++ b/homeassistant/components/climate/const.py @@ -5,6 +5,7 @@ from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -188,6 +189,9 @@ class ClimateEntityFeature(IntFlag): ClimateEntityFeature.AUX_HEAT, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore +# These can be removed if no deprecated constant are in this module anymore __getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index 3e438fb4ca13..945585de5229 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -34,6 +34,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -143,10 +144,6 @@ class CoverEntityFeature(IntFlag): CoverEntityFeature.SET_TILT_POSITION, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals()) - ATTR_CURRENT_POSITION = "current_position" ATTR_CURRENT_TILT_POSITION = "current_tilt_position" ATTR_POSITION = "position" @@ -493,3 +490,11 @@ def _get_toggle_function( if self._cover_is_last_toggle_direction_open: return fns["close"] return fns["open"] + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = ft.partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index b5ad4660cde2..adcc90cccbfe 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -6,6 +6,7 @@ from homeassistant.const import ATTR_GPS_ACCURACY, STATE_HOME # noqa: F401 from homeassistant.core import HomeAssistant from homeassistant.helpers.deprecation import ( + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -57,12 +58,6 @@ see, ) -# As we import deprecated constants from the const module, we need to add these two functions -# otherwise this module will be logged for using deprecated constants and not the custom component -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - @bind_hass def is_on(hass: HomeAssistant, entity_id: str) -> bool: @@ -83,3 +78,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await async_setup_legacy_integration(hass, config) return True + + +# As we import deprecated constants from the const module, we need to add these two functions +# otherwise this module will be logged for using deprecated constants and not the custom component +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/device_tracker/const.py b/homeassistant/components/device_tracker/const.py index 10c16e091070..67a90ab0f952 100644 --- a/homeassistant/components/device_tracker/const.py +++ b/homeassistant/components/device_tracker/const.py @@ -9,6 +9,7 @@ from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -44,10 +45,6 @@ class SourceType(StrEnum): SourceType.BLUETOOTH_LE, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - CONF_SCAN_INTERVAL: Final = "interval_seconds" SCAN_INTERVAL: Final = timedelta(seconds=12) @@ -71,3 +68,10 @@ class SourceType(StrEnum): ATTR_IP: Final = "ip" CONNECTED_DEVICE_REGISTERED: Final = "device_tracker_connected_device_registered" + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index dedaedfe6000..c35d828e3984 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -26,6 +26,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -76,10 +77,6 @@ class FanEntityFeature(IntFlag): FanEntityFeature.PRESET_MODE, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals()) - SERVICE_INCREASE_SPEED = "increase_speed" SERVICE_DECREASE_SPEED = "decrease_speed" SERVICE_OSCILLATE = "oscillate" @@ -471,3 +468,11 @@ def preset_modes(self) -> list[str] | None: if hasattr(self, "_attr_preset_modes"): return self._attr_preset_modes return None + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = ft.partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/humidifier/__init__.py b/homeassistant/components/humidifier/__init__.py index 0d8f2e295616..65a8cd9d1d05 100644 --- a/homeassistant/components/humidifier/__init__.py +++ b/homeassistant/components/humidifier/__init__.py @@ -24,6 +24,7 @@ PLATFORM_SCHEMA_BASE, ) from homeassistant.helpers.deprecation import ( + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -81,12 +82,6 @@ class HumidifierDeviceClass(StrEnum): # use the HumidifierDeviceClass enum instead. DEVICE_CLASSES = [cls.value for cls in HumidifierDeviceClass] -# As we import deprecated constants from the const module, we need to add these two functions -# otherwise this module will be logged for using deprecated constants and not the custom component -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - # mypy: disallow-any-generics @@ -293,3 +288,13 @@ def supported_features_compat(self) -> HumidifierEntityFeature: self._report_deprecated_supported_features_values(new_features) return new_features return features + + +# As we import deprecated constants from the const module, we need to add these two functions +# otherwise this module will be logged for using deprecated constants and not the custom component +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/humidifier/const.py b/homeassistant/components/humidifier/const.py index a1a219ddce76..66ac0fcf18d3 100644 --- a/homeassistant/components/humidifier/const.py +++ b/homeassistant/components/humidifier/const.py @@ -5,6 +5,7 @@ from homeassistant.helpers.deprecation import ( DeprecatedConstant, DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -66,6 +67,9 @@ class HumidifierEntityFeature(IntFlag): HumidifierEntityFeature.MODES, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore +# These can be removed if no deprecated constant are in this module anymore __getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/lock/__init__.py b/homeassistant/components/lock/__init__.py index a9370f8d0926..a4e7c4b7d1ad 100644 --- a/homeassistant/components/lock/__init__.py +++ b/homeassistant/components/lock/__init__.py @@ -33,6 +33,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -70,10 +71,6 @@ class LockEntityFeature(IntFlag): # Please use the LockEntityFeature enum instead. _DEPRECATED_SUPPORT_OPEN = DeprecatedConstantEnum(LockEntityFeature.OPEN, "2025.1") -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals()) - PROP_TO_ATTR = {"changed_by": ATTR_CHANGED_BY, "code_format": ATTR_CODE_FORMAT} # mypy: disallow-any-generics @@ -315,3 +312,11 @@ def _async_read_entity_options(self) -> None: return self._lock_option_default_code = "" + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = ft.partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/number/const.py b/homeassistant/components/number/const.py index 55d22c866489..a2d7c066af75 100644 --- a/homeassistant/components/number/const.py +++ b/homeassistant/components/number/const.py @@ -38,6 +38,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -70,10 +71,6 @@ class NumberMode(StrEnum): _DEPRECATED_MODE_BOX: Final = DeprecatedConstantEnum(NumberMode.BOX, "2025.1") _DEPRECATED_MODE_SLIDER: Final = DeprecatedConstantEnum(NumberMode.SLIDER, "2025.1") -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - class NumberDeviceClass(StrEnum): """Device class for numbers.""" @@ -481,3 +478,10 @@ class NumberDeviceClass(StrEnum): UNIT_CONVERTERS: dict[str, type[BaseUnitConverter]] = { NumberDeviceClass.TEMPERATURE: TemperatureConverter, } + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index 7e9ebfe12b9f..c5facb9785cc 100644 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -27,6 +27,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -92,10 +93,6 @@ class RemoteEntityFeature(IntFlag): ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals()) - REMOTE_SERVICE_ACTIVITY_SCHEMA = make_entity_service_schema( {vol.Optional(ATTR_ACTIVITY): cv.string} ) @@ -262,3 +259,11 @@ async def async_delete_command(self, **kwargs: Any) -> None: await self.hass.async_add_executor_job( ft.partial(self.delete_command, **kwargs) ) + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = ft.partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index d7c5cddc5db6..6498b92b03e9 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -59,6 +59,7 @@ PLATFORM_SCHEMA_BASE, ) from homeassistant.helpers.deprecation import ( + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -120,12 +121,6 @@ "SensorStateClass", ] -# As we import deprecated constants from the const module, we need to add these two functions -# otherwise this module will be logged for using deprecated constants and not the custom component -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - # mypy: disallow-any-generics @@ -955,3 +950,13 @@ def async_rounded_state(hass: HomeAssistant, entity_id: str, state: State) -> st value = f"{numerical_value:z.{precision}f}" return value + + +# As we import deprecated constants from the const module, we need to add these two functions +# otherwise this module will be logged for using deprecated constants and not the custom component +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/sensor/const.py b/homeassistant/components/sensor/const.py index d57a09981efb..b1cb120e3fee 100644 --- a/homeassistant/components/sensor/const.py +++ b/homeassistant/components/sensor/const.py @@ -38,6 +38,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -468,10 +469,6 @@ class SensorStateClass(StrEnum): ) STATE_CLASSES: Final[list[str]] = [cls.value for cls in SensorStateClass] -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] = { SensorDeviceClass.ATMOSPHERIC_PRESSURE: PressureConverter, SensorDeviceClass.CURRENT: ElectricCurrentConverter, @@ -631,3 +628,10 @@ class SensorStateClass(StrEnum): SensorDeviceClass.WEIGHT: {SensorStateClass.MEASUREMENT}, SensorDeviceClass.WIND_SPEED: {SensorStateClass.MEASUREMENT}, } + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/siren/__init__.py b/homeassistant/components/siren/__init__.py index 29ad238ac004..fb41d5f7b488 100644 --- a/homeassistant/components/siren/__init__.py +++ b/homeassistant/components/siren/__init__.py @@ -17,6 +17,7 @@ PLATFORM_SCHEMA_BASE, ) from homeassistant.helpers.deprecation import ( + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -53,12 +54,6 @@ vol.Optional(ATTR_VOLUME_LEVEL): cv.small_float, } -# As we import deprecated constants from the const module, we need to add these two functions -# otherwise this module will be logged for using deprecated constants and not the custom component -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - class SirenTurnOnServiceParameters(TypedDict, total=False): """Represent possible parameters to siren.turn_on service data dict type.""" @@ -218,3 +213,13 @@ def supported_features(self) -> SirenEntityFeature: self._report_deprecated_supported_features_values(new_features) return new_features return features + + +# As we import deprecated constants from the const module, we need to add these two functions +# otherwise this module will be logged for using deprecated constants and not the custom component +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/siren/const.py b/homeassistant/components/siren/const.py index 50c3af61c8dd..9e46d8dc997b 100644 --- a/homeassistant/components/siren/const.py +++ b/homeassistant/components/siren/const.py @@ -6,6 +6,7 @@ from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -47,6 +48,9 @@ class SirenEntityFeature(IntFlag): SirenEntityFeature.DURATION, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore +# These can be removed if no deprecated constant are in this module anymore __getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index a318f763fcb7..ce9b1477ad6a 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -23,6 +23,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -66,10 +67,6 @@ class SwitchDeviceClass(StrEnum): SwitchDeviceClass.SWITCH, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - # mypy: disallow-any-generics @@ -133,3 +130,11 @@ def device_class(self) -> SwitchDeviceClass | None: if hasattr(self, "entity_description"): return self.entity_description.device_class return None + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/components/water_heater/__init__.py b/homeassistant/components/water_heater/__init__.py index e5cf2cc2d3ce..82a853125ff1 100644 --- a/homeassistant/components/water_heater/__init__.py +++ b/homeassistant/components/water_heater/__init__.py @@ -30,6 +30,7 @@ ) from homeassistant.helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -86,10 +87,6 @@ class WaterHeaterEntityFeature(IntFlag): WaterHeaterEntityFeature.AWAY_MODE, "2025.1" ) -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals()) - ATTR_MAX_TEMP = "max_temp" ATTR_MIN_TEMP = "min_temp" ATTR_AWAY_MODE = "away_mode" @@ -441,3 +438,11 @@ async def async_service_temperature_set( kwargs[value] = temp await entity.async_set_temperature(**kwargs) + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = ft.partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/const.py b/homeassistant/const.py index a6927aa8165a..9e0505fadf33 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -8,6 +8,7 @@ from .helpers.deprecation import ( DeprecatedConstant, DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -440,12 +441,6 @@ class Platform(StrEnum): "2025.1", ) - -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - - # #### STATES #### STATE_ON: Final = "on" STATE_OFF: Final = "off" @@ -1607,3 +1602,10 @@ class EntityCategory(StrEnum): FORMAT_DATE: Final = "%Y-%m-%d" FORMAT_TIME: Final = "%H:%M:%S" FORMAT_DATETIME: Final = f"{FORMAT_DATE} {FORMAT_TIME}" + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/core.py b/homeassistant/core.py index b15d393c63e2..e843481f79da 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -83,6 +83,7 @@ ) from .helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -159,11 +160,6 @@ class ConfigSource(enum.StrEnum): _DEPRECATED_SOURCE_YAML = DeprecatedConstantEnum(ConfigSource.YAML, "2025.1") -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = functools.partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = functools.partial(dir_with_deprecated_constants, module_globals=globals()) - - # How long to wait until things that run on startup have to finish. TIMEOUT_EVENT_START = 15 @@ -2534,3 +2530,11 @@ async def async_save(self, data: dict[str, Any]) -> None: if self._original_unit_system: data["unit_system"] = self._original_unit_system return await super().async_save(data) + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = functools.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = functools.partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 5c9c0ff1ce4d..63ba565582a8 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -17,6 +17,7 @@ from .exceptions import HomeAssistantError from .helpers.deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -59,10 +60,6 @@ class FlowResultType(StrEnum): ) _DEPRECATED_RESULT_TYPE_MENU = DeprecatedConstantEnum(FlowResultType.MENU, "2025.1") -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - # Event that is fired when a flow is progressed via external or progress source. EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed" @@ -700,3 +697,11 @@ def _create_abort_data( reason=reason, description_placeholders=description_placeholders, ) + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/homeassistant/helpers/deprecation.py b/homeassistant/helpers/deprecation.py index 72b26e90b842..18a42ce9bcf1 100644 --- a/homeassistant/helpers/deprecation.py +++ b/homeassistant/helpers/deprecation.py @@ -292,10 +292,22 @@ def check_if_deprecated_constant(name: str, module_globals: dict[str, Any]) -> A return value -def dir_with_deprecated_constants(module_globals: dict[str, Any]) -> list[str]: +def dir_with_deprecated_constants(module_globals_keys: list[str]) -> list[str]: """Return dir() with deprecated constants.""" - return list(module_globals) + [ + return module_globals_keys + [ name.removeprefix(_PREFIX_DEPRECATED) - for name in module_globals + for name in module_globals_keys + if name.startswith(_PREFIX_DEPRECATED) + ] + + +def all_with_deprecated_constants(module_globals: dict[str, Any]) -> list[str]: + """Generate a list for __all___ with deprecated constants.""" + # Iterate over a copy in case the globals dict is mutated by another thread + # while we loop over it. + module_globals_keys = list(module_globals) + return [itm for itm in module_globals_keys if not itm.startswith("_")] + [ + name.removeprefix(_PREFIX_DEPRECATED) + for name in module_globals_keys if name.startswith(_PREFIX_DEPRECATED) ] diff --git a/homeassistant/helpers/device_registry.py b/homeassistant/helpers/device_registry.py index bd509cb47ec2..cfe3b78ebab3 100644 --- a/homeassistant/helpers/device_registry.py +++ b/homeassistant/helpers/device_registry.py @@ -24,6 +24,7 @@ from .debounce import Debouncer from .deprecation import ( DeprecatedConstantEnum, + all_with_deprecated_constants, check_if_deprecated_constant, dir_with_deprecated_constants, ) @@ -75,10 +76,6 @@ class DeviceEntryDisabler(StrEnum): ) _DEPRECATED_DISABLED_USER = DeprecatedConstantEnum(DeviceEntryDisabler.USER, "2025.1") -# Both can be removed if no deprecated constant are in this module anymore -__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) -__dir__ = partial(dir_with_deprecated_constants, module_globals=globals()) - class DeviceInfo(TypedDict, total=False): """Entity device information for device registry.""" @@ -1113,3 +1110,11 @@ def _normalize_connections(connections: set[tuple[str, str]]) -> set[tuple[str, (key, format_mac(value)) if key == CONNECTION_NETWORK_MAC else (key, value) for key, value in connections } + + +# These can be removed if no deprecated constant are in this module anymore +__getattr__ = partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = partial( + dir_with_deprecated_constants, module_globals_keys=[*globals().keys()] +) +__all__ = all_with_deprecated_constants(globals()) diff --git a/pyproject.toml b/pyproject.toml index ec313a5bcf6d..2fc5f594157b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -176,7 +176,8 @@ disable = [ "duplicate-bases", # PLE0241 "format-needs-mapping", # F502 "function-redefined", # F811 - "invalid-all-format", # PLE0605 + # Needed because ruff does not understand type of __all__ generated by a function + # "invalid-all-format", # PLE0605 "invalid-all-object", # PLE0604 "invalid-character-backspace", # PLE2510 "invalid-character-esc", # PLE2513 @@ -673,6 +674,9 @@ ignore = [ "COM819", "ISC001", "ISC002", + + # Disabled because ruff does not understand type of __all__ generated by a function + "PLE0605", ] [tool.ruff.flake8-import-conventions.extend-aliases] diff --git a/tests/common.py b/tests/common.py index b07788dc3d73..85193022e4f9 100644 --- a/tests/common.py +++ b/tests/common.py @@ -92,7 +92,7 @@ import homeassistant.util.yaml.loader as yaml_loader from tests.testing_config.custom_components.test_constant_deprecation import ( - import_deprecated_costant, + import_deprecated_constant, ) _LOGGER = logging.getLogger(__name__) @@ -1482,6 +1482,7 @@ def import_and_test_deprecated_constant_enum( - Assert value is the same as the replacement - Assert a warning is logged - Assert the deprecated constant is included in the modules.__dir__() + - Assert the deprecated constant is included in the modules.__all__() """ import_and_test_deprecated_constant( caplog, @@ -1507,8 +1508,9 @@ def import_and_test_deprecated_constant( - Assert value is the same as the replacement - Assert a warning is logged - Assert the deprecated constant is included in the modules.__dir__() + - Assert the deprecated constant is included in the modules.__all__() """ - value = import_deprecated_costant(module, constant_name) + value = import_deprecated_constant(module, constant_name) assert value == replacement assert ( module.__name__, @@ -1523,3 +1525,11 @@ def import_and_test_deprecated_constant( # verify deprecated constant is included in dir() assert constant_name in dir(module) + assert constant_name in module.__all__ + + +def help_test_all(module: ModuleType) -> None: + """Test module.__all__ is correctly set.""" + assert set(module.__all__) == { + itm for itm in module.__dir__() if not itm.startswith("_") + } diff --git a/tests/components/alarm_control_panel/test_init.py b/tests/components/alarm_control_panel/test_init.py index 1e6fce6def62..42a532cbb1a1 100644 --- a/tests/components/alarm_control_panel/test_init.py +++ b/tests/components/alarm_control_panel/test_init.py @@ -6,7 +6,16 @@ from homeassistant.components import alarm_control_panel -from tests.common import import_and_test_deprecated_constant_enum +from tests.common import help_test_all, import_and_test_deprecated_constant_enum + + +@pytest.mark.parametrize( + "module", + [alarm_control_panel, alarm_control_panel.const], +) +def test_all(module: ModuleType) -> None: + """Test module.__all__ is correctly set.""" + help_test_all(module) @pytest.mark.parametrize( diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 235ca48f095e..6bb1b89259a6 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -59,6 +59,7 @@ async_capture_events, async_fire_time_changed, async_mock_service, + help_test_all, import_and_test_deprecated_constant, mock_restore_cache, ) @@ -2569,6 +2570,11 @@ async def test_websocket_config( assert msg["error"]["code"] == "not_found" +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(automation) + + @pytest.mark.parametrize( ("constant_name", "replacement"), [ diff --git a/tests/components/binary_sensor/test_init.py b/tests/components/binary_sensor/test_init.py index 014722d94a4f..6ca189113b9e 100644 --- a/tests/components/binary_sensor/test_init.py +++ b/tests/components/binary_sensor/test_init.py @@ -14,6 +14,7 @@ MockConfigEntry, MockModule, MockPlatform, + help_test_all, import_and_test_deprecated_constant_enum, mock_config_flow, mock_integration, @@ -197,6 +198,11 @@ async def async_setup_entry_platform( ) +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(binary_sensor) + + @pytest.mark.parametrize( "device_class", list(binary_sensor.BinarySensorDeviceClass), diff --git a/tests/components/camera/test_init.py b/tests/components/camera/test_init.py index 0e761f2f4372..f1e3a4fdef5b 100644 --- a/tests/components/camera/test_init.py +++ b/tests/components/camera/test_init.py @@ -27,7 +27,7 @@ from .common import EMPTY_8_6_JPEG, WEBRTC_ANSWER, mock_turbo_jpeg -from tests.common import import_and_test_deprecated_constant_enum +from tests.common import help_test_all, import_and_test_deprecated_constant_enum from tests.typing import ClientSessionGenerator, WebSocketGenerator STREAM_SOURCE = "rtsp://127.0.0.1/stream" @@ -962,6 +962,15 @@ async def test_use_stream_for_stills( assert await resp.read() == b"stream_keyframe_image" +@pytest.mark.parametrize( + "module", + [camera, camera.const], +) +def test_all(module: ModuleType) -> None: + """Test module.__all__ is correctly set.""" + help_test_all(module) + + @pytest.mark.parametrize( "enum", list(camera.const.StreamType), diff --git a/tests/components/climate/test_init.py b/tests/components/climate/test_init.py index 8fc82365c23e..89826c980866 100644 --- a/tests/components/climate/test_init.py +++ b/tests/components/climate/test_init.py @@ -36,6 +36,7 @@ MockModule, MockPlatform, async_mock_service, + help_test_all, import_and_test_deprecated_constant, import_and_test_deprecated_constant_enum, mock_integration, @@ -157,6 +158,15 @@ def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]: return result +@pytest.mark.parametrize( + "module", + [climate, climate.const], +) +def test_all(module: ModuleType) -> None: + """Test module.__all__ is correctly set.""" + help_test_all(module) + + @pytest.mark.parametrize( ("enum", "constant_prefix"), _create_tuples(climate.ClimateEntityFeature, "SUPPORT_") diff --git a/tests/components/cover/test_init.py b/tests/components/cover/test_init.py index 1b08658d9839..480d1ef83aa5 100644 --- a/tests/components/cover/test_init.py +++ b/tests/components/cover/test_init.py @@ -16,7 +16,7 @@ from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -from tests.common import import_and_test_deprecated_constant_enum +from tests.common import help_test_all, import_and_test_deprecated_constant_enum async def test_services(hass: HomeAssistant, enable_custom_integrations: None) -> None: @@ -127,6 +127,11 @@ def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]: return result +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(cover) + + @pytest.mark.parametrize( ("enum", "constant_prefix"), _create_tuples(cover.CoverEntityFeature, "SUPPORT_") diff --git a/tests/components/device_tracker/test_init.py b/tests/components/device_tracker/test_init.py index 024187a33f6a..eb8fde8f0e27 100644 --- a/tests/components/device_tracker/test_init.py +++ b/tests/components/device_tracker/test_init.py @@ -34,6 +34,7 @@ from tests.common import ( assert_setup_component, async_fire_time_changed, + help_test_all, import_and_test_deprecated_constant_enum, mock_registry, mock_restore_cache, @@ -685,6 +686,15 @@ def test_see_schema_allowing_ios_calls() -> None: ) +@pytest.mark.parametrize( + "module", + [device_tracker, device_tracker.const], +) +def test_all(module: ModuleType) -> None: + """Test module.__all__ is correctly set.""" + help_test_all(module) + + @pytest.mark.parametrize(("enum"), list(SourceType)) @pytest.mark.parametrize( "module", diff --git a/tests/components/fan/test_init.py b/tests/components/fan/test_init.py index 828c13b6f167..1beea47c6fa8 100644 --- a/tests/components/fan/test_init.py +++ b/tests/components/fan/test_init.py @@ -15,7 +15,7 @@ import homeassistant.helpers.entity_registry as er from homeassistant.setup import async_setup_component -from tests.common import import_and_test_deprecated_constant_enum +from tests.common import help_test_all, import_and_test_deprecated_constant_enum from tests.testing_config.custom_components.test.fan import MockFan @@ -150,6 +150,11 @@ async def test_preset_mode_validation( assert exc.value.translation_key == "not_valid_preset_mode" +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(fan) + + @pytest.mark.parametrize(("enum"), list(fan.FanEntityFeature)) def test_deprecated_constants( caplog: pytest.LogCaptureFixture, diff --git a/tests/components/humidifier/test_init.py b/tests/components/humidifier/test_init.py index 24cf4b6d9629..3ef3fca85899 100644 --- a/tests/components/humidifier/test_init.py +++ b/tests/components/humidifier/test_init.py @@ -13,7 +13,7 @@ ) from homeassistant.core import HomeAssistant -from tests.common import import_and_test_deprecated_constant_enum +from tests.common import help_test_all, import_and_test_deprecated_constant_enum class MockHumidifierEntity(HumidifierEntity): @@ -54,6 +54,15 @@ def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]: return result +@pytest.mark.parametrize( + "module", + [humidifier, humidifier.const], +) +def test_all(module: ModuleType) -> None: + """Test module.__all__ is correctly set.""" + help_test_all(module) + + @pytest.mark.parametrize( ("enum", "constant_prefix"), _create_tuples(humidifier.HumidifierEntityFeature, "SUPPORT_") diff --git a/tests/components/lock/test_init.py b/tests/components/lock/test_init.py index 854b89fd1d83..7ebb5bf3027b 100644 --- a/tests/components/lock/test_init.py +++ b/tests/components/lock/test_init.py @@ -28,7 +28,7 @@ from .conftest import MockLock -from tests.common import import_and_test_deprecated_constant_enum +from tests.common import help_test_all, import_and_test_deprecated_constant_enum async def help_test_async_lock_service( @@ -371,6 +371,11 @@ async def test_lock_with_illegal_default_code( assert exc.value.translation_key == "add_default_code" +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(lock) + + @pytest.mark.parametrize(("enum"), list(LockEntityFeature)) def test_deprecated_constants( caplog: pytest.LogCaptureFixture, diff --git a/tests/components/number/test_const.py b/tests/components/number/test_const.py index e4b47e17e6ed..13d94e2eeaf5 100644 --- a/tests/components/number/test_const.py +++ b/tests/components/number/test_const.py @@ -4,7 +4,12 @@ from homeassistant.components.number import const -from tests.common import import_and_test_deprecated_constant_enum +from tests.common import help_test_all, import_and_test_deprecated_constant_enum + + +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(const) @pytest.mark.parametrize(("enum"), list(const.NumberMode)) diff --git a/tests/components/remote/test_init.py b/tests/components/remote/test_init.py index a75ff8584836..be4a4843097b 100644 --- a/tests/components/remote/test_init.py +++ b/tests/components/remote/test_init.py @@ -22,7 +22,11 @@ ) from homeassistant.core import HomeAssistant -from tests.common import async_mock_service, import_and_test_deprecated_constant_enum +from tests.common import ( + async_mock_service, + help_test_all, + import_and_test_deprecated_constant_enum, +) TEST_PLATFORM = {DOMAIN: {CONF_PLATFORM: "test"}} SERVICE_SEND_COMMAND = "send_command" @@ -143,6 +147,11 @@ async def test_delete_command(hass: HomeAssistant) -> None: assert call.data[ATTR_ENTITY_ID] == ENTITY_ID +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(remote) + + @pytest.mark.parametrize(("enum"), list(remote.RemoteEntityFeature)) def test_deprecated_constants( caplog: pytest.LogCaptureFixture, diff --git a/tests/components/sensor/test_init.py b/tests/components/sensor/test_init.py index 829bb5af8279..522afe3b992e 100644 --- a/tests/components/sensor/test_init.py +++ b/tests/components/sensor/test_init.py @@ -52,6 +52,7 @@ MockModule, MockPlatform, async_mock_restore_state_shutdown_restart, + help_test_all, import_and_test_deprecated_constant_enum, mock_config_flow, mock_integration, @@ -2524,6 +2525,15 @@ async def test_entity_category_config_raises_error( assert not hass.states.get("sensor.test") +@pytest.mark.parametrize( + "module", + [sensor, sensor.const], +) +def test_all(module: ModuleType) -> None: + """Test module.__all__ is correctly set.""" + help_test_all(module) + + @pytest.mark.parametrize(("enum"), list(sensor.SensorStateClass)) @pytest.mark.parametrize(("module"), [sensor, sensor.const]) def test_deprecated_constants( diff --git a/tests/components/siren/test_init.py b/tests/components/siren/test_init.py index abc5b0fac38b..1cf44d16ea00 100644 --- a/tests/components/siren/test_init.py +++ b/tests/components/siren/test_init.py @@ -13,7 +13,7 @@ from homeassistant.components.siren.const import SirenEntityFeature from homeassistant.core import HomeAssistant -from tests.common import import_and_test_deprecated_constant_enum +from tests.common import help_test_all, import_and_test_deprecated_constant_enum class MockSirenEntity(SirenEntity): @@ -110,6 +110,15 @@ async def test_missing_tones_dict(hass: HomeAssistant) -> None: process_turn_on_params(siren, {"tone": 3}) +@pytest.mark.parametrize( + "module", + [siren, siren.const], +) +def test_all(module: ModuleType) -> None: + """Test module.__all__ is correctly set.""" + help_test_all(module) + + @pytest.mark.parametrize(("enum"), list(SirenEntityFeature)) @pytest.mark.parametrize(("module"), [siren, siren.const]) def test_deprecated_constants( diff --git a/tests/components/switch/test_init.py b/tests/components/switch/test_init.py index 7a43e0bf50ef..deb7acb512a9 100644 --- a/tests/components/switch/test_init.py +++ b/tests/components/switch/test_init.py @@ -9,7 +9,11 @@ from . import common -from tests.common import MockUser, import_and_test_deprecated_constant_enum +from tests.common import ( + MockUser, + help_test_all, + import_and_test_deprecated_constant_enum, +) @pytest.fixture(autouse=True) @@ -82,6 +86,11 @@ async def test_switch_context( assert state2.context.user_id == hass_admin_user.id +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(switch) + + @pytest.mark.parametrize(("enum"), list(switch.SwitchDeviceClass)) def test_deprecated_constants( caplog: pytest.LogCaptureFixture, diff --git a/tests/components/water_heater/test_init.py b/tests/components/water_heater/test_init.py index 861be1923408..b81ef3694521 100644 --- a/tests/components/water_heater/test_init.py +++ b/tests/components/water_heater/test_init.py @@ -17,7 +17,11 @@ from homeassistant.const import UnitOfTemperature from homeassistant.core import HomeAssistant -from tests.common import async_mock_service, import_and_test_deprecated_constant_enum +from tests.common import ( + async_mock_service, + help_test_all, + import_and_test_deprecated_constant_enum, +) async def test_set_temp_schema_no_req( @@ -102,6 +106,11 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None: assert water_heater.async_turn_off.call_count == 1 +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(water_heater) + + @pytest.mark.parametrize( ("enum"), [ diff --git a/tests/helpers/test_deprecation.py b/tests/helpers/test_deprecation.py index 017e541bb08e..25b37e2073f2 100644 --- a/tests/helpers/test_deprecation.py +++ b/tests/helpers/test_deprecation.py @@ -429,7 +429,7 @@ def test_test_check_if_deprecated_constant_invalid( @pytest.mark.parametrize( - ("module_global", "expected"), + ("module_globals", "expected"), [ ({"CONSTANT": 1}, ["CONSTANT"]), ({"_DEPRECATED_CONSTANT": 1}, ["_DEPRECATED_CONSTANT", "CONSTANT"]), @@ -440,7 +440,7 @@ def test_test_check_if_deprecated_constant_invalid( ], ) def test_dir_with_deprecated_constants( - module_global: dict[str, Any], expected: list[str] + module_globals: dict[str, Any], expected: list[str] ) -> None: """Test dir() with deprecated constants.""" - assert dir_with_deprecated_constants(module_global) == expected + assert dir_with_deprecated_constants([*module_globals.keys()]) == expected diff --git a/tests/helpers/test_device_registry.py b/tests/helpers/test_device_registry.py index 43540a52f7da..240afa2cbab8 100644 --- a/tests/helpers/test_device_registry.py +++ b/tests/helpers/test_device_registry.py @@ -20,6 +20,7 @@ from tests.common import ( MockConfigEntry, flush_store, + help_test_all, import_and_test_deprecated_constant_enum, ) @@ -2018,6 +2019,11 @@ async def test_loading_invalid_configuration_url_from_storage( assert entry.configuration_url == "invalid" +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(dr) + + @pytest.mark.parametrize(("enum"), list(dr.DeviceEntryDisabler)) def test_deprecated_constants( caplog: pytest.LogCaptureFixture, diff --git a/tests/test_const.py b/tests/test_const.py index fedf35ae6d1b..4b9be4f27f1f 100644 --- a/tests/test_const.py +++ b/tests/test_const.py @@ -9,6 +9,7 @@ from homeassistant.components import sensor from tests.common import ( + help_test_all, import_and_test_deprecated_constant, import_and_test_deprecated_constant_enum, ) @@ -23,6 +24,11 @@ def _create_tuples( return result +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(const) + + @pytest.mark.parametrize( ("enum", "constant_prefix"), _create_tuples(const.EntityCategory, "ENTITY_CATEGORY_") diff --git a/tests/test_core.py b/tests/test_core.py index 90b87068a5d5..bbd271512439 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -61,6 +61,7 @@ from .common import ( async_capture_events, async_mock_service, + help_test_all, import_and_test_deprecated_constant_enum, ) @@ -2630,6 +2631,11 @@ async def shutdown_func() -> None: assert not evt.is_set() +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(ha) + + @pytest.mark.parametrize( ("enum"), [ diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index eb507febe8a1..602b21c15bc4 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -10,7 +10,11 @@ from homeassistant.core import HomeAssistant from homeassistant.util.decorator import Registry -from .common import async_capture_events, import_and_test_deprecated_constant_enum +from .common import ( + async_capture_events, + help_test_all, + import_and_test_deprecated_constant_enum, +) @pytest.fixture @@ -804,6 +808,11 @@ async def async_step_second(self, user_input=None): assert len(manager.async_progress()) == 0 +def test_all() -> None: + """Test module.__all__ is correctly set.""" + help_test_all(data_entry_flow) + + @pytest.mark.parametrize(("enum"), list(data_entry_flow.FlowResultType)) def test_deprecated_constants( caplog: pytest.LogCaptureFixture, diff --git a/tests/testing_config/custom_components/test_constant_deprecation/__init__.py b/tests/testing_config/custom_components/test_constant_deprecation/__init__.py index 4367cbed7b1a..b061b9c35fc0 100644 --- a/tests/testing_config/custom_components/test_constant_deprecation/__init__.py +++ b/tests/testing_config/custom_components/test_constant_deprecation/__init__.py @@ -4,6 +4,6 @@ from typing import Any -def import_deprecated_costant(module: ModuleType, constant_name: str) -> Any: +def import_deprecated_constant(module: ModuleType, constant_name: str) -> Any: """Import and return deprecated constant.""" return getattr(module, constant_name)