Derive entity category names from cv.ENTITY_CATEGORIES and cleanup

- Remove hardcoded _ENTITY_CATEGORY_NAMES dict, derive from cv.ENTITY_CATEGORIES keys
- Remove redundant local import re (already at top level)
- Remove last setup_test_environment noqa line
This commit is contained in:
J. Nick Koston
2026-03-06 09:46:28 -10:00
parent 5e1fe0d2b9
commit c37f1481ce
2 changed files with 4 additions and 7 deletions
+4 -4
View File
@@ -228,9 +228,6 @@ def setup_unit_of_measurement(config: ConfigType) -> None:
config[_KEY_UOM_IDX] = idx
_ENTITY_CATEGORY_NAMES = {0: "", 1: "config", 2: "diagnostic"}
def _sanitize_comment(text: str) -> str:
r"""Sanitize a string for safe inclusion in a C++ // line comment.
@@ -248,7 +245,10 @@ def _describe_packed_flags(config: ConfigType, entity_category: int) -> str:
parts.append("internal")
if config.get(_KEY_DISABLED_BY_DEFAULT):
parts.append("disabled_by_default")
if cat_name := _ENTITY_CATEGORY_NAMES.get(entity_category, ""):
entity_cat_keys = list(cv.ENTITY_CATEGORIES)
if entity_category < len(entity_cat_keys) and (
cat_name := entity_cat_keys[entity_category]
):
parts.append(f"category:{cat_name}")
if dc := config.get(CONF_DEVICE_CLASS):
parts.append(f"dc:{_sanitize_comment(dc)}")
@@ -942,7 +942,6 @@ async def test_setup_entity_with_entity_category(
setup_test_environment: list[str],
) -> None:
"""Test setup_entity sets entity_category correctly."""
setup_test_environment # noqa: F841 - fixture initializes CORE state
var = MockObj("sensor1")
config = {
CONF_NAME: "Temperature",
@@ -1008,8 +1007,6 @@ async def test_setup_entity_decorator_mode(setup_test_environment: list[str]) ->
def _extract_packed_value(expressions: list[str]) -> int:
"""Extract the third argument (packed value) from a configure_entity_() call."""
import re
for expr in expressions:
if "configure_entity_" in expr:
# Match the last integer argument before the closing ");"