Skip to content

Commit

Permalink
Cleanup (#1644)
Browse files Browse the repository at this point in the history
* Cleanup

* Cleanup
  • Loading branch information
SukramJ authored Aug 19, 2024
1 parent 97facf2 commit c9e7955
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
11 changes: 8 additions & 3 deletions hahomematic/central/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ async def add_new_devices(
interface_id=interface_id, device_descriptions=device_descriptions
)

@measure_execution_time
async def _add_new_devices(
self, interface_id: str, device_descriptions: tuple[dict[str, Any], ...]
) -> None:
Expand All @@ -815,14 +816,18 @@ async def _add_new_devices(
# We need this to avoid adding duplicates.
known_addresses = tuple(
dev_desc[Description.ADDRESS]
for dev_desc in self.device_descriptions.get_raw_device_descriptions(interface_id)
for dev_desc in self.device_descriptions.get_raw_device_descriptions(
interface_id=interface_id
)
)
client = self._clients[interface_id]
for dev_desc in device_descriptions:
try:
self.device_descriptions.add_device_description(interface_id, dev_desc)
self.device_descriptions.add_device_description(
interface_id=interface_id, device_description=dev_desc
)
if dev_desc[Description.ADDRESS] not in known_addresses:
await client.fetch_paramset_descriptions(dev_desc)
await client.fetch_paramset_descriptions(device_description=dev_desc)
except Exception as err: # pragma: no cover
_LOGGER.error(
"ADD_NEW_DEVICES failed: %s [%s]",
Expand Down
31 changes: 15 additions & 16 deletions hahomematic/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,20 +607,19 @@ async def get_paramset_descriptions(
paramsets[address] = {}
_LOGGER.debug("GET_PARAMSET_DESCRIPTIONS for %s", address)
for paramset_key in device_description.get(Description.PARAMSETS, []):
channel_no = get_channel_no(address)
device_type = (
device_description[Description.TYPE]
if channel_no is None
else device_description[Description.PARENT_TYPE]
)
if not (
self.central.config.load_all_paramset_descriptions or load_all
) and not self.central.parameter_visibility.is_relevant_paramset(
device_type=device_type,
channel_no=channel_no,
paramset_key=paramset_key,
):
continue
if not (self.central.config.load_all_paramset_descriptions or load_all):
channel_no = get_channel_no(address)
device_type = (
device_description[Description.TYPE]
if channel_no is None
else device_description[Description.PARENT_TYPE]
)
if not self.central.parameter_visibility.is_relevant_paramset(
device_type=device_type,
channel_no=channel_no,
paramset_key=paramset_key,
):
continue
if paramset_description := await self._get_paramset_description(
address=address, paramset_key=paramset_key
):
Expand Down Expand Up @@ -712,7 +711,7 @@ async def update_paramset_descriptions(self, device_address: str) -> None:
)
return
await self.fetch_paramset_descriptions(
self.central.device_descriptions.get_device(
device_description=self.central.device_descriptions.get_device(
interface_id=self.interface_id, device_address=device_address
)
)
Expand Down Expand Up @@ -783,7 +782,7 @@ async def check_connection_availability(self, handle_ping_pong: bool) -> bool:
if handle_ping_pong and self.supports_ping_pong:
self._ping_pong_cache.handle_send_ping(ping_ts=dt_now)
calllerId = (
f"{self.interface_id}#{dt_now.strftime(DATETIME_FORMAT_MILLIS)}"
f"{self.interface_id}#{dt_now.strftime(format=DATETIME_FORMAT_MILLIS)}"
if handle_ping_pong
else self.interface_id
)
Expand Down
4 changes: 3 additions & 1 deletion hahomematic/platforms/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,9 @@ async def export_data(self) -> None:
)
paramset_descriptions: Mapping[
str, Any
] = await self._client.get_all_paramset_descriptions(tuple(device_descriptions.values()))
] = await self._client.get_all_paramset_descriptions(
device_descriptions=tuple(device_descriptions.values())
)
device_type = device_descriptions[self._device_address][Description.TYPE]
filename = f"{device_type}.json"

Expand Down

0 comments on commit c9e7955

Please sign in to comment.