Skip to content

Commit db30900

Browse files
Remove deprecated support feature values in camera (home-assistant#146988)
1 parent 66e2fd9 commit db30900

File tree

4 files changed

+5
-97
lines changed

4 files changed

+5
-97
lines changed

homeassistant/components/camera/__init__.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -498,19 +498,6 @@ def supported_features(self) -> CameraEntityFeature:
498498
"""Flag supported features."""
499499
return self._attr_supported_features
500500

501-
@property
502-
def supported_features_compat(self) -> CameraEntityFeature:
503-
"""Return the supported features as CameraEntityFeature.
504-
505-
Remove this compatibility shim in 2025.1 or later.
506-
"""
507-
features = self.supported_features
508-
if type(features) is int:
509-
new_features = CameraEntityFeature(features)
510-
self._report_deprecated_supported_features_values(new_features)
511-
return new_features
512-
return features
513-
514501
@cached_property
515502
def is_recording(self) -> bool:
516503
"""Return true if the device is recording."""
@@ -704,9 +691,7 @@ def async_update_token(self) -> None:
704691
async def async_internal_added_to_hass(self) -> None:
705692
"""Run when entity about to be added to hass."""
706693
await super().async_internal_added_to_hass()
707-
self.__supports_stream = (
708-
self.supported_features_compat & CameraEntityFeature.STREAM
709-
)
694+
self.__supports_stream = self.supported_features & CameraEntityFeature.STREAM
710695
await self.async_refresh_providers(write_state=False)
711696

712697
async def async_refresh_providers(self, *, write_state: bool = True) -> None:
@@ -735,7 +720,7 @@ async def _async_get_supported_webrtc_provider[_T](
735720
self, fn: Callable[[HomeAssistant, Camera], Coroutine[None, None, _T | None]]
736721
) -> _T | None:
737722
"""Get first provider that supports this camera."""
738-
if CameraEntityFeature.STREAM not in self.supported_features_compat:
723+
if CameraEntityFeature.STREAM not in self.supported_features:
739724
return None
740725

741726
return await fn(self.hass, self)
@@ -785,7 +770,7 @@ def _invalidate_camera_capabilities_cache(self) -> None:
785770
def camera_capabilities(self) -> CameraCapabilities:
786771
"""Return the camera capabilities."""
787772
frontend_stream_types = set()
788-
if CameraEntityFeature.STREAM in self.supported_features_compat:
773+
if CameraEntityFeature.STREAM in self.supported_features:
789774
if self._supports_native_async_webrtc:
790775
# The camera has a native WebRTC implementation
791776
frontend_stream_types.add(StreamType.WEB_RTC)
@@ -805,8 +790,7 @@ def async_write_ha_state(self) -> None:
805790
"""
806791
super().async_write_ha_state()
807792
if self.__supports_stream != (
808-
supports_stream := self.supported_features_compat
809-
& CameraEntityFeature.STREAM
793+
supports_stream := self.supported_features & CameraEntityFeature.STREAM
810794
):
811795
self.__supports_stream = supports_stream
812796
self._invalidate_camera_capabilities_cache()

homeassistant/helpers/entity.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections import deque
88
from collections.abc import Callable, Coroutine, Iterable, Mapping
99
import dataclasses
10-
from enum import Enum, IntFlag, auto
10+
from enum import Enum, auto
1111
import functools as ft
1212
import logging
1313
import math
@@ -1622,31 +1622,6 @@ def _suggest_report_issue(self) -> str:
16221622
self.hass, integration_domain=platform_name, module=type(self).__module__
16231623
)
16241624

1625-
@callback
1626-
def _report_deprecated_supported_features_values(
1627-
self, replacement: IntFlag
1628-
) -> None:
1629-
"""Report deprecated supported features values."""
1630-
if self._deprecated_supported_features_reported is True:
1631-
return
1632-
self._deprecated_supported_features_reported = True
1633-
report_issue = self._suggest_report_issue()
1634-
report_issue += (
1635-
" and reference "
1636-
"https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation"
1637-
)
1638-
_LOGGER.warning(
1639-
(
1640-
"Entity %s (%s) is using deprecated supported features"
1641-
" values which will be removed in HA Core 2025.1. Instead it should use"
1642-
" %s, please %s"
1643-
),
1644-
self.entity_id,
1645-
type(self),
1646-
repr(replacement),
1647-
report_issue,
1648-
)
1649-
16501625

16511626
class ToggleEntityDescription(EntityDescription, frozen_or_thawed=True):
16521627
"""A class that describes toggle entities."""

tests/components/camera/test_init.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
from .common import EMPTY_8_6_JPEG, STREAM_SOURCE, mock_turbo_jpeg
4242

4343
from tests.common import (
44-
MockEntityPlatform,
4544
async_fire_time_changed,
4645
help_test_all,
4746
import_and_test_deprecated_constant_enum,
@@ -834,30 +833,6 @@ def test_deprecated_state_constants(
834833
import_and_test_deprecated_constant_enum(caplog, module, enum, "STATE_", "2025.10")
835834

836835

837-
def test_deprecated_supported_features_ints(
838-
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
839-
) -> None:
840-
"""Test deprecated supported features ints."""
841-
842-
class MockCamera(camera.Camera):
843-
@property
844-
def supported_features(self) -> int:
845-
"""Return supported features."""
846-
return 1
847-
848-
entity = MockCamera()
849-
entity.hass = hass
850-
entity.platform = MockEntityPlatform(hass)
851-
assert entity.supported_features_compat is camera.CameraEntityFeature(1)
852-
assert "MockCamera" in caplog.text
853-
assert "is using deprecated supported features values" in caplog.text
854-
assert "Instead it should use" in caplog.text
855-
assert "CameraEntityFeature.ON_OFF" in caplog.text
856-
caplog.clear()
857-
assert entity.supported_features_compat is camera.CameraEntityFeature(1)
858-
assert "is using deprecated supported features values" not in caplog.text
859-
860-
861836
@pytest.mark.usefixtures("mock_camera")
862837
async def test_entity_picture_url_changes_on_token_update(hass: HomeAssistant) -> None:
863838
"""Test the token is rotated and entity entity picture cache is cleared."""

tests/helpers/test_entity.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from collections.abc import Iterable
55
import dataclasses
66
from datetime import timedelta
7-
from enum import IntFlag
87
import logging
98
import threading
109
from typing import Any
@@ -2488,31 +2487,6 @@ def _attr_attribution(self):
24882487
return "🤡"
24892488

24902489

2491-
async def test_entity_report_deprecated_supported_features_values(
2492-
caplog: pytest.LogCaptureFixture,
2493-
) -> None:
2494-
"""Test reporting deprecated supported feature values only happens once."""
2495-
ent = entity.Entity()
2496-
2497-
class MockEntityFeatures(IntFlag):
2498-
VALUE1 = 1
2499-
VALUE2 = 2
2500-
2501-
ent._report_deprecated_supported_features_values(MockEntityFeatures(2))
2502-
assert (
2503-
"is using deprecated supported features values which will be removed"
2504-
in caplog.text
2505-
)
2506-
assert "MockEntityFeatures.VALUE2" in caplog.text
2507-
2508-
caplog.clear()
2509-
ent._report_deprecated_supported_features_values(MockEntityFeatures(2))
2510-
assert (
2511-
"is using deprecated supported features values which will be removed"
2512-
not in caplog.text
2513-
)
2514-
2515-
25162490
async def test_remove_entity_registry(
25172491
hass: HomeAssistant, entity_registry: er.EntityRegistry
25182492
) -> None:

0 commit comments

Comments
 (0)