Skip to content

Commit 07c1976

Browse files
authored
improve debug logging (home-assistant#47858)
1 parent 8b3dccb commit 07c1976

File tree

1 file changed

+59
-26
lines changed

1 file changed

+59
-26
lines changed

homeassistant/components/synology_dsm/__init__.py

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ def _async_migrator(entity_entry: entity_registry.RegistryEntry):
191191
try:
192192
await api.async_setup()
193193
except (SynologyDSMLoginFailedException, SynologyDSMRequestException) as err:
194-
_LOGGER.debug("Unable to connect to DSM during setup: %s", err)
194+
_LOGGER.debug(
195+
"Unable to connect to DSM '%s' during setup: %s", entry.unique_id, err
196+
)
195197
raise ConfigEntryNotReady from err
196198

197199
hass.data.setdefault(DOMAIN, {})
@@ -401,7 +403,8 @@ async def async_setup(self):
401403
self.dsm.apis.get(SynoSurveillanceStation.CAMERA_API_KEY)
402404
)
403405
_LOGGER.debug(
404-
"State of Surveillance_station during setup:%s",
406+
"State of Surveillance_station during setup of '%s': %s",
407+
self._entry.unique_id,
405408
self._with_surveillance_station,
406409
)
407410

@@ -413,19 +416,15 @@ async def async_setup(self):
413416
@callback
414417
def subscribe(self, api_key, unique_id):
415418
"""Subscribe an entity to API fetches."""
416-
_LOGGER.debug(
417-
"Subscribe new entity - api_key:%s, unique_id:%s", api_key, unique_id
418-
)
419+
_LOGGER.debug("Subscribe new entity: %s", unique_id)
419420
if api_key not in self._fetching_entities:
420421
self._fetching_entities[api_key] = set()
421422
self._fetching_entities[api_key].add(unique_id)
422423

423424
@callback
424425
def unsubscribe() -> None:
425426
"""Unsubscribe an entity from API fetches (when disable)."""
426-
_LOGGER.debug(
427-
"Unsubscribe new entity - api_key:%s, unique_id:%s", api_key, unique_id
428-
)
427+
_LOGGER.debug("Unsubscribe entity: %s", unique_id)
429428
self._fetching_entities[api_key].remove(unique_id)
430429
if len(self._fetching_entities[api_key]) == 0:
431430
self._fetching_entities.pop(api_key)
@@ -437,7 +436,9 @@ def _async_setup_api_requests(self):
437436
"""Determine if we should fetch each API, if one entity needs it."""
438437
# Entities not added yet, fetch all
439438
if not self._fetching_entities:
440-
_LOGGER.debug("Entities not added yet, fetch all")
439+
_LOGGER.debug(
440+
"Entities not added yet, fetch all for '%s'", self._entry.unique_id
441+
)
441442
return
442443

443444
# Determine if we should fetch an API
@@ -460,32 +461,47 @@ def _async_setup_api_requests(self):
460461

461462
# Reset not used API, information is not reset since it's used in device_info
462463
if not self._with_security:
463-
_LOGGER.debug("Disable security api from being updated")
464+
_LOGGER.debug(
465+
"Disable security api from being updated for '%s'",
466+
self._entry.unique_id,
467+
)
464468
self.dsm.reset(self.security)
465469
self.security = None
466470

467471
if not self._with_storage:
468-
_LOGGER.debug("Disable storage api from being updated")
472+
_LOGGER.debug(
473+
"Disable storage api from being updatedf or '%s'", self._entry.unique_id
474+
)
469475
self.dsm.reset(self.storage)
470476
self.storage = None
471477

472478
if not self._with_system:
473-
_LOGGER.debug("Disable system api from being updated")
479+
_LOGGER.debug(
480+
"Disable system api from being updated for '%s'", self._entry.unique_id
481+
)
474482
self.dsm.reset(self.system)
475483
self.system = None
476484

477485
if not self._with_upgrade:
478-
_LOGGER.debug("Disable upgrade api from being updated")
486+
_LOGGER.debug(
487+
"Disable upgrade api from being updated for '%s'", self._entry.unique_id
488+
)
479489
self.dsm.reset(self.upgrade)
480490
self.upgrade = None
481491

482492
if not self._with_utilisation:
483-
_LOGGER.debug("Disable utilisation api from being updated")
493+
_LOGGER.debug(
494+
"Disable utilisation api from being updated for '%s'",
495+
self._entry.unique_id,
496+
)
484497
self.dsm.reset(self.utilisation)
485498
self.utilisation = None
486499

487500
if not self._with_surveillance_station:
488-
_LOGGER.debug("Disable surveillance_station api from being updated")
501+
_LOGGER.debug(
502+
"Disable surveillance_station api from being updated for '%s'",
503+
self._entry.unique_id,
504+
)
489505
self.dsm.reset(self.surveillance_station)
490506
self.surveillance_station = None
491507

@@ -496,55 +512,68 @@ def _fetch_device_configuration(self):
496512
self.network.update()
497513

498514
if self._with_security:
499-
_LOGGER.debug("Enable security api for updates")
515+
_LOGGER.debug("Enable security api updates for '%s'", self._entry.unique_id)
500516
self.security = self.dsm.security
501517

502518
if self._with_storage:
503-
_LOGGER.debug("Enable storage api for updates")
519+
_LOGGER.debug("Enable storage api updates for '%s'", self._entry.unique_id)
504520
self.storage = self.dsm.storage
505521

506522
if self._with_upgrade:
507-
_LOGGER.debug("Enable upgrade api for updates")
523+
_LOGGER.debug("Enable upgrade api updates for '%s'", self._entry.unique_id)
508524
self.upgrade = self.dsm.upgrade
509525

510526
if self._with_system:
511-
_LOGGER.debug("Enable system api for updates")
527+
_LOGGER.debug("Enable system api updates for '%s'", self._entry.unique_id)
512528
self.system = self.dsm.system
513529

514530
if self._with_utilisation:
515-
_LOGGER.debug("Enable utilisation api for updates")
531+
_LOGGER.debug(
532+
"Enable utilisation api updates for '%s'", self._entry.unique_id
533+
)
516534
self.utilisation = self.dsm.utilisation
517535

518536
if self._with_surveillance_station:
519-
_LOGGER.debug("Enable surveillance_station api for updates")
537+
_LOGGER.debug(
538+
"Enable surveillance_station api updates for '%s'",
539+
self._entry.unique_id,
540+
)
520541
self.surveillance_station = self.dsm.surveillance_station
521542

522543
async def async_reboot(self):
523544
"""Reboot NAS."""
524545
try:
525546
await self._hass.async_add_executor_job(self.system.reboot)
526547
except (SynologyDSMLoginFailedException, SynologyDSMRequestException) as err:
527-
_LOGGER.error("Reboot not possible, please try again later")
548+
_LOGGER.error(
549+
"Reboot of '%s' not possible, please try again later",
550+
self._entry.unique_id,
551+
)
528552
_LOGGER.debug("Exception:%s", err)
529553

530554
async def async_shutdown(self):
531555
"""Shutdown NAS."""
532556
try:
533557
await self._hass.async_add_executor_job(self.system.shutdown)
534558
except (SynologyDSMLoginFailedException, SynologyDSMRequestException) as err:
535-
_LOGGER.error("Shutdown not possible, please try again later")
559+
_LOGGER.error(
560+
"Shutdown of '%s' not possible, please try again later",
561+
self._entry.unique_id,
562+
)
536563
_LOGGER.debug("Exception:%s", err)
537564

538565
async def async_unload(self):
539566
"""Stop interacting with the NAS and prepare for removal from hass."""
540567
try:
541568
await self._hass.async_add_executor_job(self.dsm.logout)
542569
except (SynologyDSMAPIErrorException, SynologyDSMRequestException) as err:
543-
_LOGGER.debug("Logout not possible:%s", err)
570+
_LOGGER.debug(
571+
"Logout from '%s' not possible:%s", self._entry.unique_id, err
572+
)
544573

545574
async def async_update(self, now=None):
546575
"""Update function for updating API information."""
547-
_LOGGER.debug("Start data update")
576+
_LOGGER.debug("Start data update for '%s'", self._entry.unique_id)
548577
self._async_setup_api_requests()
549578
try:
550579
await self._hass.async_add_executor_job(
@@ -554,7 +583,11 @@ async def async_update(self, now=None):
554583
_LOGGER.warning(
555584
"Connection error during update, fallback by reloading the entry"
556585
)
557-
_LOGGER.debug("Connection error during update with exception: %s", err)
586+
_LOGGER.debug(
587+
"Connection error during update of '%s' with exception: %s",
588+
self._entry.unique_id,
589+
err,
590+
)
558591
await self._hass.config_entries.async_reload(self._entry.entry_id)
559592
return
560593

0 commit comments

Comments
 (0)