From fde0ce199788706ae73a5e9c9d6347b5b538721e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 6 Mar 2015 00:04:32 -0800 Subject: [PATCH] Remove CONF_TYPE and platform_devices_from_config --- .../components/device_tracker/__init__.py | 14 +--- homeassistant/const.py | 3 - homeassistant/helpers/__init__.py | 69 +------------------ tests/test_component_light.py | 8 +-- 4 files changed, 7 insertions(+), 87 deletions(-) diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index d46c5cffd0f..4ab72eaba6b 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -16,7 +16,7 @@ import homeassistant.util as util from homeassistant.const import ( STATE_HOME, STATE_NOT_HOME, ATTR_ENTITY_PICTURE, ATTR_FRIENDLY_NAME, - CONF_PLATFORM, CONF_TYPE) + CONF_PLATFORM) from homeassistant.components import group DOMAIN = "device_tracker" @@ -53,21 +53,11 @@ def is_on(hass, entity_id=None): def setup(hass, config): """ Sets up the device tracker. """ - # CONF_TYPE is deprecated for CONF_PLATOFRM. We keep supporting it for now. - if not (validate_config(config, {DOMAIN: [CONF_PLATFORM]}, _LOGGER) or - validate_config(config, {DOMAIN: [CONF_TYPE]}, _LOGGER)): - + if not validate_config(config, {DOMAIN: [CONF_PLATFORM]}, _LOGGER): return False tracker_type = config[DOMAIN].get(CONF_PLATFORM) - if tracker_type is None: - tracker_type = config[DOMAIN][CONF_TYPE] - - _LOGGER.warning(( - "Please update your config for %s to use 'platform' " - "instead of 'type'"), tracker_type) - tracker_implementation = get_component( 'device_tracker.{}'.format(tracker_type)) diff --git a/homeassistant/const.py b/homeassistant/const.py index 6bce196437f..e90f1338b83 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -9,9 +9,6 @@ DEVICE_DEFAULT_NAME = "Unnamed Device" CONF_LATITUDE = "latitude" CONF_LONGITUDE = "longitude" -# This one is deprecated. Use platform instead. -CONF_TYPE = "type" - CONF_PLATFORM = "platform" CONF_HOST = "host" CONF_HOSTS = "hosts" diff --git a/homeassistant/helpers/__init__.py b/homeassistant/helpers/__init__.py index 5db4a8b47e7..d156e321cda 100644 --- a/homeassistant/helpers/__init__.py +++ b/homeassistant/helpers/__init__.py @@ -4,8 +4,7 @@ Helper methods for components within Home Assistant. from datetime import datetime from homeassistant.loader import get_component -from homeassistant.const import ( - ATTR_ENTITY_ID, CONF_PLATFORM, CONF_TYPE, DEVICE_DEFAULT_NAME) +from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM from homeassistant.util import ensure_unique_string, slugify # Deprecated 3/5/2015 - Moved to homeassistant.helpers.device @@ -102,15 +101,6 @@ def config_per_platform(config, domain, logger): platform_type = platform_config.get(CONF_PLATFORM) - # DEPRECATED, still supported for now. - if platform_type is None: - platform_type = platform_config.get(CONF_TYPE) - - if platform_type is not None: - logger.warning(( - 'Please update your config for {}.{} to use "platform" ' - 'instead of "type"').format(domain, platform_type)) - if platform_type is None: logger.warning('No platform specified for %s', config_key) break @@ -119,60 +109,3 @@ def config_per_platform(config, domain, logger): found += 1 config_key = "{} {}".format(domain, found) - - -def platform_devices_from_config(config, domain, hass, - entity_id_format, logger): - - """ Parses the config for specified domain. - Loads different platforms and retrieve domains. """ - devices = [] - - for p_type, p_config in config_per_platform(config, domain, logger): - platform = get_component('{}.{}'.format(domain, p_type)) - - if platform is None: - logger.error("Unknown %s type specified: %s", domain, p_type) - - else: - try: - p_devices = platform.get_devices(hass, p_config) - except AttributeError: - # DEPRECATED, still supported for now - logger.warning( - 'Platform %s should migrate to use the method get_devices', - p_type) - - if domain == 'light': - p_devices = platform.get_lights(hass, p_config) - elif domain == 'switch': - p_devices = platform.get_switches(hass, p_config) - else: - raise - - logger.info("Found %d %s %ss", len(p_devices), p_type, domain) - - devices.extend(p_devices) - - # Setup entity IDs for each device - device_dict = {} - - no_name_count = 0 - - for device in devices: - device.hass = hass - - # Get the name or set to default if none given - name = device.name or DEVICE_DEFAULT_NAME - - if name == DEVICE_DEFAULT_NAME: - no_name_count += 1 - name = "{} {}".format(domain, no_name_count) - - entity_id = generate_entity_id( - entity_id_format, name, device_dict.keys()) - - device.entity_id = entity_id - device_dict[entity_id] = device - - return device_dict diff --git a/tests/test_component_light.py b/tests/test_component_light.py index eeb7a53e4f1..c5ccb687e07 100644 --- a/tests/test_component_light.py +++ b/tests/test_component_light.py @@ -11,7 +11,7 @@ import os import homeassistant.loader as loader import homeassistant.util as util from homeassistant.const import ( - ATTR_ENTITY_ID, STATE_ON, STATE_OFF, CONF_TYPE, + ATTR_ENTITY_ID, STATE_ON, STATE_OFF, CONF_PLATFORM, SERVICE_TURN_ON, SERVICE_TURN_OFF) import homeassistant.components.light as light @@ -101,7 +101,7 @@ class TestLight(unittest.TestCase): platform.init() self.assertTrue( - light.setup(self.hass, {light.DOMAIN: {CONF_TYPE: 'test'}})) + light.setup(self.hass, {light.DOMAIN: {CONF_PLATFORM: 'test'}})) dev1, dev2, dev3 = platform.DEVICES @@ -226,7 +226,7 @@ class TestLight(unittest.TestCase): user_file.write('I,WILL,NOT,WORK\n') self.assertFalse(light.setup( - self.hass, {light.DOMAIN: {CONF_TYPE: 'test'}} + self.hass, {light.DOMAIN: {CONF_PLATFORM: 'test'}} )) def test_light_profiles(self): @@ -241,7 +241,7 @@ class TestLight(unittest.TestCase): user_file.write('test,.4,.6,100\n') self.assertTrue(light.setup( - self.hass, {light.DOMAIN: {CONF_TYPE: 'test'}} + self.hass, {light.DOMAIN: {CONF_PLATFORM: 'test'}} )) dev1, dev2, dev3 = platform.DEVICES