Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0d993cc
add syno system data and actions
mib1185 Oct 4, 2020
1041b76
add system usage examples
mib1185 Oct 4, 2020
9e91ec0
add upgrade information
mib1185 Oct 4, 2020
ce8c2c4
Fix default login Exception (#73)
Quentame Oct 14, 2020
212f029
Migrate to Python 3.6+ (#70)
Quentame Oct 14, 2020
5244a49
correct alphabetically order
mib1185 Oct 16, 2020
1892770
add SynoCoreUpgrade instance
mib1185 Oct 16, 2020
97bc931
simplify update_available()
mib1185 Oct 16, 2020
5b63dfd
correct defaults of .get()
mib1185 Oct 16, 2020
abcb8f1
harmonize use of API_KEY
mib1185 Oct 16, 2020
bdfd8c8
update docs
mib1185 Oct 16, 2020
3c94ef3
add test data
mib1185 Oct 16, 2020
fbc2810
due to #70
mib1185 Oct 16, 2020
4e190d4
update docs
mib1185 Oct 16, 2020
34bf335
solve conflict
mib1185 Oct 16, 2020
d4c006c
add syno system data and actions
mib1185 Oct 4, 2020
b61e90d
add system usage examples
mib1185 Oct 4, 2020
8d6bef6
add upgrade information
mib1185 Oct 4, 2020
609bc32
correct alphabetically order
mib1185 Oct 16, 2020
2a3e609
add SynoCoreUpgrade instance
mib1185 Oct 16, 2020
13a63fa
simplify update_available()
mib1185 Oct 16, 2020
b878050
correct defaults of .get()
mib1185 Oct 16, 2020
aa217cf
harmonize use of API_KEY
mib1185 Oct 16, 2020
907e74c
update docs
mib1185 Oct 16, 2020
17016a9
add test data
mib1185 Oct 16, 2020
f9c8819
due to #70
mib1185 Oct 16, 2020
5d58f17
update docs
mib1185 Oct 16, 2020
c8775b7
Merge branch 'master' of https://github.com/mib1185/python-synology
mib1185 Oct 16, 2020
c6b337c
Apply suggestions from code review: function return type
Quentame Oct 18, 2020
81bafb1
Don't save previous update data
Quentame Oct 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,66 @@ Surveillance Station usage
surveillance.set_home_mode(True)


System usage
--------------------------

.. code-block:: python

from synology_dsm import SynologyDSM

api = SynologyDSM("<IP/DNS>", "<port>", "<username>", "<password>")
system = api.system

Comment thread
Quentame marked this conversation as resolved.
# Reboot NAS
system.reboot()

# Shutdown NAS
system.shutdown()

# Manual update system information
system.update()

# Get CPU information
system.cpu_clock_speed()
system.cpu_cores()
system.cpu_family()
system.cpu_series()

# Get NTP settings
system.enabled_ntp()
system.ntp_server()

# Get system information
system.firmware_ver()
system.model()
system.ram_size()
system.serial()
system.sys_temp()
system.time()
system.time_zone()
system.time_zone_desc()
system.up_time()
Comment thread
Quentame marked this conversation as resolved.
Outdated

# Get list of all connected USB devices
system.usb_dev()


Upgrade usage
--------------------------

.. code-block:: python

from synology_dsm import SynologyDSM

api = SynologyDSM("<IP/DNS>", "<port>", "<username>", "<password>")
upgrade = api.upgrade

Comment thread
Quentame marked this conversation as resolved.
# Manual update upgrade information
upgrade.update()

# check if DSM update is available
if upgrade.update_available:
do something ...

Credits / Special Thanks
========================
Expand Down
118 changes: 118 additions & 0 deletions synology_dsm/api/core/system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*-
"""DSM System data and actions."""


class SynoCoreSystem(object):
Comment thread
Quentame marked this conversation as resolved.
Outdated
"""Class containing System data and actions."""

API_KEY = "SYNO.Core.System"

def __init__(self, dsm):
self._dsm = dsm
self._data = {}

def update(self):
"""Updates System data."""
raw_data = self._dsm.get(self.API_KEY, "info")
if raw_data:
self._data = raw_data["data"]

### get information
@property
def cpu_clock_speed(self):
"""Gets System CPU clock speed."""
return self._data.get('cpu_clock_speed')

@property
def cpu_cores(self):
"""Gets System CPU cores."""
return self._data.get('cpu_cores')

@property
def cpu_family(self):
"""Gets System CPU family."""
return self._data.get('cpu_family')

@property
def cpu_series(self):
"""Gets System CPU series."""
return self._data.get('cpu_series')

@property
def enabled_ntp(self):
"""Gets System NTP state."""
return self._data.get('enabled_ntp')

@property
def ntp_server(self):
"""Gets System NTP server."""
return self._data.get('ntp_server')

@property
def firmware_ver(self):
"""Gets System firmware version."""
return self._data.get('firmware_ver')

@property
def model(self):
"""Gets System model."""
return self._data.get('model')

@property
def ram_size(self):
"""Gets System ram size."""
return self._data.get('ram_size')

@property
def serial(self):
"""Gets System serial number."""
return self._data.get('serial')

@property
def sys_temp(self):
"""Gets System temperature."""
return self._data.get('sys_temp')

@property
def time(self):
"""Gets System time."""
return self._data.get('time')

@property
def time_zone(self):
"""Gets System time zone."""
return self._data.get('time_zone')

@property
def time_zone_desc(self):
"""Gets System time zone description."""
return self._data.get('time_zone_desc')

@property
def up_time(self):
"""Gets System uptime."""
return self._data.get('up_time')

@property
def usb_dev(self):
"""Gets System connected usb devices."""
return self._data.get('usb_dev', [])

### do system actions
def shutdown(self):
"""Shutdown NAS."""
res = self._dsm.get(
self.API_KEY,
"shutdown",
max_version=1, # shutdown method is only available on api version 1
)
return res

def reboot(self):
"""Reboot NAS."""
res = self._dsm.get(
self.API_KEY,
"reboot",
max_version=1, # reboot method is only available on api version 1
)
return res
24 changes: 24 additions & 0 deletions synology_dsm/api/core/upgrade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
"""DSM Upgrade data and actions."""


class SynoCoreUpgrade(object):
Comment thread
Quentame marked this conversation as resolved.
Outdated
"""Class containing upgrade data and actions."""

API_KEY = "SYNO.Core.Upgrade"
API_SERVER_KEY = API_KEY + ".Server"

def __init__(self, dsm):
self._dsm = dsm
self._data = {}

def update(self):
"""Updates Upgrade data."""
raw_data = self._dsm.get(self.API_SERVER_KEY, "check")
if raw_data:
self._data.update(raw_data["data"])
Comment thread
Quentame marked this conversation as resolved.
Outdated

@property
def update_available(self):
Comment thread
Quentame marked this conversation as resolved.
"""Gets all Upgrade info."""
return self._data["update"].get("available")
79 changes: 57 additions & 22 deletions synology_dsm/synology_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
)

from .api.core.security import SynoCoreSecurity
from .api.core.utilization import SynoCoreUtilization
from .api.core.share import SynoCoreShare
from .api.core.system import SynoCoreSystem
from .api.core.upgrade import SynoCoreUpgrade
from .api.core.utilization import SynoCoreUtilization
from .api.download_station import SynoDownloadStation
from .api.dsm.information import SynoDSMInformation
from .api.dsm.network import SynoDSMNetwork
Expand Down Expand Up @@ -75,10 +77,12 @@ def __init__(
self._information = None
self._network = None
self._security = None
self._utilisation = None
self._storage = None
self._share = None
self._storage = None
self._surveillance = None
self._system = None
self._utilisation = None
self._upgrade = None

# Build variables
if use_https:
Expand Down Expand Up @@ -325,6 +329,12 @@ def update(self, with_information=False, with_network=False):
if self._surveillance:
self._surveillance.update()

if self._system:
self._system.update()

if self._upgrade:
self._upgrade.update()

def reset(self, api):
"""Reset an API to avoid fetching in on update."""
if isinstance(api, str):
Expand All @@ -333,40 +343,51 @@ def reset(self, api):
if hasattr(self, "_" + api):
setattr(self, "_" + api, None)
return True
if api == SynoDownloadStation.API_KEY:
self._download = None
return True
if api == SynoCoreSecurity.API_KEY:
self._security = None
return True
if api == SynoCoreShare.API_KEY:
self._share = None
return True
if api == SynoCoreSystem.API_KEY:
self._system = None
return True
if api == SynoCoreUpgrade.API_KEY:
self._upgrade = None
return True
if api == SynoCoreUtilization.API_KEY:
self._utilisation = None
return True
if api == SynoDownloadStation.API_KEY:
self._download = None
return True
if api == SynoStorage.API_KEY:
self._storage = None
return True
if api == SynoSurveillanceStation.API_KEY:
self._surveillance = None
return True
if isinstance(api, SynoDownloadStation):
self._download = None
return True
if isinstance(api, SynoCoreSecurity):
self._security = None
return True
if isinstance(api, SynoCoreShare):
self._share = None
return True
if isinstance(api, SynoCoreSystem):
self._system = None
return True
if isinstance(api, SynoCoreUpgrade):
self._utilisation = None
return True
if isinstance(api, SynoCoreUtilization):
self._utilisation = None
return True
if isinstance(api, SynoDownloadStation):
self._download = None
return True
if isinstance(api, SynoStorage):
self._storage = None
return True

if isinstance(api, SynoSurveillanceStation):
self._surveillance = None
return True
Expand Down Expand Up @@ -401,11 +422,11 @@ def security(self):
return self._security

@property
def utilisation(self):
"""Gets NAS utilisation informations."""
if not self._utilisation:
self._utilisation = SynoCoreUtilization(self)
return self._utilisation
def share(self):
Comment thread
Quentame marked this conversation as resolved.
Outdated
"""Gets NAS shares information."""
if not self._share:
self._share = SynoCoreShare(self)
return self._share

@property
def storage(self):
Expand All @@ -414,16 +435,30 @@ def storage(self):
self._storage = SynoStorage(self)
return self._storage

@property
def share(self):
"""Gets NAS shares information."""
if not self._share:
self._share = SynoCoreShare(self)
return self._share

@property
def surveillance_station(self):
"""Gets NAS SurveillanceStation."""
if not self._surveillance:
self._surveillance = SynoSurveillanceStation(self)
return self._surveillance

@property
def system(self):
Comment thread
Quentame marked this conversation as resolved.
Outdated
"""Gets NAS system information."""
if not self._system:
self._system = SynoCoreSystem(self)
return self._system

@property
def upgrade(self):
Comment thread
Quentame marked this conversation as resolved.
Outdated
"""Gets NAS upgrade informations."""
if not self._upgrade:
self._upgrade = SynoCoreUpgrade(self)
return self._upgrade

@property
def utilisation(self):
"""Gets NAS utilisation informations."""
if not self._utilisation:
self._utilisation = SynoCoreUtilization(self)
return self._utilisation