diff --git a/homeassistant/components/synology_dsm/__init__.py b/homeassistant/components/synology_dsm/__init__.py index dacb124aa77187..27aed4ce38ba65 100644 --- a/homeassistant/components/synology_dsm/__init__.py +++ b/homeassistant/components/synology_dsm/__init__.py @@ -173,6 +173,7 @@ def _async_migrator(entity_entry: entity_registry.RegistryEntry): ) # Continue setup + _LOGGER.debug("async_setup_entry - unique_id:%s - setup SynoApi", entry.unique_id) api = SynoApi(hass, entry) try: await api.async_setup() @@ -190,11 +191,21 @@ def _async_migrator(entity_entry: entity_registry.RegistryEntry): # For SSDP compat if not entry.data.get(CONF_MAC): network = await hass.async_add_executor_job(getattr, api.dsm, "network") + _LOGGER.debug( + "async_setup_entry - unique_id:%s - add macs %s", + entry.unique_id, + network.macs, + ) hass.config_entries.async_update_entry( entry, data={**entry.data, CONF_MAC: network.macs} ) for platform in PLATFORMS: + _LOGGER.debug( + "async_setup_entry - unique_id:%s - setup platform %s", + entry.unique_id, + platform, + ) hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, platform) ) @@ -204,6 +215,7 @@ def _async_migrator(entity_entry: entity_registry.RegistryEntry): async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry): """Unload Synology DSM sensors.""" + _LOGGER.debug("async_unload_entry - unique_id:%s - start unload", entry.unique_id) unload_ok = all( await asyncio.gather( *[ @@ -214,6 +226,7 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry): ) if unload_ok: + _LOGGER.debug("async_unload_entry - unique_id:%s - unload ok", entry.unique_id) entry_data = hass.data[DOMAIN][entry.unique_id] entry_data[UNDO_UPDATE_LISTENER]() await entry_data[SYNO_API].async_unload() @@ -224,6 +237,9 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry): async def _async_update_listener(hass: HomeAssistantType, entry: ConfigEntry): """Handle options update.""" + _LOGGER.debug( + "_async_update_listener - unique_id:%s - reload entity", entry.unique_id + ) await hass.config_entries.async_reload(entry.entry_id) @@ -232,6 +248,7 @@ class SynoApi: def __init__(self, hass: HomeAssistantType, entry: ConfigEntry): """Initialize the API wrapper class.""" + _LOGGER.debug("SynoApi - unique_id:%s - init", entry.unique_id) self._hass = hass self._entry = entry @@ -263,6 +280,10 @@ def signal_sensor_update(self) -> str: async def async_setup(self): """Start interacting with the NAS.""" + _LOGGER.debug( + "SynoApi.async_setup - unique_id:%s - setup SynologyDSM", + self._entry.unique_id, + ) self.dsm = SynologyDSM( self._entry.data[CONF_HOST], self._entry.data[CONF_PORT], @@ -273,11 +294,21 @@ async def async_setup(self): timeout=self._entry.options.get(CONF_TIMEOUT), device_token=self._entry.data.get("device_token"), ) + + _LOGGER.debug( + "SynoApi.async_setup - unique_id:%s - SynologyDSM.login()", + self._entry.unique_id, + ) await self._hass.async_add_executor_job(self.dsm.login) self._with_surveillance_station = bool( self.dsm.apis.get(SynoSurveillanceStation.CAMERA_API_KEY) ) + _LOGGER.debug( + "SynoApi.async_setup - unique_id:%s - _with_surveillance_station:%s", + self._entry.unique_id, + self._with_surveillance_station, + ) self._async_setup_api_requests() @@ -311,8 +342,15 @@ def unsubscribe() -> None: @callback def _async_setup_api_requests(self): """Determine if we should fetch each API, if one entity needs it.""" + _LOGGER.debug( + "SynoApi._async_setup_api_requests - unique_id:%s", self._entry.unique_id + ) # Entities not added yet, fetch all if not self._fetching_entities: + _LOGGER.debug( + "SynoApi._async_setup_api_requests - unique_id:%s - fetch all", + self._entry.unique_id, + ) return # Determine if we should fetch an API @@ -356,6 +394,9 @@ def _async_setup_api_requests(self): def _fetch_device_configuration(self): """Fetch initial device config.""" + _LOGGER.debug( + "SynoApi._fetch_device_configuration - unique_id:%s", self._entry.unique_id + ) self.information = self.dsm.information self.network = self.dsm.network self.network.update() @@ -377,10 +418,12 @@ def _fetch_device_configuration(self): async def async_unload(self): """Stop interacting with the NAS and prepare for removal from hass.""" + _LOGGER.debug("SynoApi.async_unload - unique_id:%s", self._entry.unique_id) self._unsub_dispatcher() async def async_update(self, now=None): """Update function for updating API information.""" + _LOGGER.debug("SynoApi.async_update - unique_id:%s", self._entry.unique_id) self._async_setup_api_requests() await self._hass.async_add_executor_job(self.dsm.update, self._with_information) async_dispatcher_send(self._hass, self.signal_sensor_update) @@ -407,6 +450,7 @@ def __init__( self._icon = entity_info[ENTITY_ICON] self._unit = entity_info[ENTITY_UNIT] self._unique_id = f"{self._api.information.serial}_{entity_type}" + _LOGGER.debug("SynologyDSMEntity - unique_id:%s - init", self._unique_id) @property def unique_id(self) -> str: @@ -491,6 +535,11 @@ def __init__( ): """Initialize the Synology DSM disk or volume entity.""" super().__init__(api, entity_type, entity_info) + _LOGGER.debug( + "SynologyDSMDeviceEntity - device_id:%s type:%s - init", + device_id, + entity_type, + ) self._device_id = device_id self._device_name = None self._device_manufacturer = None diff --git a/homeassistant/components/synology_dsm/binary_sensor.py b/homeassistant/components/synology_dsm/binary_sensor.py index 69f217a4b4e9c0..ec30c9fefa16e2 100644 --- a/homeassistant/components/synology_dsm/binary_sensor.py +++ b/homeassistant/components/synology_dsm/binary_sensor.py @@ -1,4 +1,5 @@ """Support for Synology DSM binary sensors.""" +import logging from typing import Dict from homeassistant.components.binary_sensor import BinarySensorEntity @@ -15,6 +16,8 @@ UPGRADE_BINARY_SENSORS, ) +_LOGGER = logging.getLogger(__name__) + async def async_setup_entry( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities @@ -47,6 +50,7 @@ async def async_setup_entry( for sensor_type in STORAGE_DISK_BINARY_SENSORS ] + _LOGGER.debug("async_setup_entry - %s", entities) async_add_entities(entities) diff --git a/homeassistant/components/synology_dsm/camera.py b/homeassistant/components/synology_dsm/camera.py index 1dfd8ff945bd98..0bedb7c2719be9 100644 --- a/homeassistant/components/synology_dsm/camera.py +++ b/homeassistant/components/synology_dsm/camera.py @@ -1,4 +1,5 @@ """Support for Synology DSM cameras.""" +import logging from typing import Dict from synology_dsm.api.surveillance_station import SynoSurveillanceStation @@ -19,6 +20,8 @@ SYNO_API, ) +_LOGGER = logging.getLogger(__name__) + async def async_setup_entry( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities @@ -35,6 +38,7 @@ async def async_setup_entry( cameras = surveillance_station.get_all_cameras() entities = [SynoDSMCamera(api, camera) for camera in cameras] + _LOGGER.debug("async_setup_entry - %s", entities) async_add_entities(entities) diff --git a/homeassistant/components/synology_dsm/config_flow.py b/homeassistant/components/synology_dsm/config_flow.py index da792e3a4d3f55..a3f7214dd2daa0 100644 --- a/homeassistant/components/synology_dsm/config_flow.py +++ b/homeassistant/components/synology_dsm/config_flow.py @@ -77,6 +77,8 @@ def _ordered_shared_schema(schema_input): class SynologyDSMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """Handle a config flow.""" + _LOGGER.debug("SynologyDSMFlowHandler") + VERSION = 1 CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL @@ -103,6 +105,7 @@ async def _show_setup_form(self, user_input=None, errors=None): else: step_id = "user" data_schema = _user_schema_with_defaults(user_input) + _LOGGER.debug("SynologyDSMFlowHandler._show_setup_form - step_id:%s", step_id) return self.async_show_form( step_id=step_id, @@ -113,6 +116,7 @@ async def _show_setup_form(self, user_input=None, errors=None): async def async_step_user(self, user_input=None): """Handle a flow initiated by the user.""" + _LOGGER.debug("SynologyDSMFlowHandler.async_step_user") errors = {} if user_input is None: @@ -165,7 +169,13 @@ async def async_step_user(self, user_input=None): return await self._show_setup_form(user_input, errors) # Check if already configured + _LOGGER.debug( + "SynologyDSMFlowHandler.async_step_user - async_set_unique_id(%s)", serial + ) await self.async_set_unique_id(serial, raise_on_progress=False) + _LOGGER.debug( + "SynologyDSMFlowHandler.async_step_user - check if already configured" + ) self._abort_if_unique_id_configured() config_data = { @@ -184,10 +194,15 @@ async def async_step_user(self, user_input=None): if user_input.get(CONF_VOLUMES): config_data[CONF_VOLUMES] = user_input[CONF_VOLUMES] + _LOGGER.debug("SynologyDSMFlowHandler.async_step_user - finish config flow") return self.async_create_entry(title=host, data=config_data) async def async_step_ssdp(self, discovery_info): """Handle a discovered synology_dsm.""" + _LOGGER.debug( + "SynologyDSMFlowHandler.async_step_ssdp - discovery_info: %s", + discovery_info, + ) parsed_url = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION]) friendly_name = ( discovery_info[ssdp.ATTR_UPNP_FRIENDLY_NAME].split("(", 1)[0].strip() @@ -197,6 +212,10 @@ async def async_step_ssdp(self, discovery_info): # Synology NAS can broadcast on multiple IP addresses, since they can be connected to multiple ethernets. # The serial of the NAS is actually its MAC address. if self._mac_already_configured(mac): + _LOGGER.debug( + "SynologyDSMFlowHandler.async_step_ssdp - mac %s is already configured", + mac, + ) return self.async_abort(reason="already_configured") await self.async_set_unique_id(mac) @@ -237,11 +256,18 @@ async def async_step_2sa(self, user_input, errors=None): def _mac_already_configured(self, mac): """See if we already have configured a NAS with this MAC address.""" + _LOGGER.debug( + "SynologyDSMFlowHandler._mac_already_configured - check mac %s", mac + ) existing_macs = [ mac.replace("-", "") for entry in self._async_current_entries() for mac in entry.data.get(CONF_MAC, []) ] + _LOGGER.debug( + "SynologyDSMFlowHandler._mac_already_configured - existing macs %s", + existing_macs, + ) return mac in existing_macs diff --git a/homeassistant/components/synology_dsm/sensor.py b/homeassistant/components/synology_dsm/sensor.py index 31013451682570..e5c29b259bef43 100644 --- a/homeassistant/components/synology_dsm/sensor.py +++ b/homeassistant/components/synology_dsm/sensor.py @@ -1,5 +1,6 @@ """Support for Synology DSM sensors.""" from datetime import timedelta +import logging from typing import Dict from homeassistant.config_entries import ConfigEntry @@ -27,6 +28,8 @@ UTILISATION_SENSORS, ) +_LOGGER = logging.getLogger(__name__) + async def async_setup_entry( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities @@ -65,6 +68,7 @@ async def async_setup_entry( for sensor_type in INFORMATION_SENSORS ] + _LOGGER.debug("async_setup_entry - %s", entities) async_add_entities(entities) diff --git a/homeassistant/components/synology_dsm/switch.py b/homeassistant/components/synology_dsm/switch.py index ee29c9f2692801..f7fc8450adb4fc 100644 --- a/homeassistant/components/synology_dsm/switch.py +++ b/homeassistant/components/synology_dsm/switch.py @@ -1,4 +1,5 @@ """Support for Synology DSM switch.""" +import logging from typing import Dict from synology_dsm.api.surveillance_station import SynoSurveillanceStation @@ -10,6 +11,8 @@ from . import SynoApi, SynologyDSMEntity from .const import DOMAIN, SURVEILLANCE_SWITCH, SYNO_API +_LOGGER = logging.getLogger(__name__) + async def async_setup_entry( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities @@ -30,6 +33,7 @@ async def async_setup_entry( for sensor_type in SURVEILLANCE_SWITCH ] + _LOGGER.debug("async_setup_entry - %s", entities) async_add_entities(entities, True)