diff --git a/changelog.txt b/changelog.txt index 7e3bfa43..88fef4a8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +Version 0.17.1 (2022-01-09) +- Add config option to specify storage directory + Version 0.17.1 (2022-01-09) - Fix naming for multi channel custom entities diff --git a/example.py b/example.py index a829160c..68bdc8f3 100644 --- a/example.py +++ b/example.py @@ -68,6 +68,7 @@ async def example_run(self): host=CCU_HOST, username=CCU_USERNAME, password=CCU_PASSWORD, + storage_folder="hahm", ).get_central() # For testing we set a short INIT_TIMEOUT diff --git a/example_multi.py b/example_multi.py index 6a2ebcd5..add40da1 100644 --- a/example_multi.py +++ b/example_multi.py @@ -89,6 +89,7 @@ async def example_run(self): host=CCU_HOST, username=CCU_USERNAME, password=CCU_PASSWORD, + storage_folder="hahm", ).get_central() self.central_2 = await CentralConfig( domain="hahm", @@ -98,6 +99,7 @@ async def example_run(self): host=CCU_HOST, username=CCU_USERNAME, password=CCU_PASSWORD, + storage_folder="hahm", ).get_central() # For testing we set a short INIT_TIMEOUT diff --git a/hahomematic/central_unit.py b/hahomematic/central_unit.py index 7dba21c5..039b6f29 100644 --- a/hahomematic/central_unit.py +++ b/hahomematic/central_unit.py @@ -589,6 +589,7 @@ def __init__( loop: asyncio.AbstractEventLoop, xml_rpc_server: xml_rpc.XmlRpcServer, domain: str, + storage_folder: str, name: str, host: str = LOCALHOST, username: str = DEFAULT_USERNAME, @@ -604,6 +605,7 @@ def __init__( self.loop = loop self.xml_rpc_server = xml_rpc_server self.domain = domain + self.storage_folder = storage_folder self.name = name self.host = host self.username = username @@ -646,7 +648,7 @@ def __init__( cache_dict: dict[str, Any], ): self._central = central - self._cache_dir = f"{self._central.domain}/cache" + self._cache_dir = f"{self._central.central_config.storage_folder}/cache" self._filename = f"{self._central.instance_name}_{filename}" self._cache_dict = cache_dict diff --git a/hahomematic/helpers.py b/hahomematic/helpers.py index cce4adf5..81ba5712 100644 --- a/hahomematic/helpers.py +++ b/hahomematic/helpers.py @@ -93,7 +93,16 @@ def check_or_create_directory(directory: str) -> bool: if not directory: return False if not os.path.exists(directory): - os.makedirs(directory) + try: + os.makedirs(directory) + except OSError as ose: + _LOGGER.exception( + "Helpers.check_or_create_directory: Unable to create directory %s ('%s')", + directory, + ose.strerror, + ) + return False + return True diff --git a/hahomematic/support.py b/hahomematic/support.py index 6878616b..b94af17c 100644 --- a/hahomematic/support.py +++ b/hahomematic/support.py @@ -34,7 +34,7 @@ def __init__( ): self._client = client self._central = client.central - self._domain = self._central.domain + self._storage_folder = self._central.central_config.storage_folder self._interface_id = interface_id self._device_address = device_address self._random_id = "VCU%i" % random.randint(1000000, 9999999) @@ -81,14 +81,14 @@ async def export_data(self) -> None: # Save device_descriptions for device to file. await self._save( - file_dir=f"{self._domain}/{DEVICE_DESCRIPTIONS_DIR}", + file_dir=f"{self._storage_folder}/{DEVICE_DESCRIPTIONS_DIR}", filename=filename, data=anonymize_device_descriptions, ) # Save device_descriptions for device to file. await self._save( - file_dir=f"{self._domain}/{PARAMSET_DESCRIPTIONS_DIR}", + file_dir=f"{self._storage_folder}/{PARAMSET_DESCRIPTIONS_DIR}", filename=filename, data=anonymize_paramset_descriptions, ) diff --git a/setup.py b/setup.py index 01e5ac3a..47d0ac14 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def readme(): }, PACKAGE_NAME = "hahomematic" HERE = os.path.abspath(os.path.dirname(__file__)) -VERSION = "0.17.1" +VERSION = "0.17.2" PACKAGES = find_packages(exclude=["tests", "tests.*", "dist", "build"]) diff --git a/tests/conftest.py b/tests/conftest.py index 668519ee..45c8283c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,8 +17,8 @@ logging.basicConfig(level=logging.DEBUG) CCU_HOST = "127.0.0.1" -CCU_USERNAME = None -CCU_PASSWORD = None +CCU_USERNAME = "user" +CCU_PASSWORD = "pass" GOT_DEVICES = False # content of conftest.py @@ -73,6 +73,7 @@ def systemcallback(src, *args): host=CCU_HOST, username=CCU_USERNAME, password=CCU_PASSWORD, + storage_folder="hahm", ).get_central() central_unit.callback_system_event = systemcallback client1 = await ClientConfig(