mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Update icloud to respect track=false. (#2640)
This commit is contained in:
parent
cdb6f3717d
commit
4f89230251
@ -11,7 +11,8 @@ from homeassistant.const import (CONF_PASSWORD, CONF_USERNAME,
|
|||||||
EVENT_HOMEASSISTANT_START)
|
EVENT_HOMEASSISTANT_START)
|
||||||
from homeassistant.helpers.event import track_utc_time_change
|
from homeassistant.helpers.event import track_utc_time_change
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
from homeassistant.components.device_tracker import PLATFORM_SCHEMA
|
from homeassistant.components.device_tracker import (ENTITY_ID_FORMAT,
|
||||||
|
PLATFORM_SCHEMA)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -55,6 +56,8 @@ def setup_scanner(hass, config, see):
|
|||||||
api.authenticate()
|
api.authenticate()
|
||||||
_LOGGER.info("Authenticate against iCloud")
|
_LOGGER.info("Authenticate against iCloud")
|
||||||
|
|
||||||
|
seen_devices = {}
|
||||||
|
|
||||||
def update_icloud(now):
|
def update_icloud(now):
|
||||||
"""Authenticate against iCloud and scan for devices."""
|
"""Authenticate against iCloud and scan for devices."""
|
||||||
try:
|
try:
|
||||||
@ -62,11 +65,20 @@ def setup_scanner(hass, config, see):
|
|||||||
# Loop through every device registered with the iCloud account
|
# Loop through every device registered with the iCloud account
|
||||||
for device in api.devices:
|
for device in api.devices:
|
||||||
status = device.status()
|
status = device.status()
|
||||||
|
dev_id = slugify(status['name'].replace(' ', '', 99))
|
||||||
|
|
||||||
|
# An entity will not be created by see() when track=false in
|
||||||
|
# 'known_devices.yaml', but we need to see() it at least once
|
||||||
|
entity = hass.states.get(ENTITY_ID_FORMAT.format(dev_id))
|
||||||
|
if entity is None and dev_id in seen_devices:
|
||||||
|
continue
|
||||||
|
seen_devices[dev_id] = True
|
||||||
|
|
||||||
location = device.location()
|
location = device.location()
|
||||||
# If the device has a location add it. If not do nothing
|
# If the device has a location add it. If not do nothing
|
||||||
if location:
|
if location:
|
||||||
see(
|
see(
|
||||||
dev_id=slugify(status['name'].replace(' ', '', 99)),
|
dev_id=dev_id,
|
||||||
host_name=status['name'],
|
host_name=status['name'],
|
||||||
gps=(location['latitude'], location['longitude']),
|
gps=(location['latitude'], location['longitude']),
|
||||||
battery=status['batteryLevel']*100,
|
battery=status['batteryLevel']*100,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user