mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove is_on
function from homeassistant.components
(#125104)
* Remove `is_on` method from `homeassistant.components` * Cleanup test
This commit is contained in:
parent
d68ee8dcea
commit
0c18b2e7ff
@ -6,52 +6,3 @@ Component design guidelines:
|
|||||||
format "<DOMAIN>.<OBJECT_ID>".
|
format "<DOMAIN>.<OBJECT_ID>".
|
||||||
- Each component should publish services only under its own domain.
|
- 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
|
|
||||||
|
@ -7,7 +7,6 @@ import voluptuous as vol
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from homeassistant import config
|
from homeassistant import config
|
||||||
import homeassistant.components as comps
|
|
||||||
from homeassistant.components.homeassistant import (
|
from homeassistant.components.homeassistant import (
|
||||||
ATTR_ENTRY_ID,
|
ATTR_ENTRY_ID,
|
||||||
ATTR_SAFE_MODE,
|
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:
|
async def test_turn_on_without_entities(hass: HomeAssistant) -> None:
|
||||||
"""Test turn_on method without entities."""
|
"""Test turn_on method without entities."""
|
||||||
await async_setup_component(hass, ha.DOMAIN, {})
|
await async_setup_component(hass, ha.DOMAIN, {})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user