Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove states UI options in group integration #32021

Merged
merged 1 commit into from Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
107 changes: 3 additions & 104 deletions homeassistant/components/group/__init__.py
Expand Up @@ -30,7 +30,6 @@
)
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import make_entity_service_schema
from homeassistant.helpers.entity import Entity, async_generate_entity_id
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.event import async_track_state_change
Expand All @@ -44,26 +43,18 @@
ENTITY_ID_FORMAT = DOMAIN + ".{}"

CONF_ENTITIES = "entities"
CONF_VIEW = "view"
CONF_CONTROL = "control"
CONF_ALL = "all"

ATTR_ADD_ENTITIES = "add_entities"
ATTR_AUTO = "auto"
ATTR_CONTROL = "control"
ATTR_ENTITIES = "entities"
ATTR_OBJECT_ID = "object_id"
ATTR_ORDER = "order"
ATTR_VIEW = "view"
ATTR_VISIBLE = "visible"
ATTR_ALL = "all"

SERVICE_SET_VISIBILITY = "set_visibility"
SERVICE_SET = "set"
SERVICE_REMOVE = "remove"

CONTROL_TYPES = vol.In(["hidden", None])

_LOGGER = logging.getLogger(__name__)


Expand All @@ -76,15 +67,11 @@ def _conf_preprocess(value):


GROUP_SCHEMA = vol.All(
cv.deprecated(CONF_CONTROL, invalidation_version="0.107.0"),
cv.deprecated(CONF_VIEW, invalidation_version="0.107.0"),
vol.Schema(
{
vol.Optional(CONF_ENTITIES): vol.Any(cv.entity_ids, None),
CONF_VIEW: cv.boolean,
CONF_NAME: cv.string,
CONF_ICON: cv.icon,
CONF_CONTROL: CONTROL_TYPES,
CONF_ALL: cv.boolean,
}
),
Expand Down Expand Up @@ -257,7 +244,7 @@ async def groups_service_handler(service):

extra_arg = {
attr: service.data[attr]
for attr in (ATTR_VISIBLE, ATTR_ICON, ATTR_VIEW, ATTR_CONTROL)
for attr in (ATTR_ICON)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you're iterating over each character in the string, one comma is all the difference…

Suggested change
for attr in (ATTR_ICON)
for attr in (ATTR_ICON,)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we on top of this, to fix it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, seeing the notification just now. Adjusting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why I merged this without being addressed 🤦‍♂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before coffee ☕️ 😉

All good now 👍

if service.data.get(attr) is not None
}

Expand Down Expand Up @@ -293,22 +280,10 @@ async def groups_service_handler(service):
group.name = service.data[ATTR_NAME]
need_update = True

if ATTR_VISIBLE in service.data:
group.visible = service.data[ATTR_VISIBLE]
need_update = True

if ATTR_ICON in service.data:
group.icon = service.data[ATTR_ICON]
need_update = True

if ATTR_CONTROL in service.data:
group.control = service.data[ATTR_CONTROL]
need_update = True

if ATTR_VIEW in service.data:
group.view = service.data[ATTR_VIEW]
need_update = True

if ATTR_ALL in service.data:
group.mode = all if service.data[ATTR_ALL] else any
need_update = True
Expand All @@ -327,17 +302,11 @@ async def groups_service_handler(service):
SERVICE_SET,
locked_service_handler,
schema=vol.All(
cv.deprecated(ATTR_CONTROL, invalidation_version="0.107.0"),
cv.deprecated(ATTR_VIEW, invalidation_version="0.107.0"),
cv.deprecated(ATTR_VISIBLE, invalidation_version="0.107.0"),
vol.Schema(
{
vol.Required(ATTR_OBJECT_ID): cv.slug,
vol.Optional(ATTR_NAME): cv.string,
vol.Optional(ATTR_VIEW): cv.boolean,
vol.Optional(ATTR_ICON): cv.string,
vol.Optional(ATTR_CONTROL): CONTROL_TYPES,
vol.Optional(ATTR_VISIBLE): cv.boolean,
vol.Optional(ATTR_ALL): cv.boolean,
vol.Exclusive(ATTR_ENTITIES, "entities"): cv.entity_ids,
vol.Exclusive(ATTR_ADD_ENTITIES, "entities"): cv.entity_ids,
Expand All @@ -353,32 +322,6 @@ async def groups_service_handler(service):
schema=vol.Schema({vol.Required(ATTR_OBJECT_ID): cv.slug}),
)

async def visibility_service_handler(service):
"""Change visibility of a group."""
visible = service.data.get(ATTR_VISIBLE)

_LOGGER.warning(
"The group.set_visibility service has been deprecated and will"
"be removed in Home Assistant 0.107.0."
)

tasks = []
for group in await component.async_extract_from_service(
service, expand_group=False
):
group.visible = visible
tasks.append(group.async_update_ha_state())

if tasks:
await asyncio.wait(tasks)

hass.services.async_register(
DOMAIN,
SERVICE_SET_VISIBILITY,
visibility_service_handler,
schema=make_entity_service_schema({vol.Required(ATTR_VISIBLE): cv.boolean}),
)

return True


Expand All @@ -388,21 +331,12 @@ async def _async_process_config(hass, config, component):
name = conf.get(CONF_NAME, object_id)
entity_ids = conf.get(CONF_ENTITIES) or []
icon = conf.get(CONF_ICON)
view = conf.get(CONF_VIEW)
control = conf.get(CONF_CONTROL)
mode = conf.get(CONF_ALL)

# Don't create tasks and await them all. The order is important as
# groups get a number based on creation order.
await Group.async_create_group(
hass,
name,
entity_ids,
icon=icon,
view=view,
control=control,
object_id=object_id,
mode=mode,
hass, name, entity_ids, icon=icon, object_id=object_id, mode=mode,
)


Expand All @@ -414,10 +348,7 @@ def __init__(
hass,
name,
order=None,
visible=True,
icon=None,
view=False,
control=None,
user_defined=True,
entity_ids=None,
mode=None,
Expand All @@ -430,15 +361,12 @@ def __init__(
self._name = name
self._state = STATE_UNKNOWN
self._icon = icon
self.view = view
if entity_ids:
self.tracking = tuple(ent_id.lower() for ent_id in entity_ids)
else:
self.tracking = tuple()
self.group_on = None
self.group_off = None
self.visible = visible
self.control = control
self.user_defined = user_defined
self.mode = any
if mode:
Expand All @@ -453,26 +381,14 @@ def create_group(
name,
entity_ids=None,
user_defined=True,
visible=True,
icon=None,
view=False,
control=None,
object_id=None,
mode=None,
):
"""Initialize a group."""
return asyncio.run_coroutine_threadsafe(
Group.async_create_group(
hass,
name,
entity_ids,
user_defined,
visible,
icon,
view,
control,
object_id,
mode,
hass, name, entity_ids, user_defined, icon, object_id, mode,
),
hass.loop,
).result()
Expand All @@ -483,10 +399,7 @@ async def async_create_group(
name,
entity_ids=None,
user_defined=True,
visible=True,
icon=None,
view=False,
control=None,
object_id=None,
mode=None,
):
Expand All @@ -498,10 +411,7 @@ async def async_create_group(
hass,
name,
order=len(hass.states.async_entity_ids(DOMAIN)),
visible=visible,
icon=icon,
view=view,
control=control,
user_defined=user_defined,
entity_ids=entity_ids,
mode=mode,
Expand Down Expand Up @@ -551,23 +461,12 @@ def icon(self, value):
"""Set Icon for group."""
self._icon = value

@property
def hidden(self):
"""If group should be hidden or not."""
if self.visible and not self.view:
return False
return True

@property
def state_attributes(self):
"""Return the state attributes for the group."""
data = {ATTR_ENTITY_ID: self.tracking, ATTR_ORDER: self._order}
if not self.user_defined:
data[ATTR_AUTO] = True
if self.view:
data[ATTR_VIEW] = True
if self.control:
data[ATTR_CONTROL] = self.control
return data

@property
Expand Down
28 changes: 4 additions & 24 deletions homeassistant/components/group/services.yaml
Expand Up @@ -3,37 +3,18 @@
reload:
description: Reload group configuration.

set_visibility:
description: Hide or show a group.
fields:
entity_id:
description: Name(s) of entities to set value.
example: 'group.travel'
visible:
description: True if group should be shown or False if it should be hidden.
example: True

set:
description: Create/Update a user group.
fields:
object_id:
description: Group id and part of entity id.
example: 'test_group'
example: "test_group"
name:
description: Name of group
example: 'My test group'
view:
description: Boolean for if the group is a view.
example: True
example: "My test group"
icon:
description: Name of icon for the group.
example: 'mdi:camera'
control:
description: Value for control the group control.
example: 'hidden'
visible:
description: If the group is visible on UI.
example: True
example: "mdi:camera"
entities:
description: List of all members in the group. Not compatible with 'delta'.
example: domain.entity_id1, domain.entity_id2
Expand All @@ -49,5 +30,4 @@ remove:
fields:
object_id:
description: Group id and part of entity id.
example: 'test_group'

example: "test_group"
47 changes: 4 additions & 43 deletions tests/components/group/common.py
Expand Up @@ -5,17 +5,13 @@
"""
from homeassistant.components.group import (
ATTR_ADD_ENTITIES,
ATTR_CONTROL,
ATTR_ENTITIES,
ATTR_OBJECT_ID,
ATTR_VIEW,
ATTR_VISIBLE,
DOMAIN,
SERVICE_REMOVE,
SERVICE_SET,
SERVICE_SET_VISIBILITY,
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_ICON, ATTR_NAME, SERVICE_RELOAD
from homeassistant.const import ATTR_ICON, ATTR_NAME, SERVICE_RELOAD
from homeassistant.core import callback
from homeassistant.loader import bind_hass

Expand All @@ -35,43 +31,18 @@ def async_reload(hass):

@bind_hass
def set_group(
hass,
object_id,
name=None,
entity_ids=None,
visible=None,
icon=None,
view=None,
control=None,
add=None,
hass, object_id, name=None, entity_ids=None, icon=None, add=None,
):
"""Create/Update a group."""
hass.add_job(
async_set_group,
hass,
object_id,
name,
entity_ids,
visible,
icon,
view,
control,
add,
async_set_group, hass, object_id, name, entity_ids, icon, add,
)


@callback
@bind_hass
def async_set_group(
hass,
object_id,
name=None,
entity_ids=None,
visible=None,
icon=None,
view=None,
control=None,
add=None,
hass, object_id, name=None, entity_ids=None, icon=None, add=None,
):
"""Create/Update a group."""
data = {
Expand All @@ -80,10 +51,7 @@ def async_set_group(
(ATTR_OBJECT_ID, object_id),
(ATTR_NAME, name),
(ATTR_ENTITIES, entity_ids),
(ATTR_VISIBLE, visible),
(ATTR_ICON, icon),
(ATTR_VIEW, view),
(ATTR_CONTROL, control),
(ATTR_ADD_ENTITIES, add),
]
if value is not None
Expand All @@ -98,10 +66,3 @@ 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))


@bind_hass
def set_visibility(hass, entity_id=None, visible=True):
"""Hide or shows a group."""
data = {ATTR_ENTITY_ID: entity_id, ATTR_VISIBLE: visible}
hass.services.call(DOMAIN, SERVICE_SET_VISIBILITY, data)