2013-12-11 08:07:30 +00:00
|
|
|
"""
|
|
|
|
This package contains components that can be plugged into Home Assistant.
|
2014-01-05 02:24:30 +00:00
|
|
|
|
|
|
|
Component design guidelines:
|
2016-03-08 16:55:57 +00:00
|
|
|
- Each component defines a constant DOMAIN that is equal to its filename.
|
|
|
|
- Each component that tracks states should create state entity names in the
|
|
|
|
format "<DOMAIN>.<OBJECT_ID>".
|
|
|
|
- Each component should publish services only under its own domain.
|
2013-12-11 08:07:30 +00:00
|
|
|
"""
|
2014-08-13 12:28:45 +00:00
|
|
|
import logging
|
2014-01-24 07:26:00 +00:00
|
|
|
|
2019-03-26 12:38:33 +00:00
|
|
|
from homeassistant.core import split_entity_id
|
2014-03-12 05:45:05 +00:00
|
|
|
|
2014-11-08 21:57:08 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2014-08-13 12:28:45 +00:00
|
|
|
|
2014-01-24 07:26:00 +00:00
|
|
|
|
2014-04-24 07:40:45 +00:00
|
|
|
def is_on(hass, entity_id=None):
|
2016-03-08 16:55:57 +00:00
|
|
|
"""Load up the module to call the is_on method.
|
|
|
|
|
|
|
|
If there is no entity id given we will check all.
|
|
|
|
"""
|
2014-04-13 19:59:45 +00:00
|
|
|
if entity_id:
|
2017-07-16 19:39:38 +00:00
|
|
|
entity_ids = hass.components.group.expand_entity_ids([entity_id])
|
2014-04-13 19:59:45 +00:00
|
|
|
else:
|
2014-11-29 07:19:59 +00:00
|
|
|
entity_ids = hass.states.entity_ids()
|
2014-01-24 07:26:00 +00:00
|
|
|
|
2017-07-06 03:02:16 +00:00
|
|
|
for ent_id in entity_ids:
|
2019-03-26 12:38:33 +00:00
|
|
|
domain = split_entity_id(ent_id)[0]
|
2014-01-24 07:26:00 +00:00
|
|
|
|
|
|
|
try:
|
2017-07-16 19:39:38 +00:00
|
|
|
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("Component %s has no is_on method.", domain)
|
|
|
|
continue
|
2014-01-24 07:26:00 +00:00
|
|
|
|
2017-07-16 19:39:38 +00:00
|
|
|
if component.is_on(ent_id):
|
|
|
|
return True
|
2014-01-24 07:26:00 +00:00
|
|
|
|
|
|
|
return False
|