core: Synology shutdown error

The problem

When invoking synology_dsm.shutdown an error gets printed in the logs, after a while stops working.

Environment

  • Home Assistant Core release with the issue: 2021.1.3
  • Last working Home Assistant Core release (if known): N/A
  • Operating environment (OS/Container/Supervised/Core): OS
  • Integration causing this issue: Synology DSM
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/synology_dsm/

Problem-relevant configuration.yaml

- platform: wake_on_lan
  mac: !secret synology_mac
  name: Synology NAS
  host: !secret synology_host
  turn_off:
    service: synology_dsm.shutdown

Traceback/Error logs

    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 273, in service_handler
    await dsm_api.system.shutdown()
TypeError: object dict can't be used in 'await' expression

subsequent calls yield

2021-01-22 20:50:39 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [1749415440] 'NoneType' object has no attribute 'shutdown'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 273, in service_handler
    await dsm_api.system.shutdown()
AttributeError: 'NoneType' object has no attribute 'shutdown'

Additional information

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (16 by maintainers)

Most upvoted comments

Tried reproducing and it didn’t happen. Perhaps I was just too eager to shutdown after reboot?

Greetings from Berlin 👯

I copied the synology_dsm folder from your branch into custom_components on my pi and rebooted Home Assistant.

I turned my NAS off using the synology_dsm.shutdown and all worked good, turning it back on and logged in via the Synology WebUI and issued another shutdown command and this came up in the logs + as a modal.

2021-02-07 21:49:17 ERROR (MainThread) [homeassistant.helpers.script.synology_nas] Synology NAS: Error executing script. Unexpected error for call_service at pos 1: {'api': 'SYNO.Core.System', 'code': 103, 'reason': 'API method does not exist', 'details': None}
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1490, in _execute_service
    await handler.job.target(service_call)
  File "/config/custom_components/synology_dsm/__init__.py", line 353, in service_handler
    await dsm_api.async_shutdown()
  File "/config/custom_components/synology_dsm/__init__.py", line 526, in async_shutdown
    await self._hass.async_add_executor_job(self.system.shutdown)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/api/core/system.py", line 108, in shutdown
    res = self._dsm.get(
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 204, in get
    return self._request("GET", api, method, params, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 270, in _request
    return self._request(request_method, api, method, params, False)
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 271, in _request
    raise SynologyDSMAPIErrorException(
synology_dsm.exceptions.SynologyDSMAPIErrorException: {'api': 'SYNO.Core.System', 'code': 103, 'reason': 'API method does not exist', 'details': None}
2021-02-07 21:49:17 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [1871687816] {'api': 'SYNO.Core.System', 'code': 103, 'reason': 'API method does not exist', 'details': None}
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 136, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1490, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 595, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 632, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 699, in async_turn_off
    await self.hass.async_add_executor_job(ft.partial(self.turn_off, **kwargs))
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/wake_on_lan/switch.py", line 120, in turn_off
    self._off_script.run(context=self._context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 964, in run
    asyncio.run_coroutine_threadsafe(
  File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1033, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1490, in _execute_service
    await handler.job.target(service_call)
  File "/config/custom_components/synology_dsm/__init__.py", line 353, in service_handler
    await dsm_api.async_shutdown()
  File "/config/custom_components/synology_dsm/__init__.py", line 526, in async_shutdown
    await self._hass.async_add_executor_job(self.system.shutdown)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/api/core/system.py", line 108, in shutdown
    res = self._dsm.get(
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 204, in get
    return self._request("GET", api, method, params, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 270, in _request
    return self._request(request_method, api, method, params, False)
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 271, in _request
    raise SynologyDSMAPIErrorException(
synology_dsm.exceptions.SynologyDSMAPIErrorException: {'api': 'SYNO.Core.System', 'code': 103, 'reason': 'API method does not exist', 'details': None}

However trying again shortly after it worked. Perhaps the NAS API wasn’t up at that time?


Just retried - same experience - first time fails, second works

Hi @mib1185,

Thanks for doing this! How would be best to test this in my normal hassio setup?

Would checking out your branch locally and copying the synology_dsm component into my custom_components be enough?


Looks like it is https://skylar.tech/overriding-default-home-assistant-components/

Trying now - will report back.