mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Remove deprecated support feature values in camera (#146988)
This commit is contained in:
parent
66e2fd997b
commit
db3090078b
@ -498,19 +498,6 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return self._attr_supported_features
|
return self._attr_supported_features
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features_compat(self) -> CameraEntityFeature:
|
|
||||||
"""Return the supported features as CameraEntityFeature.
|
|
||||||
|
|
||||||
Remove this compatibility shim in 2025.1 or later.
|
|
||||||
"""
|
|
||||||
features = self.supported_features
|
|
||||||
if type(features) is int:
|
|
||||||
new_features = CameraEntityFeature(features)
|
|
||||||
self._report_deprecated_supported_features_values(new_features)
|
|
||||||
return new_features
|
|
||||||
return features
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def is_recording(self) -> bool:
|
def is_recording(self) -> bool:
|
||||||
"""Return true if the device is recording."""
|
"""Return true if the device is recording."""
|
||||||
@ -704,9 +691,7 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
async def async_internal_added_to_hass(self) -> None:
|
async def async_internal_added_to_hass(self) -> None:
|
||||||
"""Run when entity about to be added to hass."""
|
"""Run when entity about to be added to hass."""
|
||||||
await super().async_internal_added_to_hass()
|
await super().async_internal_added_to_hass()
|
||||||
self.__supports_stream = (
|
self.__supports_stream = self.supported_features & CameraEntityFeature.STREAM
|
||||||
self.supported_features_compat & CameraEntityFeature.STREAM
|
|
||||||
)
|
|
||||||
await self.async_refresh_providers(write_state=False)
|
await self.async_refresh_providers(write_state=False)
|
||||||
|
|
||||||
async def async_refresh_providers(self, *, write_state: bool = True) -> None:
|
async def async_refresh_providers(self, *, write_state: bool = True) -> None:
|
||||||
@ -735,7 +720,7 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
self, fn: Callable[[HomeAssistant, Camera], Coroutine[None, None, _T | None]]
|
self, fn: Callable[[HomeAssistant, Camera], Coroutine[None, None, _T | None]]
|
||||||
) -> _T | None:
|
) -> _T | None:
|
||||||
"""Get first provider that supports this camera."""
|
"""Get first provider that supports this camera."""
|
||||||
if CameraEntityFeature.STREAM not in self.supported_features_compat:
|
if CameraEntityFeature.STREAM not in self.supported_features:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return await fn(self.hass, self)
|
return await fn(self.hass, self)
|
||||||
@ -785,7 +770,7 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
def camera_capabilities(self) -> CameraCapabilities:
|
def camera_capabilities(self) -> CameraCapabilities:
|
||||||
"""Return the camera capabilities."""
|
"""Return the camera capabilities."""
|
||||||
frontend_stream_types = set()
|
frontend_stream_types = set()
|
||||||
if CameraEntityFeature.STREAM in self.supported_features_compat:
|
if CameraEntityFeature.STREAM in self.supported_features:
|
||||||
if self._supports_native_async_webrtc:
|
if self._supports_native_async_webrtc:
|
||||||
# The camera has a native WebRTC implementation
|
# The camera has a native WebRTC implementation
|
||||||
frontend_stream_types.add(StreamType.WEB_RTC)
|
frontend_stream_types.add(StreamType.WEB_RTC)
|
||||||
@ -805,8 +790,7 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
"""
|
"""
|
||||||
super().async_write_ha_state()
|
super().async_write_ha_state()
|
||||||
if self.__supports_stream != (
|
if self.__supports_stream != (
|
||||||
supports_stream := self.supported_features_compat
|
supports_stream := self.supported_features & CameraEntityFeature.STREAM
|
||||||
& CameraEntityFeature.STREAM
|
|
||||||
):
|
):
|
||||||
self.__supports_stream = supports_stream
|
self.__supports_stream = supports_stream
|
||||||
self._invalidate_camera_capabilities_cache()
|
self._invalidate_camera_capabilities_cache()
|
||||||
|
@ -7,7 +7,7 @@ import asyncio
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from collections.abc import Callable, Coroutine, Iterable, Mapping
|
from collections.abc import Callable, Coroutine, Iterable, Mapping
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from enum import Enum, IntFlag, auto
|
from enum import Enum, auto
|
||||||
import functools as ft
|
import functools as ft
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
@ -1622,31 +1622,6 @@ class Entity(
|
|||||||
self.hass, integration_domain=platform_name, module=type(self).__module__
|
self.hass, integration_domain=platform_name, module=type(self).__module__
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
|
||||||
def _report_deprecated_supported_features_values(
|
|
||||||
self, replacement: IntFlag
|
|
||||||
) -> None:
|
|
||||||
"""Report deprecated supported features values."""
|
|
||||||
if self._deprecated_supported_features_reported is True:
|
|
||||||
return
|
|
||||||
self._deprecated_supported_features_reported = True
|
|
||||||
report_issue = self._suggest_report_issue()
|
|
||||||
report_issue += (
|
|
||||||
" and reference "
|
|
||||||
"https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation"
|
|
||||||
)
|
|
||||||
_LOGGER.warning(
|
|
||||||
(
|
|
||||||
"Entity %s (%s) is using deprecated supported features"
|
|
||||||
" values which will be removed in HA Core 2025.1. Instead it should use"
|
|
||||||
" %s, please %s"
|
|
||||||
),
|
|
||||||
self.entity_id,
|
|
||||||
type(self),
|
|
||||||
repr(replacement),
|
|
||||||
report_issue,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ToggleEntityDescription(EntityDescription, frozen_or_thawed=True):
|
class ToggleEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||||
"""A class that describes toggle entities."""
|
"""A class that describes toggle entities."""
|
||||||
|
@ -41,7 +41,6 @@ from homeassistant.util import dt as dt_util
|
|||||||
from .common import EMPTY_8_6_JPEG, STREAM_SOURCE, mock_turbo_jpeg
|
from .common import EMPTY_8_6_JPEG, STREAM_SOURCE, mock_turbo_jpeg
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
MockEntityPlatform,
|
|
||||||
async_fire_time_changed,
|
async_fire_time_changed,
|
||||||
help_test_all,
|
help_test_all,
|
||||||
import_and_test_deprecated_constant_enum,
|
import_and_test_deprecated_constant_enum,
|
||||||
@ -834,30 +833,6 @@ def test_deprecated_state_constants(
|
|||||||
import_and_test_deprecated_constant_enum(caplog, module, enum, "STATE_", "2025.10")
|
import_and_test_deprecated_constant_enum(caplog, module, enum, "STATE_", "2025.10")
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_supported_features_ints(
|
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
|
||||||
) -> None:
|
|
||||||
"""Test deprecated supported features ints."""
|
|
||||||
|
|
||||||
class MockCamera(camera.Camera):
|
|
||||||
@property
|
|
||||||
def supported_features(self) -> int:
|
|
||||||
"""Return supported features."""
|
|
||||||
return 1
|
|
||||||
|
|
||||||
entity = MockCamera()
|
|
||||||
entity.hass = hass
|
|
||||||
entity.platform = MockEntityPlatform(hass)
|
|
||||||
assert entity.supported_features_compat is camera.CameraEntityFeature(1)
|
|
||||||
assert "MockCamera" in caplog.text
|
|
||||||
assert "is using deprecated supported features values" in caplog.text
|
|
||||||
assert "Instead it should use" in caplog.text
|
|
||||||
assert "CameraEntityFeature.ON_OFF" in caplog.text
|
|
||||||
caplog.clear()
|
|
||||||
assert entity.supported_features_compat is camera.CameraEntityFeature(1)
|
|
||||||
assert "is using deprecated supported features values" not in caplog.text
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_camera")
|
@pytest.mark.usefixtures("mock_camera")
|
||||||
async def test_entity_picture_url_changes_on_token_update(hass: HomeAssistant) -> None:
|
async def test_entity_picture_url_changes_on_token_update(hass: HomeAssistant) -> None:
|
||||||
"""Test the token is rotated and entity entity picture cache is cleared."""
|
"""Test the token is rotated and entity entity picture cache is cleared."""
|
||||||
|
@ -4,7 +4,6 @@ import asyncio
|
|||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from enum import IntFlag
|
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@ -2488,31 +2487,6 @@ async def test_cached_entity_property_override(hass: HomeAssistant) -> None:
|
|||||||
return "🤡"
|
return "🤡"
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_report_deprecated_supported_features_values(
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
|
||||||
"""Test reporting deprecated supported feature values only happens once."""
|
|
||||||
ent = entity.Entity()
|
|
||||||
|
|
||||||
class MockEntityFeatures(IntFlag):
|
|
||||||
VALUE1 = 1
|
|
||||||
VALUE2 = 2
|
|
||||||
|
|
||||||
ent._report_deprecated_supported_features_values(MockEntityFeatures(2))
|
|
||||||
assert (
|
|
||||||
"is using deprecated supported features values which will be removed"
|
|
||||||
in caplog.text
|
|
||||||
)
|
|
||||||
assert "MockEntityFeatures.VALUE2" in caplog.text
|
|
||||||
|
|
||||||
caplog.clear()
|
|
||||||
ent._report_deprecated_supported_features_values(MockEntityFeatures(2))
|
|
||||||
assert (
|
|
||||||
"is using deprecated supported features values which will be removed"
|
|
||||||
not in caplog.text
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_remove_entity_registry(
|
async def test_remove_entity_registry(
|
||||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user