Skip to content

Commit

Permalink
Add extended_validation marker
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ committed Dec 2, 2023
1 parent 2bd85b2 commit 246928d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ repos:
# shell.
- id: mypy
name: mypy
entry: script/run-in-env.sh mypy --enable-incomplete-feature=Unpack
entry: script/run-in-env.sh mypy
language: script
types: [python]
require_serial: true
Expand Down
26 changes: 12 additions & 14 deletions hahomematic/central/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,29 +1296,27 @@ def use_caches(self) -> bool:
"""Return if caches should be used."""
return self.start_direct is False

def check_config(self) -> None:
"""Check config."""
def check_config(self, extended_validation: bool = True) -> None:
"""Check config. Throws BaseHomematicException on failure."""
if extended_validation and IDENTIFIER_SEPARATOR in self.name:
raise HaHomematicConfigException(f"Name must not contain {IDENTIFIER_SEPARATOR}")

if not self.username:
raise HaHomematicConfigException("CHECK_CONFIG: Username must not be empty")
raise HaHomematicConfigException("Username must not be empty")
if self.password is None:
raise HaHomematicConfigException("CHECK_CONFIG: Password is required")
raise HaHomematicConfigException("Password is required")
if not check_password(self.password):
raise HaHomematicConfigException("CHECK_CONFIG: Password is not valid")
if IDENTIFIER_SEPARATOR in self.name:
raise HaHomematicConfigException(
f"CHECK_CONFIG: Name must not contain {IDENTIFIER_SEPARATOR}"
)

raise HaHomematicConfigException("Password is not valid")
check_or_create_directory(self.storage_folder)

def create_central(self) -> CentralUnit:
"""Return the central."""
def create_central(self, extended_validation: bool = True) -> CentralUnit:
"""Create the central. Throws BaseHomematicException on validation failure."""
try:
self.check_config()
self.check_config(extended_validation=extended_validation)
return CentralUnit(self)
except BaseHomematicException as bhex:
_LOGGER.warning("CREATE_CENTRAL: Not able to create a central: %s", bhex)
raise # HaHomematicException(bhex) from bhex
raise

def create_json_rpc_client(self) -> JsonRpcAioHttpClient:
"""Return the json rpc client."""
Expand Down

0 comments on commit 246928d

Please sign in to comment.