Remove entity category system in favor of hidden_by (#68550)
This commit is contained in:
parent
a4682ae6e1
commit
1aaf78ef99
9 changed files with 42 additions and 51 deletions
|
@ -764,11 +764,9 @@ CLOUD_NEVER_EXPOSED_ENTITIES: Final[list[str]] = ["group.all_locks"]
|
||||||
# use the EntityCategory enum instead.
|
# use the EntityCategory enum instead.
|
||||||
ENTITY_CATEGORY_CONFIG: Final = "config"
|
ENTITY_CATEGORY_CONFIG: Final = "config"
|
||||||
ENTITY_CATEGORY_DIAGNOSTIC: Final = "diagnostic"
|
ENTITY_CATEGORY_DIAGNOSTIC: Final = "diagnostic"
|
||||||
ENTITY_CATEGORY_SYSTEM: Final = "system"
|
|
||||||
ENTITY_CATEGORIES: Final[list[str]] = [
|
ENTITY_CATEGORIES: Final[list[str]] = [
|
||||||
ENTITY_CATEGORY_CONFIG,
|
ENTITY_CATEGORY_CONFIG,
|
||||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||||
ENTITY_CATEGORY_SYSTEM,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# The ID of the Home Assistant Media Player Cast App
|
# The ID of the Home Assistant Media Player Cast App
|
||||||
|
|
|
@ -200,9 +200,6 @@ class EntityCategory(StrEnum):
|
||||||
# Diagnostic: An entity exposing some configuration parameter or diagnostics of a device
|
# Diagnostic: An entity exposing some configuration parameter or diagnostics of a device
|
||||||
DIAGNOSTIC = "diagnostic"
|
DIAGNOSTIC = "diagnostic"
|
||||||
|
|
||||||
# System: An entity which is not useful for the user to interact with
|
|
||||||
SYSTEM = "system"
|
|
||||||
|
|
||||||
|
|
||||||
ENTITY_CATEGORIES_SCHEMA: Final = vol.Coerce(EntityCategory)
|
ENTITY_CATEGORIES_SCHEMA: Final = vol.Coerce(EntityCategory)
|
||||||
|
|
||||||
|
|
|
@ -519,8 +519,8 @@ class EntityPlatform:
|
||||||
config_entry=self.config_entry,
|
config_entry=self.config_entry,
|
||||||
device_id=device_id,
|
device_id=device_id,
|
||||||
disabled_by=disabled_by,
|
disabled_by=disabled_by,
|
||||||
hidden_by=hidden_by,
|
|
||||||
entity_category=entity.entity_category,
|
entity_category=entity.entity_category,
|
||||||
|
hidden_by=hidden_by,
|
||||||
known_object_ids=self.entities.keys(),
|
known_object_ids=self.entities.keys(),
|
||||||
original_device_class=entity.device_class,
|
original_device_class=entity.device_class,
|
||||||
original_icon=entity.icon,
|
original_icon=entity.icon,
|
||||||
|
|
|
@ -43,20 +43,13 @@ async def test_categorized_hidden_entities(hass):
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
entity_entry3 = entity_registry.async_get_or_create(
|
entity_entry3 = entity_registry.async_get_or_create(
|
||||||
"switch",
|
|
||||||
"test",
|
|
||||||
"switch_system_id",
|
|
||||||
suggested_object_id="system_switch",
|
|
||||||
entity_category=EntityCategory.SYSTEM,
|
|
||||||
)
|
|
||||||
entity_entry4 = entity_registry.async_get_or_create(
|
|
||||||
"switch",
|
"switch",
|
||||||
"test",
|
"test",
|
||||||
"switch_hidden_integration_id",
|
"switch_hidden_integration_id",
|
||||||
suggested_object_id="hidden_integration_switch",
|
suggested_object_id="hidden_integration_switch",
|
||||||
hidden_by=er.RegistryEntryHider.INTEGRATION,
|
hidden_by=er.RegistryEntryHider.INTEGRATION,
|
||||||
)
|
)
|
||||||
entity_entry5 = entity_registry.async_get_or_create(
|
entity_entry4 = entity_registry.async_get_or_create(
|
||||||
"switch",
|
"switch",
|
||||||
"test",
|
"test",
|
||||||
"switch_hidden_user_id",
|
"switch_hidden_user_id",
|
||||||
|
@ -69,7 +62,6 @@ async def test_categorized_hidden_entities(hass):
|
||||||
hass.states.async_set(entity_entry2.entity_id, "something_else")
|
hass.states.async_set(entity_entry2.entity_id, "something_else")
|
||||||
hass.states.async_set(entity_entry3.entity_id, "blah")
|
hass.states.async_set(entity_entry3.entity_id, "blah")
|
||||||
hass.states.async_set(entity_entry4.entity_id, "foo")
|
hass.states.async_set(entity_entry4.entity_id, "foo")
|
||||||
hass.states.async_set(entity_entry5.entity_id, "bar")
|
|
||||||
|
|
||||||
msg = await smart_home.async_handle_message(hass, get_default_config(hass), request)
|
msg = await smart_home.async_handle_message(hass, get_default_config(hass), request)
|
||||||
|
|
||||||
|
|
|
@ -39,20 +39,13 @@ async def test_alexa_config_expose_entity_prefs(hass, cloud_prefs, cloud_stub):
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
entity_entry3 = entity_registry.async_get_or_create(
|
entity_entry3 = entity_registry.async_get_or_create(
|
||||||
"light",
|
|
||||||
"test",
|
|
||||||
"light_system_id",
|
|
||||||
suggested_object_id="system_light",
|
|
||||||
entity_category=EntityCategory.SYSTEM,
|
|
||||||
)
|
|
||||||
entity_entry4 = entity_registry.async_get_or_create(
|
|
||||||
"light",
|
"light",
|
||||||
"test",
|
"test",
|
||||||
"light_hidden_integration_id",
|
"light_hidden_integration_id",
|
||||||
suggested_object_id="hidden_integration_light",
|
suggested_object_id="hidden_integration_light",
|
||||||
hidden_by=er.RegistryEntryHider.INTEGRATION,
|
hidden_by=er.RegistryEntryHider.INTEGRATION,
|
||||||
)
|
)
|
||||||
entity_entry5 = entity_registry.async_get_or_create(
|
entity_entry4 = entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
"test",
|
"test",
|
||||||
"light_hidden_user_id",
|
"light_hidden_user_id",
|
||||||
|
@ -77,7 +70,6 @@ async def test_alexa_config_expose_entity_prefs(hass, cloud_prefs, cloud_stub):
|
||||||
assert not conf.should_expose(entity_entry2.entity_id)
|
assert not conf.should_expose(entity_entry2.entity_id)
|
||||||
assert not conf.should_expose(entity_entry3.entity_id)
|
assert not conf.should_expose(entity_entry3.entity_id)
|
||||||
assert not conf.should_expose(entity_entry4.entity_id)
|
assert not conf.should_expose(entity_entry4.entity_id)
|
||||||
assert not conf.should_expose(entity_entry5.entity_id)
|
|
||||||
|
|
||||||
entity_conf["should_expose"] = True
|
entity_conf["should_expose"] = True
|
||||||
assert conf.should_expose("light.kitchen")
|
assert conf.should_expose("light.kitchen")
|
||||||
|
@ -86,7 +78,6 @@ async def test_alexa_config_expose_entity_prefs(hass, cloud_prefs, cloud_stub):
|
||||||
assert not conf.should_expose(entity_entry2.entity_id)
|
assert not conf.should_expose(entity_entry2.entity_id)
|
||||||
assert not conf.should_expose(entity_entry3.entity_id)
|
assert not conf.should_expose(entity_entry3.entity_id)
|
||||||
assert not conf.should_expose(entity_entry4.entity_id)
|
assert not conf.should_expose(entity_entry4.entity_id)
|
||||||
assert not conf.should_expose(entity_entry5.entity_id)
|
|
||||||
|
|
||||||
entity_conf["should_expose"] = None
|
entity_conf["should_expose"] = None
|
||||||
assert conf.should_expose("light.kitchen")
|
assert conf.should_expose("light.kitchen")
|
||||||
|
@ -95,7 +86,6 @@ async def test_alexa_config_expose_entity_prefs(hass, cloud_prefs, cloud_stub):
|
||||||
assert not conf.should_expose(entity_entry2.entity_id)
|
assert not conf.should_expose(entity_entry2.entity_id)
|
||||||
assert not conf.should_expose(entity_entry3.entity_id)
|
assert not conf.should_expose(entity_entry3.entity_id)
|
||||||
assert not conf.should_expose(entity_entry4.entity_id)
|
assert not conf.should_expose(entity_entry4.entity_id)
|
||||||
assert not conf.should_expose(entity_entry5.entity_id)
|
|
||||||
|
|
||||||
assert "alexa" not in hass.config.components
|
assert "alexa" not in hass.config.components
|
||||||
await cloud_prefs.async_update(
|
await cloud_prefs.async_update(
|
||||||
|
|
|
@ -298,20 +298,13 @@ async def test_google_config_expose_entity_prefs(hass, mock_conf, cloud_prefs):
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
entity_entry3 = entity_registry.async_get_or_create(
|
entity_entry3 = entity_registry.async_get_or_create(
|
||||||
"light",
|
|
||||||
"test",
|
|
||||||
"light_system_id",
|
|
||||||
suggested_object_id="system_light",
|
|
||||||
entity_category=EntityCategory.SYSTEM,
|
|
||||||
)
|
|
||||||
entity_entry4 = entity_registry.async_get_or_create(
|
|
||||||
"light",
|
"light",
|
||||||
"test",
|
"test",
|
||||||
"light_hidden_integration_id",
|
"light_hidden_integration_id",
|
||||||
suggested_object_id="hidden_integration_light",
|
suggested_object_id="hidden_integration_light",
|
||||||
hidden_by=er.RegistryEntryHider.INTEGRATION,
|
hidden_by=er.RegistryEntryHider.INTEGRATION,
|
||||||
)
|
)
|
||||||
entity_entry5 = entity_registry.async_get_or_create(
|
entity_entry4 = entity_registry.async_get_or_create(
|
||||||
"light",
|
"light",
|
||||||
"test",
|
"test",
|
||||||
"light_hidden_user_id",
|
"light_hidden_user_id",
|
||||||
|
@ -328,14 +321,12 @@ async def test_google_config_expose_entity_prefs(hass, mock_conf, cloud_prefs):
|
||||||
state = State("light.kitchen", "on")
|
state = State("light.kitchen", "on")
|
||||||
state_config = State(entity_entry1.entity_id, "on")
|
state_config = State(entity_entry1.entity_id, "on")
|
||||||
state_diagnostic = State(entity_entry2.entity_id, "on")
|
state_diagnostic = State(entity_entry2.entity_id, "on")
|
||||||
state_system = State(entity_entry3.entity_id, "on")
|
state_hidden_integration = State(entity_entry3.entity_id, "on")
|
||||||
state_hidden_integration = State(entity_entry4.entity_id, "on")
|
state_hidden_user = State(entity_entry4.entity_id, "on")
|
||||||
state_hidden_user = State(entity_entry5.entity_id, "on")
|
|
||||||
|
|
||||||
assert not mock_conf.should_expose(state)
|
assert not mock_conf.should_expose(state)
|
||||||
assert not mock_conf.should_expose(state_config)
|
assert not mock_conf.should_expose(state_config)
|
||||||
assert not mock_conf.should_expose(state_diagnostic)
|
assert not mock_conf.should_expose(state_diagnostic)
|
||||||
assert not mock_conf.should_expose(state_system)
|
|
||||||
assert not mock_conf.should_expose(state_hidden_integration)
|
assert not mock_conf.should_expose(state_hidden_integration)
|
||||||
assert not mock_conf.should_expose(state_hidden_user)
|
assert not mock_conf.should_expose(state_hidden_user)
|
||||||
|
|
||||||
|
@ -344,7 +335,6 @@ async def test_google_config_expose_entity_prefs(hass, mock_conf, cloud_prefs):
|
||||||
# categorized and hidden entities should not be exposed
|
# categorized and hidden entities should not be exposed
|
||||||
assert not mock_conf.should_expose(state_config)
|
assert not mock_conf.should_expose(state_config)
|
||||||
assert not mock_conf.should_expose(state_diagnostic)
|
assert not mock_conf.should_expose(state_diagnostic)
|
||||||
assert not mock_conf.should_expose(state_system)
|
|
||||||
assert not mock_conf.should_expose(state_hidden_integration)
|
assert not mock_conf.should_expose(state_hidden_integration)
|
||||||
assert not mock_conf.should_expose(state_hidden_user)
|
assert not mock_conf.should_expose(state_hidden_user)
|
||||||
|
|
||||||
|
@ -353,7 +343,6 @@ async def test_google_config_expose_entity_prefs(hass, mock_conf, cloud_prefs):
|
||||||
# categorized and hidden entities should not be exposed
|
# categorized and hidden entities should not be exposed
|
||||||
assert not mock_conf.should_expose(state_config)
|
assert not mock_conf.should_expose(state_config)
|
||||||
assert not mock_conf.should_expose(state_diagnostic)
|
assert not mock_conf.should_expose(state_diagnostic)
|
||||||
assert not mock_conf.should_expose(state_system)
|
|
||||||
assert not mock_conf.should_expose(state_hidden_integration)
|
assert not mock_conf.should_expose(state_hidden_integration)
|
||||||
assert not mock_conf.should_expose(state_hidden_user)
|
assert not mock_conf.should_expose(state_hidden_user)
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,40 @@ async def test_cost_sensor_no_states(hass, hass_storage, setup_integration) -> N
|
||||||
# TODO: No states, should the cost entity refuse to setup?
|
# TODO: No states, should the cost entity refuse to setup?
|
||||||
|
|
||||||
|
|
||||||
|
async def test_cost_sensor_attributes(hass, hass_storage, setup_integration) -> None:
|
||||||
|
"""Test sensor attributes."""
|
||||||
|
energy_data = data.EnergyManager.default_preferences()
|
||||||
|
energy_data["energy_sources"].append(
|
||||||
|
{
|
||||||
|
"type": "grid",
|
||||||
|
"flow_from": [
|
||||||
|
{
|
||||||
|
"stat_energy_from": "sensor.energy_consumption",
|
||||||
|
"entity_energy_from": "sensor.energy_consumption",
|
||||||
|
"stat_cost": None,
|
||||||
|
"entity_energy_price": None,
|
||||||
|
"number_energy_price": 1,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"flow_to": [],
|
||||||
|
"cost_adjustment_day": 0,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
hass_storage[data.STORAGE_KEY] = {
|
||||||
|
"version": 1,
|
||||||
|
"data": energy_data,
|
||||||
|
}
|
||||||
|
await setup_integration(hass)
|
||||||
|
|
||||||
|
registry = er.async_get(hass)
|
||||||
|
cost_sensor_entity_id = "sensor.energy_consumption_cost"
|
||||||
|
entry = registry.async_get(cost_sensor_entity_id)
|
||||||
|
assert entry.entity_category is None
|
||||||
|
assert entry.disabled_by is None
|
||||||
|
assert entry.hidden_by == er.RegistryEntryHider.INTEGRATION
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("initial_energy,initial_cost", [(0, "0.0"), (None, "unknown")])
|
@pytest.mark.parametrize("initial_energy,initial_cost", [(0, "0.0"), (None, "unknown")])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"price_entity,fixed_price", [("sensor.energy_price", None), (None, 1)]
|
"price_entity,fixed_price", [("sensor.energy_price", None), (None, 1)]
|
||||||
|
|
|
@ -147,20 +147,13 @@ async def test_sync_request(hass_fixture, assistant_client, auth_header):
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
)
|
)
|
||||||
entity_entry3 = entity_registry.async_get_or_create(
|
entity_entry3 = entity_registry.async_get_or_create(
|
||||||
"switch",
|
|
||||||
"test",
|
|
||||||
"switch_system_id",
|
|
||||||
suggested_object_id="system_switch",
|
|
||||||
entity_category=EntityCategory.SYSTEM,
|
|
||||||
)
|
|
||||||
entity_entry4 = entity_registry.async_get_or_create(
|
|
||||||
"switch",
|
"switch",
|
||||||
"test",
|
"test",
|
||||||
"switch_hidden_integration_id",
|
"switch_hidden_integration_id",
|
||||||
suggested_object_id="hidden_integration_switch",
|
suggested_object_id="hidden_integration_switch",
|
||||||
hidden_by=er.RegistryEntryHider.INTEGRATION,
|
hidden_by=er.RegistryEntryHider.INTEGRATION,
|
||||||
)
|
)
|
||||||
entity_entry5 = entity_registry.async_get_or_create(
|
entity_entry4 = entity_registry.async_get_or_create(
|
||||||
"switch",
|
"switch",
|
||||||
"test",
|
"test",
|
||||||
"switch_hidden_user_id",
|
"switch_hidden_user_id",
|
||||||
|
@ -173,7 +166,6 @@ async def test_sync_request(hass_fixture, assistant_client, auth_header):
|
||||||
hass_fixture.states.async_set(entity_entry2.entity_id, "something_else")
|
hass_fixture.states.async_set(entity_entry2.entity_id, "something_else")
|
||||||
hass_fixture.states.async_set(entity_entry3.entity_id, "blah")
|
hass_fixture.states.async_set(entity_entry3.entity_id, "blah")
|
||||||
hass_fixture.states.async_set(entity_entry4.entity_id, "foo")
|
hass_fixture.states.async_set(entity_entry4.entity_id, "foo")
|
||||||
hass_fixture.states.async_set(entity_entry5.entity_id, "bar")
|
|
||||||
|
|
||||||
reqid = "5711642932632160983"
|
reqid = "5711642932632160983"
|
||||||
data = {"requestId": reqid, "inputs": [{"intent": "action.devices.SYNC"}]}
|
data = {"requestId": reqid, "inputs": [{"intent": "action.devices.SYNC"}]}
|
||||||
|
|
|
@ -913,7 +913,6 @@ async def test_entity_category_property(hass):
|
||||||
(
|
(
|
||||||
("config", entity.EntityCategory.CONFIG),
|
("config", entity.EntityCategory.CONFIG),
|
||||||
("diagnostic", entity.EntityCategory.DIAGNOSTIC),
|
("diagnostic", entity.EntityCategory.DIAGNOSTIC),
|
||||||
("system", entity.EntityCategory.SYSTEM),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_entity_category_schema(value, expected):
|
def test_entity_category_schema(value, expected):
|
||||||
|
@ -930,7 +929,7 @@ def test_entity_category_schema_error(value):
|
||||||
schema = vol.Schema(entity.ENTITY_CATEGORIES_SCHEMA)
|
schema = vol.Schema(entity.ENTITY_CATEGORIES_SCHEMA)
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
vol.Invalid,
|
vol.Invalid,
|
||||||
match=r"expected EntityCategory or one of 'config', 'diagnostic', 'system'",
|
match=r"expected EntityCategory or one of 'config', 'diagnostic'",
|
||||||
):
|
):
|
||||||
schema(value)
|
schema(value)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue