2018-09-26 06:50:05 +00:00
|
|
|
"""Collection of helper methods.
|
|
|
|
|
|
|
|
All containing methods are legacy helpers that should not be used by new
|
|
|
|
components. Instead call the service directly.
|
|
|
|
"""
|
2018-09-27 21:14:09 +00:00
|
|
|
from homeassistant.components.group import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_ADD_ENTITIES,
|
|
|
|
ATTR_ENTITIES,
|
|
|
|
ATTR_OBJECT_ID,
|
|
|
|
DOMAIN,
|
|
|
|
SERVICE_REMOVE,
|
|
|
|
SERVICE_SET,
|
|
|
|
)
|
2020-02-20 16:26:41 +00:00
|
|
|
from homeassistant.const import ATTR_ICON, ATTR_NAME, SERVICE_RELOAD
|
2018-09-27 21:14:09 +00:00
|
|
|
from homeassistant.core import callback
|
2018-09-26 06:50:05 +00:00
|
|
|
from homeassistant.loader import bind_hass
|
|
|
|
|
|
|
|
|
2018-09-27 21:14:09 +00:00
|
|
|
@bind_hass
|
|
|
|
def reload(hass):
|
|
|
|
"""Reload the automation from config."""
|
|
|
|
hass.add_job(async_reload, hass)
|
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
@bind_hass
|
|
|
|
def async_reload(hass):
|
|
|
|
"""Reload the automation from config."""
|
|
|
|
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_RELOAD))
|
|
|
|
|
|
|
|
|
|
|
|
@bind_hass
|
2019-07-31 19:25:30 +00:00
|
|
|
def set_group(
|
2020-08-27 11:56:20 +00:00
|
|
|
hass,
|
|
|
|
object_id,
|
|
|
|
name=None,
|
|
|
|
entity_ids=None,
|
|
|
|
icon=None,
|
|
|
|
add=None,
|
2019-07-31 19:25:30 +00:00
|
|
|
):
|
2018-09-27 21:14:09 +00:00
|
|
|
"""Create/Update a group."""
|
|
|
|
hass.add_job(
|
2020-08-27 11:56:20 +00:00
|
|
|
async_set_group,
|
|
|
|
hass,
|
|
|
|
object_id,
|
|
|
|
name,
|
|
|
|
entity_ids,
|
|
|
|
icon,
|
|
|
|
add,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2018-09-27 21:14:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
@bind_hass
|
2019-07-31 19:25:30 +00:00
|
|
|
def async_set_group(
|
2020-08-27 11:56:20 +00:00
|
|
|
hass,
|
|
|
|
object_id,
|
|
|
|
name=None,
|
|
|
|
entity_ids=None,
|
|
|
|
icon=None,
|
|
|
|
add=None,
|
2019-07-31 19:25:30 +00:00
|
|
|
):
|
2018-09-27 21:14:09 +00:00
|
|
|
"""Create/Update a group."""
|
|
|
|
data = {
|
2019-07-31 19:25:30 +00:00
|
|
|
key: value
|
|
|
|
for key, value in [
|
2018-09-27 21:14:09 +00:00
|
|
|
(ATTR_OBJECT_ID, object_id),
|
|
|
|
(ATTR_NAME, name),
|
|
|
|
(ATTR_ENTITIES, entity_ids),
|
|
|
|
(ATTR_ICON, icon),
|
|
|
|
(ATTR_ADD_ENTITIES, add),
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
|
|
|
if value is not None
|
2018-09-27 21:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SET, data))
|
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
@bind_hass
|
|
|
|
def async_remove(hass, object_id):
|
|
|
|
"""Remove a user group."""
|
|
|
|
data = {ATTR_OBJECT_ID: object_id}
|
|
|
|
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_REMOVE, data))
|