Skip to content

Commit

Permalink
Include deprecated constants in wildcard imports (#107114)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored and frenck committed Jan 5, 2024
1 parent a7aa5c0 commit b8576b8
Show file tree
Hide file tree
Showing 52 changed files with 438 additions and 137 deletions.
17 changes: 11 additions & 6 deletions homeassistant/components/alarm_control_panel/__init__.py
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
12 changes: 8 additions & 4 deletions homeassistant/components/alarm_control_panel/const.py
Expand Up @@ -5,6 +5,7 @@

from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -60,14 +61,17 @@ 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"
CONDITION_ARMED_AWAY: Final = "is_armed_away"
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())
13 changes: 9 additions & 4 deletions homeassistant/components/automation/__init__.py
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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())
13 changes: 9 additions & 4 deletions homeassistant/components/binary_sensor/__init__.py
Expand Up @@ -19,6 +19,7 @@
)
from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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())
13 changes: 9 additions & 4 deletions homeassistant/components/camera/__init__.py
Expand Up @@ -54,6 +54,7 @@
)
from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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())
8 changes: 6 additions & 2 deletions homeassistant/components/camera/const.py
Expand Up @@ -5,6 +5,7 @@

from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -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())
17 changes: 11 additions & 6 deletions homeassistant/components/climate/__init__.py
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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())
8 changes: 6 additions & 2 deletions homeassistant/components/climate/const.py
Expand Up @@ -5,6 +5,7 @@

from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -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())
13 changes: 9 additions & 4 deletions homeassistant/components/cover/__init__.py
Expand Up @@ -34,6 +34,7 @@
)
from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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())
17 changes: 11 additions & 6 deletions homeassistant/components/device_tracker/__init__.py
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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:
Expand All @@ -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())
12 changes: 8 additions & 4 deletions homeassistant/components/device_tracker/const.py
Expand Up @@ -9,6 +9,7 @@

from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -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)

Expand All @@ -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())
13 changes: 9 additions & 4 deletions homeassistant/components/fan/__init__.py
Expand Up @@ -26,6 +26,7 @@
)
from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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())
17 changes: 11 additions & 6 deletions homeassistant/components/humidifier/__init__.py
Expand Up @@ -24,6 +24,7 @@
PLATFORM_SCHEMA_BASE,
)
from homeassistant.helpers.deprecation import (
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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())

0 comments on commit b8576b8

Please sign in to comment.