mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Deprecate homeassistant.components.is_on
function (#111891)
This commit is contained in:
parent
7e0aac3feb
commit
d4ae4a9cd0
@ -12,6 +12,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant, split_entity_id
|
from homeassistant.core import HomeAssistant, split_entity_id
|
||||||
|
from homeassistant.helpers.frame import report
|
||||||
from homeassistant.helpers.group import expand_entity_ids
|
from homeassistant.helpers.group import expand_entity_ids
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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.
|
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:
|
if entity_id:
|
||||||
entity_ids = expand_entity_ids(hass, [entity_id])
|
entity_ids = expand_entity_ids(hass, [entity_id])
|
||||||
else:
|
else:
|
||||||
|
@ -136,10 +136,11 @@ class TestComponentsCore(unittest.TestCase):
|
|||||||
|
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
"""Test is_on method."""
|
"""Test is_on method."""
|
||||||
assert comps.is_on(self.hass, "light.Bowl")
|
with pytest.raises(
|
||||||
assert not comps.is_on(self.hass, "light.Ceiling")
|
RuntimeError,
|
||||||
assert comps.is_on(self.hass)
|
match="Detected code that uses homeassistant.components.is_on. This is deprecated and will stop working",
|
||||||
assert not comps.is_on(self.hass, "non_existing.entity")
|
):
|
||||||
|
assert comps.is_on(self.hass, "light.Bowl")
|
||||||
|
|
||||||
def test_turn_on_without_entities(self):
|
def test_turn_on_without_entities(self):
|
||||||
"""Test turn_on method without entities."""
|
"""Test turn_on method without entities."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user