diff --git a/.coveragerc b/.coveragerc index 7164dd3d35e..f9e026fefda 100644 --- a/.coveragerc +++ b/.coveragerc @@ -316,7 +316,7 @@ omit = homeassistant/components/iaqualink/light.py homeassistant/components/iaqualink/sensor.py homeassistant/components/iaqualink/switch.py - homeassistant/components/icloud/device_tracker.py + homeassistant/components/icloud/* homeassistant/components/izone/climate.py homeassistant/components/izone/discovery.py homeassistant/components/izone/__init__.py diff --git a/homeassistant/components/device_tracker/services.yaml b/homeassistant/components/device_tracker/services.yaml index 938e9c8e324..51865034b00 100644 --- a/homeassistant/components/device_tracker/services.yaml +++ b/homeassistant/components/device_tracker/services.yaml @@ -24,40 +24,3 @@ see: battery: description: Battery level of device. example: '100' - -icloud_lost_iphone: - description: Service to play the lost iphone sound on an iDevice. - fields: - account_name: - description: Name of the account in the config that will be used to look for the device. This is optional, if it isn't given it will use all accounts. - example: 'bart' - device_name: - description: Name of the device that will play the sound. This is optional, if it isn't given it will play on all devices for the given account. - example: 'iphonebart' -icloud_set_interval: - description: Service to set the interval of an iDevice. - fields: - account_name: - description: Name of the account in the config that will be used to look for the device. This is optional, if it isn't given it will use all accounts. - example: 'bart' - device_name: - description: Name of the device that will get a new interval. This is optional, if it isn't given it will change the interval for all devices for the given account. - example: 'iphonebart' - interval: - description: The interval (in minutes) that the iDevice will have until the according device_tracker entity changes from zone or until this service is used again. This is optional, if it isn't given the interval of the device will revert back to the original interval based on the current state. - example: 1 -icloud_update: - description: Service to ask for an update of an iDevice. - fields: - account_name: - description: Name of the account in the config that will be used to look for the device. This is optional, if it isn't given it will use all accounts. - example: 'bart' - device_name: - description: Name of the device that will be updated. This is optional, if it isn't given it will update all devices for the given account. - example: 'iphonebart' -icloud_reset_account: - description: Service to restart an iCloud account. Helpful when not all devices are found after initializing or when you add a new device. - fields: - account_name: - description: Name of the account in the config that will be restarted. This is optional, if it isn't given it will restart all accounts. - example: 'bart' diff --git a/homeassistant/components/icloud/const.py b/homeassistant/components/icloud/const.py new file mode 100644 index 00000000000..fe8010df703 --- /dev/null +++ b/homeassistant/components/icloud/const.py @@ -0,0 +1,6 @@ +"""Constants for the iCloud component.""" +DOMAIN = "icloud" +SERVICE_LOST_IPHONE = "lost_iphone" +SERVICE_UPDATE = "update" +SERVICE_RESET_ACCOUNT = "reset_account" +SERVICE_SET_INTERVAL = "set_interval" diff --git a/homeassistant/components/icloud/device_tracker.py b/homeassistant/components/icloud/device_tracker.py index f6efb05fd08..3d9fb4715da 100644 --- a/homeassistant/components/icloud/device_tracker.py +++ b/homeassistant/components/icloud/device_tracker.py @@ -14,7 +14,6 @@ import voluptuous as vol from homeassistant.components.device_tracker import PLATFORM_SCHEMA from homeassistant.components.device_tracker.const import ( ATTR_ATTRIBUTES, - DOMAIN, ENTITY_ID_FORMAT, ) from homeassistant.components.device_tracker.legacy import DeviceScanner @@ -27,6 +26,14 @@ from homeassistant.util.async_ import run_callback_threadsafe import homeassistant.util.dt as dt_util from homeassistant.util.location import distance +from .const import ( + DOMAIN, + SERVICE_LOST_IPHONE, + SERVICE_RESET_ACCOUNT, + SERVICE_SET_INTERVAL, + SERVICE_UPDATE, +) + _LOGGER = logging.getLogger(__name__) CONF_ACCOUNTNAME = "account_name" @@ -144,7 +151,7 @@ def setup_scanner(hass, config: dict, see, discovery_info=None): ICLOUDTRACKERS[account].lost_iphone(devicename) hass.services.register( - DOMAIN, "icloud_lost_iphone", lost_iphone, schema=SERVICE_SCHEMA + DOMAIN, SERVICE_LOST_IPHONE, lost_iphone, schema=SERVICE_SCHEMA ) def update_icloud(call): @@ -155,9 +162,7 @@ def setup_scanner(hass, config: dict, see, discovery_info=None): if account in ICLOUDTRACKERS: ICLOUDTRACKERS[account].update_icloud(devicename) - hass.services.register( - DOMAIN, "icloud_update", update_icloud, schema=SERVICE_SCHEMA - ) + hass.services.register(DOMAIN, SERVICE_UPDATE, update_icloud, schema=SERVICE_SCHEMA) def reset_account_icloud(call): """Reset an iCloud account.""" @@ -167,7 +172,7 @@ def setup_scanner(hass, config: dict, see, discovery_info=None): ICLOUDTRACKERS[account].reset_account_icloud() hass.services.register( - DOMAIN, "icloud_reset_account", reset_account_icloud, schema=SERVICE_SCHEMA + DOMAIN, SERVICE_RESET_ACCOUNT, reset_account_icloud, schema=SERVICE_SCHEMA ) def setinterval(call): @@ -180,7 +185,7 @@ def setup_scanner(hass, config: dict, see, discovery_info=None): ICLOUDTRACKERS[account].setinterval(interval, devicename) hass.services.register( - DOMAIN, "icloud_set_interval", setinterval, schema=SERVICE_SCHEMA + DOMAIN, SERVICE_SET_INTERVAL, setinterval, schema=SERVICE_SCHEMA ) # Tells the bootstrapper that the component was successfully initialized diff --git a/homeassistant/components/icloud/services.yaml b/homeassistant/components/icloud/services.yaml index e69de29bb2d..7b2d3b80e84 100644 --- a/homeassistant/components/icloud/services.yaml +++ b/homeassistant/components/icloud/services.yaml @@ -0,0 +1,39 @@ +lost_iphone: + description: Service to play the lost iphone sound on an iDevice. + fields: + account_name: + description: Name of the account in the config that will be used to look for the device. This is optional, if it isn't given it will use all accounts. + example: 'bart' + device_name: + description: Name of the device that will play the sound. This is optional, if it isn't given it will play on all devices for the given account. + example: 'iphonebart' + +set_interval: + description: Service to set the interval of an iDevice. + fields: + account_name: + description: Name of the account in the config that will be used to look for the device. This is optional, if it isn't given it will use all accounts. + example: 'bart' + device_name: + description: Name of the device that will get a new interval. This is optional, if it isn't given it will change the interval for all devices for the given account. + example: 'iphonebart' + interval: + description: The interval (in minutes) that the iDevice will have until the according device_tracker entity changes from zone or until this service is used again. This is optional, if it isn't given the interval of the device will revert back to the original interval based on the current state. + example: 1 + +update: + description: Service to ask for an update of an iDevice. + fields: + account_name: + description: Name of the account in the config that will be used to look for the device. This is optional, if it isn't given it will use all accounts. + example: 'bart' + device_name: + description: Name of the device that will be updated. This is optional, if it isn't given it will update all devices for the given account. + example: 'iphonebart' + +reset_account: + description: Service to restart an iCloud account. Helpful when not all devices are found after initializing or when you add a new device. + fields: + account_name: + description: Name of the account in the config that will be restarted. This is optional, if it isn't given it will restart all accounts. + example: 'bart'