<s> """<STR_LIT>""" <EOL> import logging <EOL> import re <EOL> from homeassistant . const import CONF_PASSWORD , CONF_USERNAME <EOL> from homeassistant . helpers . event import track_utc_time_change <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> REQUIREMENTS = [ '<STR_LIT>' ] <EOL> CONF_INTERVAL = '<STR_LIT>' <EOL> DEFAULT_INTERVAL = <NUM_LIT:8> <EOL> def setup_scanner ( hass , config , see ) : <EOL> """<STR_LIT>""" <EOL> from pyicloud import PyiCloudService <EOL> from pyicloud . exceptions import PyiCloudFailedLoginException <EOL> from pyicloud . exceptions import PyiCloudNoDevicesException <EOL> username = config . get ( CONF_USERNAME ) <EOL> password = config . get ( CONF_PASSWORD ) <EOL> if username is None or password is None : <EOL> _LOGGER . error ( '<STR_LIT>' ) <EOL> return False <EOL> try : <EOL> _LOGGER . info ( '<STR_LIT>' ) <EOL> api = PyiCloudService ( username , <EOL> password , <EOL> verify = True ) <EOL> except PyiCloudFailedLoginException as error : <EOL> _LOGGER . exception ( '<STR_LIT>' , error ) <EOL> return False <EOL> def keep_alive ( now ) : <EOL> """<STR_LIT>""" <EOL> api . authenticate ( ) <EOL> _LOGGER . info ( "<STR_LIT>" ) <EOL> track_utc_time_change ( hass , keep_alive , second = <NUM_LIT:0> ) <EOL> def update_icloud ( now ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> api . authenticate ( ) <EOL> for device in api . devices : <EOL> status = device . status ( ) <EOL> location = device . location ( ) <EOL> if location : <EOL> see ( <EOL> dev_id = re . sub ( r"<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> status [ '<STR_LIT:name>' ] ) , <EOL> host_name = status [ '<STR_LIT:name>' ] , <EOL> gps = ( location [ '<STR_LIT>' ] , location [ '<STR_LIT>' ] ) , <EOL> battery = status [ '<STR_LIT>' ] * <NUM_LIT:100> , <EOL> gps_accuracy = location [ '<STR_LIT>' ] <EOL> ) <EOL> else : <EOL> continue <EOL> except PyiCloudNoDevicesException : <EOL> _LOGGER . info ( '<STR_LIT>' ) <EOL> track_utc_time_change ( <EOL> hass , update_icloud , <EOL> minute = range ( <NUM_LIT:0> , <NUM_LIT> , config . get ( CONF_INTERVAL , DEFAULT_INTERVAL ) ) , <EOL> second = <NUM_LIT:0> <EOL> ) <EOL> return True </s>
