From d4ae4a9cd0a72c542f3ca8b12815c872bfa604f2 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Wed, 13 Mar 2024 17:21:00 +0100 Subject: [PATCH] Deprecate `homeassistant.components.is_on` function (#111891) --- homeassistant/components/__init__.py | 10 ++++++++++ tests/components/homeassistant/test_init.py | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/__init__.py b/homeassistant/components/__init__.py index 6a3d12fec5e..030e23628d6 100644 --- a/homeassistant/components/__init__.py +++ b/homeassistant/components/__init__.py @@ -12,6 +12,7 @@ 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__) @@ -22,6 +23,15 @@ def is_on(hass: HomeAssistant, entity_id: str | None = None) -> bool: 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: diff --git a/tests/components/homeassistant/test_init.py b/tests/components/homeassistant/test_init.py index 2294e7a8f75..faa2f34d33c 100644 --- a/tests/components/homeassistant/test_init.py +++ b/tests/components/homeassistant/test_init.py @@ -136,10 +136,11 @@ class TestComponentsCore(unittest.TestCase): def test_is_on(self): """Test is_on method.""" - assert comps.is_on(self.hass, "light.Bowl") - assert not comps.is_on(self.hass, "light.Ceiling") - assert comps.is_on(self.hass) - assert not comps.is_on(self.hass, "non_existing.entity") + with pytest.raises( + RuntimeError, + match="Detected code that uses homeassistant.components.is_on. This is deprecated and will stop working", + ): + assert comps.is_on(self.hass, "light.Bowl") def test_turn_on_without_entities(self): """Test turn_on method without entities."""