Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Provide functionality to keep track of devices."""
2 
3 from __future__ import annotations
4 
5 from functools import partial
6 
7 from homeassistant.const import ATTR_GPS_ACCURACY, STATE_HOME # noqa: F401
8 from homeassistant.core import HomeAssistant
10  all_with_deprecated_constants,
11  check_if_deprecated_constant,
12  dir_with_deprecated_constants,
13 )
14 from homeassistant.helpers.typing import ConfigType
15 from homeassistant.loader import bind_hass
16 
17 from .config_entry import ( # noqa: F401
18  ScannerEntity,
19  ScannerEntityDescription,
20  TrackerEntity,
21  TrackerEntityDescription,
22  async_setup_entry,
23  async_unload_entry,
24 )
25 from .const import ( # noqa: F401
26  _DEPRECATED_SOURCE_TYPE_BLUETOOTH,
27  _DEPRECATED_SOURCE_TYPE_BLUETOOTH_LE,
28  _DEPRECATED_SOURCE_TYPE_GPS,
29  _DEPRECATED_SOURCE_TYPE_ROUTER,
30  ATTR_ATTRIBUTES,
31  ATTR_BATTERY,
32  ATTR_DEV_ID,
33  ATTR_GPS,
34  ATTR_HOST_NAME,
35  ATTR_IP,
36  ATTR_LOCATION_NAME,
37  ATTR_MAC,
38  ATTR_SOURCE_TYPE,
39  CONF_CONSIDER_HOME,
40  CONF_NEW_DEVICE_DEFAULTS,
41  CONF_SCAN_INTERVAL,
42  CONF_TRACK_NEW,
43  CONNECTED_DEVICE_REGISTERED,
44  DEFAULT_CONSIDER_HOME,
45  DEFAULT_TRACK_NEW,
46  DOMAIN,
47  ENTITY_ID_FORMAT,
48  SCAN_INTERVAL,
49  SourceType,
50 )
51 from .legacy import ( # noqa: F401
52  PLATFORM_SCHEMA,
53  PLATFORM_SCHEMA_BASE,
54  SERVICE_SEE,
55  SERVICE_SEE_PAYLOAD_SCHEMA,
56  SOURCE_TYPES,
57  AsyncSeeCallback,
58  DeviceScanner,
59  SeeCallback,
60  async_setup_integration as async_setup_legacy_integration,
61  see,
62 )
63 
64 
65 @bind_hass
66 def is_on(hass: HomeAssistant, entity_id: str) -> bool:
67  """Return the state if any or a specified device is home."""
68  return hass.states.is_state(entity_id, STATE_HOME)
69 
70 
71 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
72  """Set up the device tracker."""
73  async_setup_legacy_integration(hass, config)
74  return True
75 
76 
77 # As we import deprecated constants from the const module, we need to add these two functions
78 # otherwise this module will be logged for using deprecated constants and not the custom component
79 # These can be removed if no deprecated constant are in this module anymore
80 __getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
81 __dir__ = partial(
82  dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
83 )
84 __all__ = all_with_deprecated_constants(globals())
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:71
bool is_on(HomeAssistant hass, str entity_id)
Definition: __init__.py:66
list[str] all_with_deprecated_constants(dict[str, Any] module_globals)
Definition: deprecation.py:356