From b3a9159810fd3e8cc7eeb5e04cade619113f3cbb Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:34:53 +0000 Subject: [PATCH 1/2] Raise error on invalid DeviceEntryDisabler or DeviceEntryType --- homeassistant/helpers/device_registry.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/helpers/device_registry.py b/homeassistant/helpers/device_registry.py index faf4257577d..c964d632558 100644 --- a/homeassistant/helpers/device_registry.py +++ b/homeassistant/helpers/device_registry.py @@ -38,7 +38,7 @@ from .deprecation import ( check_if_deprecated_constant, dir_with_deprecated_constants, ) -from .frame import report +from .frame import ReportBehavior, report_usage from .json import JSON_DUMP, find_paths_unserializable_data, json_bytes, json_fragment from .registry import BaseRegistry, BaseRegistryItems, RegistryIndexType from .singleton import singleton @@ -828,13 +828,14 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]): via_device_id = UNDEFINED if isinstance(entry_type, str) and not isinstance(entry_type, DeviceEntryType): - report( # type: ignore[unreachable] + report_usage( # type: ignore[unreachable] ( "uses str for device registry entry_type. This is deprecated and" " will stop working in Home Assistant 2022.3, it should be updated" " to use DeviceEntryType instead" ), - error_if_core=False, + core_integration_behavior=ReportBehavior.ERROR, + custom_integration_behavior=ReportBehavior.ERROR, ) entry_type = DeviceEntryType(entry_type) @@ -927,13 +928,14 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]): if isinstance(disabled_by, str) and not isinstance( disabled_by, DeviceEntryDisabler ): - report( # type: ignore[unreachable] + report_usage( # type: ignore[unreachable] ( "uses str for device registry disabled_by. This is deprecated and" " will stop working in Home Assistant 2022.3, it should be updated" " to use DeviceEntryDisabler instead" ), - error_if_core=False, + core_integration_behavior=ReportBehavior.ERROR, + custom_integration_behavior=ReportBehavior.ERROR, ) disabled_by = DeviceEntryDisabler(disabled_by) From 03df3c557ad7de78edec1b21b5819170c0da7b8c Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:07:34 +0000 Subject: [PATCH 2/2] Just cleanup --- homeassistant/helpers/device_registry.py | 27 ------------------------ 1 file changed, 27 deletions(-) diff --git a/homeassistant/helpers/device_registry.py b/homeassistant/helpers/device_registry.py index c964d632558..0e56adc7377 100644 --- a/homeassistant/helpers/device_registry.py +++ b/homeassistant/helpers/device_registry.py @@ -38,7 +38,6 @@ from .deprecation import ( check_if_deprecated_constant, dir_with_deprecated_constants, ) -from .frame import ReportBehavior, report_usage from .json import JSON_DUMP, find_paths_unserializable_data, json_bytes, json_fragment from .registry import BaseRegistry, BaseRegistryItems, RegistryIndexType from .singleton import singleton @@ -827,18 +826,6 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]): else: via_device_id = UNDEFINED - if isinstance(entry_type, str) and not isinstance(entry_type, DeviceEntryType): - report_usage( # type: ignore[unreachable] - ( - "uses str for device registry entry_type. This is deprecated and" - " will stop working in Home Assistant 2022.3, it should be updated" - " to use DeviceEntryType instead" - ), - core_integration_behavior=ReportBehavior.ERROR, - custom_integration_behavior=ReportBehavior.ERROR, - ) - entry_type = DeviceEntryType(entry_type) - device = self.async_update_device( device.id, allow_collisions=True, @@ -925,20 +912,6 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]): "Cannot define both merge_identifiers and new_identifiers" ) - if isinstance(disabled_by, str) and not isinstance( - disabled_by, DeviceEntryDisabler - ): - report_usage( # type: ignore[unreachable] - ( - "uses str for device registry disabled_by. This is deprecated and" - " will stop working in Home Assistant 2022.3, it should be updated" - " to use DeviceEntryDisabler instead" - ), - core_integration_behavior=ReportBehavior.ERROR, - custom_integration_behavior=ReportBehavior.ERROR, - ) - disabled_by = DeviceEntryDisabler(disabled_by) - if ( suggested_area is not None and suggested_area is not UNDEFINED