Remove `is_on` function from `homeassistant.components` (#125104)

* Remove `is_on` method from `homeassistant.components`

* Cleanup test
pull/125118/head
Jan Bouwhuis 2024-09-03 06:57:25 +02:00 committed by GitHub
parent d68ee8dcea
commit 0c18b2e7ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 59 deletions

View File

@ -6,52 +6,3 @@ Component design guidelines:
format "<DOMAIN>.<OBJECT_ID>".
- 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

View File

@ -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, {})