From 0c18b2e7ffe069024cbce77fc011b0b588164673 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Tue, 3 Sep 2024 06:57:25 +0200 Subject: [PATCH] Remove `is_on` function from `homeassistant.components` (#125104) * Remove `is_on` method from `homeassistant.components` * Cleanup test --- homeassistant/components/__init__.py | 49 --------------------- tests/components/homeassistant/test_init.py | 10 ----- 2 files changed, 59 deletions(-) diff --git a/homeassistant/components/__init__.py b/homeassistant/components/__init__.py index 030e23628d6..d01f51c3951 100644 --- a/homeassistant/components/__init__.py +++ b/homeassistant/components/__init__.py @@ -6,52 +6,3 @@ Component design guidelines: format ".". - Each component should publish services only under its own domain. """ - -from __future__ import annotations - -import logging - -from homeassistant.core import HomeAssistant, split_entity_id -from homeassistant.helpers.frame import report -from homeassistant.helpers.group import expand_entity_ids - -_LOGGER = logging.getLogger(__name__) - - -def is_on(hass: HomeAssistant, entity_id: str | None = None) -> bool: - """Load up the module to call the is_on method. - - If there is no entity id given we will check all. - """ - report( - ( - "uses homeassistant.components.is_on." - " This is deprecated and will stop working in Home Assistant 2024.9, it" - " should be updated to use the function of the platform directly." - ), - error_if_core=True, - ) - - if entity_id: - entity_ids = expand_entity_ids(hass, [entity_id]) - else: - entity_ids = hass.states.entity_ids() - - for ent_id in entity_ids: - domain = split_entity_id(ent_id)[0] - - try: - component = getattr(hass.components, domain) - - except ImportError: - _LOGGER.error("Failed to call %s.is_on: component not found", domain) - continue - - if not hasattr(component, "is_on"): - _LOGGER.warning("Integration %s has no is_on method", domain) - continue - - if component.is_on(ent_id): - return True - - return False diff --git a/tests/components/homeassistant/test_init.py b/tests/components/homeassistant/test_init.py index a0902fe62df..a66d13e5ffe 100644 --- a/tests/components/homeassistant/test_init.py +++ b/tests/components/homeassistant/test_init.py @@ -7,7 +7,6 @@ import voluptuous as vol import yaml from homeassistant import config -import homeassistant.components as comps from homeassistant.components.homeassistant import ( ATTR_ENTRY_ID, ATTR_SAFE_MODE, @@ -46,15 +45,6 @@ from tests.common import ( ) -async def test_is_on(hass: HomeAssistant) -> None: - """Test is_on method.""" - with pytest.raises( - RuntimeError, - match="Detected code that uses homeassistant.components.is_on. This is deprecated and will stop working", - ): - assert comps.is_on(hass, "light.Bowl") - - async def test_turn_on_without_entities(hass: HomeAssistant) -> None: """Test turn_on method without entities.""" await async_setup_component(hass, ha.DOMAIN, {})