Skip to content

Commit

Permalink
Add config option to specify storage directory (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored Jan 10, 2022
1 parent d861815 commit a413f68
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions example_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion hahomematic/central_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion hahomematic/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions hahomematic/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a413f68

Please sign in to comment.