Entity Component to no longer generate automatic groups (#23789)
This commit is contained in:
1 parent
13e6479b6e
commit
9aa02e35a7
41 files changed
+149
-377
No files matched your search
@@ -3,7 +3,6 @@ import asyncio
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import group
|
||||
from homeassistant.const import ATTR_GPS_ACCURACY, STATE_HOME
|
||||
from homeassistant.helpers import discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@@ -43,8 +42,6 @@ from .const import (
|
||||
)
|
||||
from .legacy import DeviceScanner # noqa: F401 pylint: disable=unused-import
|
||||
|
||||
ENTITY_ID_ALL_DEVICES = group.ENTITY_ID_FORMAT.format("all_devices")
|
||||
|
||||
SERVICE_SEE = "see"
|
||||
|
||||
SOURCE_TYPES = (
|
||||
@@ -97,11 +94,9 @@ SERVICE_SEE_PAYLOAD_SCHEMA = vol.Schema(
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass: HomeAssistantType, entity_id: str = None):
|
||||
def is_on(hass: HomeAssistantType, entity_id: str):
|
||||
"""Return the state if any or a specified device is home."""
|
||||
entity = entity_id or ENTITY_ID_ALL_DEVICES
|
||||
|
||||
return hass.states.is_state(entity, STATE_HOME)
|
||||
return hass.states.is_state(entity_id, STATE_HOME)
|
||||
|
||||
|
||||
def see(
|
||||
@@ -148,8 +143,6 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
||||
if setup_tasks:
|
||||
await asyncio.wait(setup_tasks)
|
||||
|
||||
tracker.async_setup_group()
|
||||
|
||||
async def async_platform_discovered(p_type, info):
|
||||
"""Load a platform."""
|
||||
platform = await setup.async_create_platform_type(hass, config, p_type, {})
|
||||
|
||||
@@ -8,15 +8,6 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant import util
|
||||
from homeassistant.components import zone
|
||||
from homeassistant.components.group import (
|
||||
ATTR_ADD_ENTITIES,
|
||||
ATTR_ENTITIES,
|
||||
ATTR_OBJECT_ID,
|
||||
ATTR_VISIBLE,
|
||||
DOMAIN as DOMAIN_GROUP,
|
||||
SERVICE_SET,
|
||||
)
|
||||
from homeassistant.components.zone import async_active_zone
|
||||
from homeassistant.config import async_log_exception, load_yaml_config_file
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
@@ -60,7 +51,6 @@ from .const import (
|
||||
)
|
||||
|
||||
YAML_DEVICES = "known_devices.yaml"
|
||||
GROUP_NAME_ALL_DEVICES = "all devices"
|
||||
EVENT_NEW_DEVICE = "device_tracker_new_device"
|
||||
|
||||
|
||||
@@ -104,7 +94,6 @@ class DeviceTracker:
|
||||
else defaults.get(CONF_TRACK_NEW, DEFAULT_TRACK_NEW)
|
||||
)
|
||||
self.defaults = defaults
|
||||
self.group = None
|
||||
self._is_updating = asyncio.Lock()
|
||||
|
||||
for dev in devices:
|
||||
@@ -230,21 +219,6 @@ class DeviceTracker:
|
||||
if device.track:
|
||||
await device.async_update_ha_state()
|
||||
|
||||
# During init, we ignore the group
|
||||
if self.group and self.track_new:
|
||||
self.hass.async_create_task(
|
||||
self.hass.async_call(
|
||||
DOMAIN_GROUP,
|
||||
SERVICE_SET,
|
||||
{
|
||||
ATTR_OBJECT_ID: util.slugify(GROUP_NAME_ALL_DEVICES),
|
||||
ATTR_VISIBLE: False,
|
||||
ATTR_NAME: GROUP_NAME_ALL_DEVICES,
|
||||
ATTR_ADD_ENTITIES: [device.entity_id],
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
self.hass.bus.async_fire(
|
||||
EVENT_NEW_DEVICE,
|
||||
{
|
||||
@@ -271,27 +245,6 @@ class DeviceTracker:
|
||||
update_config, self.hass.config.path(YAML_DEVICES), dev_id, device
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_setup_group(self):
|
||||
"""Initialize group for all tracked devices.
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
entity_ids = [dev.entity_id for dev in self.devices.values() if dev.track]
|
||||
|
||||
self.hass.async_create_task(
|
||||
self.hass.services.async_call(
|
||||
DOMAIN_GROUP,
|
||||
SERVICE_SET,
|
||||
{
|
||||
ATTR_OBJECT_ID: util.slugify(GROUP_NAME_ALL_DEVICES),
|
||||
ATTR_VISIBLE: False,
|
||||
ATTR_NAME: GROUP_NAME_ALL_DEVICES,
|
||||
ATTR_ENTITIES: entity_ids,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_stale(self, now: dt_util.dt.datetime):
|
||||
"""Update stale devices.
|
||||
@@ -489,7 +442,7 @@ class Device(RestoreEntity):
|
||||
if self.location_name:
|
||||
self._state = self.location_name
|
||||
elif self.gps is not None and self.source_type == SOURCE_TYPE_GPS:
|
||||
zone_state = async_active_zone(
|
||||
zone_state = zone.async_active_zone(
|
||||
self.hass, self.gps[0], self.gps[1], self.gps_accuracy
|
||||
)
|
||||
if zone_state is None:
|
||||
|
||||
Reference in new issue
Block a user