From b700a27c8fb0c4cd080725bde7a432597fb339c9 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Wed, 21 Jan 2026 21:56:51 +0100 Subject: [PATCH] Enable apple tv on Python 3.14 (#161396) --- homeassistant/components/apple_tv/__init__.py | 72 +++++++------------ tests/components/apple_tv/__init__.py | 7 +- 2 files changed, 28 insertions(+), 51 deletions(-) diff --git a/homeassistant/components/apple_tv/__init__.py b/homeassistant/components/apple_tv/__init__.py index 7c0004d44c5..2448ddd06aa 100644 --- a/homeassistant/components/apple_tv/__init__.py +++ b/homeassistant/components/apple_tv/__init__.py @@ -5,9 +5,14 @@ from __future__ import annotations import asyncio import logging from random import randrange -import sys from typing import Any, cast +from pyatv import connect, exceptions, scan +from pyatv.conf import AppleTV +from pyatv.const import DeviceModel, Protocol +from pyatv.convert import model_str +from pyatv.interface import AppleTV as AppleTVInterface, DeviceListener + from homeassistant.components import zeroconf from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -24,11 +29,7 @@ from homeassistant.const import ( Platform, ) from homeassistant.core import Event, HomeAssistant, callback -from homeassistant.exceptions import ( - ConfigEntryAuthFailed, - ConfigEntryNotReady, - HomeAssistantError, -) +from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import device_registry as dr from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -42,18 +43,6 @@ from .const import ( SIGNAL_DISCONNECTED, ) -if sys.version_info < (3, 14): - from pyatv import connect, exceptions, scan - from pyatv.conf import AppleTV - from pyatv.const import DeviceModel, Protocol - from pyatv.convert import model_str - from pyatv.interface import AppleTV as AppleTVInterface, DeviceListener -else: - - class DeviceListener: - """Dummy class.""" - - _LOGGER = logging.getLogger(__name__) DEFAULT_NAME_TV = "Apple TV" @@ -64,30 +53,25 @@ BACKOFF_TIME_UPPER_LIMIT = 300 # Five minutes PLATFORMS = [Platform.MEDIA_PLAYER, Platform.REMOTE] -if sys.version_info < (3, 14): - AUTH_EXCEPTIONS = ( - exceptions.AuthenticationError, - exceptions.InvalidCredentialsError, - exceptions.NoCredentialsError, - ) - CONNECTION_TIMEOUT_EXCEPTIONS = ( - OSError, - asyncio.CancelledError, - TimeoutError, - exceptions.ConnectionLostError, - exceptions.ConnectionFailedError, - ) - DEVICE_EXCEPTIONS = ( - exceptions.ProtocolError, - exceptions.NoServiceError, - exceptions.PairingError, - exceptions.BackOffError, - exceptions.DeviceIdMissingError, - ) -else: - AUTH_EXCEPTIONS = () - CONNECTION_TIMEOUT_EXCEPTIONS = () - DEVICE_EXCEPTIONS = () +AUTH_EXCEPTIONS = ( + exceptions.AuthenticationError, + exceptions.InvalidCredentialsError, + exceptions.NoCredentialsError, +) +CONNECTION_TIMEOUT_EXCEPTIONS = ( + OSError, + asyncio.CancelledError, + TimeoutError, + exceptions.ConnectionLostError, + exceptions.ConnectionFailedError, +) +DEVICE_EXCEPTIONS = ( + exceptions.ProtocolError, + exceptions.NoServiceError, + exceptions.PairingError, + exceptions.BackOffError, + exceptions.DeviceIdMissingError, +) type AppleTvConfigEntry = ConfigEntry[AppleTVManager] @@ -95,10 +79,6 @@ type AppleTvConfigEntry = ConfigEntry[AppleTVManager] async def async_setup_entry(hass: HomeAssistant, entry: AppleTvConfigEntry) -> bool: """Set up a config entry for Apple TV.""" - if sys.version_info >= (3, 14): - raise HomeAssistantError( - "Apple TV is not supported on Python 3.14. Please use Python 3.13." - ) manager = AppleTVManager(hass, entry) if manager.is_on: diff --git a/tests/components/apple_tv/__init__.py b/tests/components/apple_tv/__init__.py index e06e5deaa15..514d77bde4d 100644 --- a/tests/components/apple_tv/__init__.py +++ b/tests/components/apple_tv/__init__.py @@ -1,9 +1,6 @@ """Tests for Apple TV.""" -import sys - import pytest -if sys.version_info < (3, 14): - # Make asserts in the common module display differences - pytest.register_assert_rewrite("tests.components.apple_tv.common") +# Make asserts in the common module display differences +pytest.register_assert_rewrite("tests.components.apple_tv.common")