Skip to content

Commit

Permalink
Fix : DSM 5 can't fetch Storage data
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentame committed Apr 28, 2020
1 parent 1569715 commit aa57f9b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions synology_dsm/synology_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class SynologyDSM(object):
API_INFO = "SYNO.API.Info"
API_AUTH = "SYNO.API.Auth"

DSM_5_WEIRD_URL_API = [
SynoStorage.API_KEY,
]

def __init__(
self,
dsm_ip,
Expand Down Expand Up @@ -74,16 +78,22 @@ def _debuglog(self, message):
if self._debugmode:
print("DEBUG: " + message)

def _build_url(self, api):
if (
api == SynoStorage.API_KEY
def _is_weird_api_url(self, api):
"""Returns True if the API URL is not common (nas_base_url/webapi/path?params) [Only handles DSM 5 for now]."""
return (
api in self.DSM_5_WEIRD_URL_API
and self._information
and self._information.version
and int(self._information.version) < 7321 # < DSM 6
):
return (
"%s/webman/modules/StorageManager/storagehandler.cgi?" % self._base_url
)
)

def _build_url(self, api):
if self._is_weird_api_url(api):
if api == SynoStorage.API_KEY:
return (
"%s/webman/modules/StorageManager/storagehandler.cgi?"
% self._base_url
)

return "%s/webapi/%s?" % (self._base_url, self.apis[api]["path"])

Expand Down Expand Up @@ -177,7 +187,7 @@ def _request(
self.login()

# Check if API is available
if not self.apis.get(api):
if not self.apis.get(api) and not self._is_weird_api_url(api):
raise SynologyDSMAPINotExistsException(api)

# Build request params
Expand Down

0 comments on commit aa57f9b

Please sign in to comment.