Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
79c92cd0
Commit
79c92cd0
authored
9 years ago
by
Paulus Schoutsen
Browse files
Options
Downloads
Plain Diff
Merge branch 'pr/616' into dev
parents
946f6cab
254889e3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/device_tracker/icloud.py
+89
-0
89 additions, 0 deletions
homeassistant/components/device_tracker/icloud.py
requirements_all.txt
+3
-0
3 additions, 0 deletions
requirements_all.txt
with
92 additions
and
0 deletions
homeassistant/components/device_tracker/icloud.py
0 → 100644
+
89
−
0
View file @
79c92cd0
"""
homeassistant.components.device_tracker.icloud
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Device tracker platform that supports scanning iCloud devices.
It does require that your device has beend registered with Find My iPhone.
Note: that this may cause battery drainage as it wakes up your device to
get the current location.
Note: You may receive an email from Apple stating that someone has logged
into your account.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.icloud/
"""
import
logging
import
re
from
homeassistant.const
import
CONF_USERNAME
,
CONF_PASSWORD
from
homeassistant.helpers.event
import
track_utc_time_change
SCAN_INTERVAL
=
1800
_LOGGER
=
logging
.
getLogger
(
__name__
)
REQUIREMENTS
=
[
'
https://github.com/picklepete/pyicloud/archive/
'
'
80f6cd6decc950514b8dc43b30c5bded81b34d5f.zip
'
'
#pyicloud==0.8.0
'
]
def
setup_scanner
(
hass
,
config
,
see
):
"""
Set up the iCloud Scanner
"""
from
pyicloud
import
PyiCloudService
from
pyicloud.exceptions
import
PyiCloudFailedLoginException
from
pyicloud.exceptions
import
PyiCloudNoDevicesException
# Get the username and password from the configuration
username
=
config
[
CONF_USERNAME
]
password
=
config
[
CONF_PASSWORD
]
try
:
_LOGGER
.
info
(
'
Logging into iCloud Account
'
)
# Attempt the login to iCloud
api
=
PyiCloudService
(
username
,
password
,
verify
=
True
)
except
PyiCloudFailedLoginException
as
error
:
_LOGGER
.
exception
(
'
Error logging into iCloud Service: %s
'
%
error
)
return
def
update_icloud
(
now
):
"""
Authenticate against iCloud and scan for devices.
"""
try
:
# The session timeouts if we are not using it so we
# have to re-authenticate. This will send an email.
api
.
authenticate
()
# Loop through every device registered with the iCloud account
for
device
in
api
.
devices
:
status
=
device
.
status
()
location
=
device
.
location
()
# If the device has a location add it. If not do nothing
if
location
:
see
(
dev_id
=
re
.
sub
(
r
"
(\s|\W|
'
)
"
,
''
,
status
[
'
name
'
]),
host_name
=
status
[
'
name
'
],
gps
=
(
location
[
'
latitude
'
],
location
[
'
longitude
'
]),
battery
=
status
[
'
batteryLevel
'
]
*
100
,
gps_accuracy
=
location
[
'
horizontalAccuracy
'
]
)
else
:
# No location found for the device so continue
continue
except
PyiCloudNoDevicesException
:
_LOGGER
.
info
(
'
No iCloud Devices found!
'
)
track_utc_time_change
(
hass
,
update_icloud
,
second
=
range
(
0
,
60
,
SCAN_INTERVAL
)
)
This diff is collapsed.
Click to expand it.
requirements_all.txt
+
3
−
0
View file @
79c92cd0
...
...
@@ -177,3 +177,6 @@ https://github.com/persandstrom/python-verisure/archive/9873c4527f01b1ba1f72ae60
# homeassistant.components.zwave
pydispatcher==2.0.5
# homeassistant.sensor.icloud
https://github.com/picklepete/pyicloud/archive/80f6cd6decc950514b8dc43b30c5bded81b34d5f.zip#pyicloud==0.8.0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment