Rename config.get_config_path to config.path
parent
9b643d57f0
commit
7a7f486cb2
|
@ -63,11 +63,15 @@ class HomeAssistant(object):
|
|||
@property
|
||||
def config_dir(self):
|
||||
""" DEPRECATED 3/18/2015. Use hass.config.config_dir """
|
||||
_LOGGER.warning(
|
||||
'hass.config_dir is deprecated. Use hass.config.config_dir')
|
||||
return self.config.config_dir
|
||||
|
||||
def get_config_path(self, path):
|
||||
""" DEPRECATED 3/18/2015. Use hass.config.get_config_path """
|
||||
return self.config.get_config_path(path)
|
||||
""" DEPRECATED 3/18/2015. Use hass.config.path """
|
||||
_LOGGER.warning(
|
||||
'hass.get_config_path is deprecated. Use hass.config.path')
|
||||
return self.config.path(path)
|
||||
|
||||
def start(self):
|
||||
""" Start home assistant. """
|
||||
|
@ -854,10 +858,6 @@ class Config(object):
|
|||
# Directory that holds the configuration
|
||||
self.config_dir = os.path.join(os.getcwd(), 'config')
|
||||
|
||||
def get_config_path(self, path):
|
||||
""" Returns path to the file within the config dir. """
|
||||
return os.path.join(self.config_dir, path)
|
||||
|
||||
def auto_detect(self):
|
||||
""" Will attempt to detect config of Home Assistant. """
|
||||
# Only detect if location or temp unit missing
|
||||
|
@ -892,6 +892,10 @@ class Config(object):
|
|||
if self.time_zone is None:
|
||||
self.time_zone = info['time_zone']
|
||||
|
||||
def path(self, path):
|
||||
""" Returns path to the file within the config dir. """
|
||||
return os.path.join(self.config_dir, path)
|
||||
|
||||
def temperature(self, value, unit):
|
||||
""" Converts temperature to user preferred unit if set. """
|
||||
if not (unit and self.temperature_unit and
|
||||
|
|
|
@ -148,7 +148,7 @@ def enable_logging(hass):
|
|||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
# Log errors to a file if we have write access to file or config dir
|
||||
err_log_path = hass.config.get_config_path("home-assistant.log")
|
||||
err_log_path = hass.config.path("home-assistant.log")
|
||||
err_path_exists = os.path.isfile(err_log_path)
|
||||
|
||||
# Check if we can write to the error log if it exists or that
|
||||
|
|
|
@ -179,8 +179,7 @@ class DeviceTracker(object):
|
|||
# Write new devices to known devices file
|
||||
if not self.invalid_known_devices_file:
|
||||
|
||||
known_dev_path = self.hass.config.get_config_path(
|
||||
KNOWN_DEVICES_FILE)
|
||||
known_dev_path = self.hass.config.path(KNOWN_DEVICES_FILE)
|
||||
|
||||
try:
|
||||
# If file does not exist we will write the header too
|
||||
|
@ -215,7 +214,7 @@ class DeviceTracker(object):
|
|||
# pylint: disable=too-many-branches
|
||||
def _read_known_devices_file(self):
|
||||
""" Parse and process the known devices file. """
|
||||
known_dev_path = self.hass.config.get_config_path(KNOWN_DEVICES_FILE)
|
||||
known_dev_path = self.hass.config.path(KNOWN_DEVICES_FILE)
|
||||
|
||||
# Return if no known devices file exists
|
||||
if not os.path.isfile(known_dev_path):
|
||||
|
|
|
@ -148,7 +148,7 @@ def setup(hass, config):
|
|||
# Load built-in profiles and custom profiles
|
||||
profile_paths = [os.path.join(os.path.dirname(__file__),
|
||||
LIGHT_PROFILES_FILE),
|
||||
hass.config.get_config_path(LIGHT_PROFILES_FILE)]
|
||||
hass.config.path(LIGHT_PROFILES_FILE)]
|
||||
profiles = {}
|
||||
|
||||
for profile_path in profile_paths:
|
||||
|
|
|
@ -52,7 +52,7 @@ def setup_bridge(host, hass, add_devices_callback):
|
|||
try:
|
||||
bridge = phue.Bridge(
|
||||
host,
|
||||
config_file_path=hass.config.get_config_path(PHUE_CONFIG_FILE))
|
||||
config_file_path=hass.config.path(PHUE_CONFIG_FILE))
|
||||
except ConnectionRefusedError: # Wrong host was given
|
||||
_LOGGER.exception("Error connecting to the Hue bridge at %s", host)
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ class Recorder(threading.Thread):
|
|||
|
||||
def _setup_connection(self):
|
||||
""" Ensure database is ready to fly. """
|
||||
db_path = self.hass.get_config_path(DB_FILE)
|
||||
db_path = self.hass.config.path(DB_FILE)
|
||||
self.conn = sqlite3.connect(db_path, check_same_thread=False)
|
||||
self.conn.row_factory = sqlite3.Row
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ def setup(hass, config):
|
|||
schedule.schedule(hass)
|
||||
return True
|
||||
|
||||
with open(hass.config.get_config_path(_SCHEDULE_FILE)) as schedule_file:
|
||||
with open(hass.config.path(_SCHEDULE_FILE)) as schedule_file:
|
||||
schedule_descriptions = json.load(schedule_file)
|
||||
|
||||
for schedule_description in schedule_descriptions:
|
||||
|
|
|
@ -46,7 +46,7 @@ def prepare(hass):
|
|||
pkgutil.iter_modules(components.__path__, 'homeassistant.components.'))
|
||||
|
||||
# Look for available custom components
|
||||
custom_path = hass.config.get_config_path("custom_components")
|
||||
custom_path = hass.config.path("custom_components")
|
||||
|
||||
if os.path.isdir(custom_path):
|
||||
# Ensure we can load custom components using Pythons import
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
|||
self.hass = get_test_home_assistant()
|
||||
loader.prepare(self.hass)
|
||||
|
||||
self.known_dev_path = self.hass.get_config_path(
|
||||
self.known_dev_path = self.hass.config.path(
|
||||
device_tracker.KNOWN_DEVICES_FILE)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
|
|
|
@ -29,7 +29,7 @@ class TestLight(unittest.TestCase):
|
|||
""" Stop down stuff we started. """
|
||||
self.hass.stop()
|
||||
|
||||
user_light_file = self.hass.get_config_path(light.LIGHT_PROFILES_FILE)
|
||||
user_light_file = self.hass.config.path(light.LIGHT_PROFILES_FILE)
|
||||
|
||||
if os.path.isfile(user_light_file):
|
||||
os.remove(user_light_file)
|
||||
|
@ -218,7 +218,7 @@ class TestLight(unittest.TestCase):
|
|||
platform = loader.get_component('light.test')
|
||||
platform.init()
|
||||
|
||||
user_light_file = self.hass.get_config_path(light.LIGHT_PROFILES_FILE)
|
||||
user_light_file = self.hass.config.path(light.LIGHT_PROFILES_FILE)
|
||||
|
||||
# Setup a wrong light file
|
||||
with open(user_light_file, 'w') as user_file:
|
||||
|
@ -234,7 +234,7 @@ class TestLight(unittest.TestCase):
|
|||
platform = loader.get_component('light.test')
|
||||
platform.init()
|
||||
|
||||
user_light_file = self.hass.get_config_path(light.LIGHT_PROFILES_FILE)
|
||||
user_light_file = self.hass.config.path(light.LIGHT_PROFILES_FILE)
|
||||
|
||||
with open(user_light_file, 'w') as user_file:
|
||||
user_file.write('id,x,y,brightness\n')
|
||||
|
|
|
@ -35,10 +35,10 @@ class TestHomeAssistant(unittest.TestCase):
|
|||
def test_get_config_path(self):
|
||||
""" Test get_config_path method. """
|
||||
self.assertEqual(os.path.join(os.getcwd(), "config"),
|
||||
self.hass.config_dir)
|
||||
self.hass.config.config_dir)
|
||||
|
||||
self.assertEqual(os.path.join(os.getcwd(), "config", "test.conf"),
|
||||
self.hass.get_config_path("test.conf"))
|
||||
self.hass.config.path("test.conf"))
|
||||
|
||||
def test_block_till_stoped(self):
|
||||
""" Test if we can block till stop service is called. """
|
||||
|
|
Loading…
Reference in New Issue