1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00
ha-core/homeassistant/components/device_tracker/__init__.py
Marc Mueller 2b1e1365fd
Add StrEnum for device_tracker SourceType (#75892)
Add StrEnum for device_tracker SourceType
2022-07-29 13:09:03 +02:00

64 lines
1.7 KiB
Python

"""Provide functionality to keep track of devices."""
from __future__ import annotations
from homeassistant.const import ATTR_GPS_ACCURACY, STATE_HOME # noqa: F401
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass
from .config_entry import async_setup_entry, async_unload_entry # noqa: F401
from .const import ( # noqa: F401
ATTR_ATTRIBUTES,
ATTR_BATTERY,
ATTR_DEV_ID,
ATTR_GPS,
ATTR_HOST_NAME,
ATTR_LOCATION_NAME,
ATTR_MAC,
ATTR_SOURCE_TYPE,
CONF_CONSIDER_HOME,
CONF_NEW_DEVICE_DEFAULTS,
CONF_SCAN_INTERVAL,
CONF_TRACK_NEW,
DOMAIN,
ENTITY_ID_FORMAT,
SOURCE_TYPE_BLUETOOTH,
SOURCE_TYPE_BLUETOOTH_LE,
SOURCE_TYPE_GPS,
SOURCE_TYPE_ROUTER,
SourceType,
)
from .legacy import ( # noqa: F401
PLATFORM_SCHEMA,
PLATFORM_SCHEMA_BASE,
SERVICE_SEE,
SERVICE_SEE_PAYLOAD_SCHEMA,
SOURCE_TYPES,
AsyncSeeCallback,
DeviceScanner,
SeeCallback,
async_setup_integration as async_setup_legacy_integration,
see,
)
@bind_hass
def is_on(hass: HomeAssistant, entity_id: str) -> bool:
"""Return the state if any or a specified device is home."""
return hass.states.is_state(entity_id, STATE_HOME)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the device tracker."""
# We need to add the component here break the deadlock
# when setting up integrations from config entries as
# they would otherwise wait for the device tracker to be
# setup and thus the config entries would not be able to
# setup their platforms.
hass.config.components.add(DOMAIN)
await async_setup_legacy_integration(hass, config)
return True