Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 2 additions & 10 deletions homeassistant/components/synology_dsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
CONF_API_VERSION,
CONF_DISKS,
CONF_HOST,
CONF_PASSWORD,
Expand All @@ -22,14 +21,13 @@
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import HomeAssistantType

from .const import CONF_VOLUMES, DEFAULT_DSM_VERSION, DEFAULT_SSL, DOMAIN
from .const import CONF_VOLUMES, DEFAULT_SSL, DOMAIN

CONFIG_SCHEMA = vol.Schema(
{
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT): cv.port,
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
vol.Optional(CONF_API_VERSION, default=DEFAULT_DSM_VERSION): cv.positive_int,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_DISKS): cv.ensure_list,
Expand Down Expand Up @@ -70,12 +68,9 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
password = entry.data[CONF_PASSWORD]
unit = hass.config.units.temperature_unit
use_ssl = entry.data[CONF_SSL]
api_version = entry.data.get(CONF_API_VERSION, DEFAULT_DSM_VERSION)
device_token = entry.data.get("device_token")

api = SynoApi(
hass, host, port, username, password, unit, use_ssl, device_token, api_version
)
api = SynoApi(hass, host, port, username, password, unit, use_ssl, device_token)

await api.async_setup()

Expand Down Expand Up @@ -109,7 +104,6 @@ def __init__(
temp_unit: str,
use_ssl: bool,
device_token: str,
api_version: int,
):
"""Initialize the API wrapper class."""
self._hass = hass
Expand All @@ -119,7 +113,6 @@ def __init__(
self._password = password
self._use_ssl = use_ssl
self._device_token = device_token
self._api_version = api_version
self.temp_unit = temp_unit

self._dsm: SynologyDSM = None
Expand All @@ -143,7 +136,6 @@ async def async_setup(self):
self._password,
self._use_ssl,
device_token=self._device_token,
dsm_version=self._api_version,
)

await self._hass.async_add_executor_job(self._fetch_device_configuration)
Expand Down
42 changes: 12 additions & 30 deletions homeassistant/components/synology_dsm/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

from synology_dsm import SynologyDSM
from synology_dsm.exceptions import (
SynologyDSMException,
SynologyDSMLogin2SAFailedException,
SynologyDSMLogin2SARequiredException,
SynologyDSMLoginInvalidException,
SynologyDSMRequestException,
)
import voluptuous as vol

from homeassistant import config_entries, exceptions
from homeassistant.components import ssdp
from homeassistant.const import (
CONF_API_VERSION,
CONF_DISKS,
CONF_HOST,
CONF_NAME,
Expand All @@ -23,13 +24,7 @@
CONF_USERNAME,
)

from .const import (
CONF_VOLUMES,
DEFAULT_DSM_VERSION,
DEFAULT_PORT,
DEFAULT_PORT_SSL,
DEFAULT_SSL,
)
from .const import CONF_VOLUMES, DEFAULT_PORT, DEFAULT_PORT_SSL, DEFAULT_SSL
from .const import DOMAIN # pylint: disable=unused-import

_LOGGER = logging.getLogger(__name__)
Expand All @@ -56,12 +51,6 @@ def _ordered_shared_schema(schema_input):
vol.Required(CONF_PASSWORD, default=schema_input.get(CONF_PASSWORD, "")): str,
vol.Optional(CONF_PORT, default=schema_input.get(CONF_PORT, "")): str,
vol.Optional(CONF_SSL, default=schema_input.get(CONF_SSL, DEFAULT_SSL)): bool,
vol.Optional(
CONF_API_VERSION,
default=schema_input.get(CONF_API_VERSION, DEFAULT_DSM_VERSION),
): vol.All(
vol.Coerce(int), vol.In([5, 6]), # DSM versions supported by the library
),
}


Expand Down Expand Up @@ -111,7 +100,6 @@ async def async_step_user(self, user_input=None):
username = user_input[CONF_USERNAME]
password = user_input[CONF_PASSWORD]
use_ssl = user_input.get(CONF_SSL, DEFAULT_SSL)
api_version = user_input.get(CONF_API_VERSION, DEFAULT_DSM_VERSION)
otp_code = user_input.get(CONF_OTP_CODE)

if not port:
Expand All @@ -120,9 +108,7 @@ async def async_step_user(self, user_input=None):
else:
port = DEFAULT_PORT

api = SynologyDSM(
host, port, username, password, use_ssl, dsm_version=api_version,
)
api = SynologyDSM(host, port, username, password, use_ssl)

try:
serial = await self.hass.async_add_executor_job(
Expand All @@ -134,8 +120,12 @@ async def async_step_user(self, user_input=None):
errors[CONF_OTP_CODE] = "otp_failed"
user_input[CONF_OTP_CODE] = None
return await self.async_step_2sa(user_input, errors)
except (SynologyDSMLoginInvalidException, InvalidAuth):
except SynologyDSMLoginInvalidException:
errors[CONF_USERNAME] = "login"
except SynologyDSMRequestException:
errors[CONF_HOST] = "connection"
except SynologyDSMException:
errors["base"] = "unknown"
except InvalidData:
errors["base"] = "missing_data"

Expand All @@ -152,7 +142,6 @@ async def async_step_user(self, user_input=None):
CONF_SSL: use_ssl,
CONF_USERNAME: username,
CONF_PASSWORD: password,
CONF_API_VERSION: api_version,
}
if otp_code:
config_data["device_token"] = api.device_token
Expand Down Expand Up @@ -216,28 +205,21 @@ def _host_already_configured(self, hostname):

def _login_and_fetch_syno_info(api, otp_code):
"""Login to the NAS and fetch basic data."""
if not api.login(otp_code):
raise InvalidAuth

# These do i/o
information = api.information
api.login(otp_code)
utilisation = api.utilisation
storage = api.storage

if (
information.serial is None
api.information.serial is None
or utilisation.cpu_user_load is None
or storage.disks_ids is None
or storage.volumes_ids is None
):
raise InvalidData

return information.serial
return api.information.serial


class InvalidData(exceptions.HomeAssistantError):
"""Error to indicate we get invalid data from the nas."""


class InvalidAuth(exceptions.HomeAssistantError):
"""Error to indicate there is invalid auth."""
1 change: 0 additions & 1 deletion homeassistant/components/synology_dsm/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
DEFAULT_SSL = True
DEFAULT_PORT = 5000
DEFAULT_PORT_SSL = 5001
DEFAULT_DSM_VERSION = 6

UTILISATION_SENSORS = {
"cpu_other_load": ["CPU Load (Other)", UNIT_PERCENTAGE, "mdi:chip"],
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/synology_dsm/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "synology_dsm",
"name": "Synology DSM",
"documentation": "https://www.home-assistant.io/integrations/synology_dsm",
"requirements": ["python-synology==0.6.0"],
"requirements": ["python-synology==0.7.0"],
"codeowners": ["@ProtoThis", "@Quentame"],
"config_flow": true,
"ssdp": [
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/synology_dsm/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"host": "Host",
"port": "Port (Optional)",
"ssl": "Use SSL/TLS to connect to your NAS",
"api_version": "DSM version",
"username": "Username",
"password": "Password"
}
Expand All @@ -24,17 +23,18 @@
"description": "Do you want to setup {name} ({host})?",
"data": {
"ssl": "Use SSL/TLS to connect to your NAS",
"api_version": "DSM version",
"username": "Username",
"password": "Password",
"port": "Port (Optional)"
}
}
},
"error": {
"connection": "Connection error: please check your host, password & ssl",
"login": "Login error: please check your username & password",
"missing_data": "Missing data: please retry later or an other configuration",
"otp_failed": "Two-step authentication failed, retry with a new pass code"
"otp_failed": "Two-step authentication failed, retry with a new pass code",
"unknown": "Unknown error: please check logs to get more details"
},
"abort": { "already_configured": "Host already configured" }
}
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/synology_dsm/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"already_configured": "Host already configured"
},
"error": {
"connection": "Connection error: please check your host, password & ssl",
"login": "Login error: please check your username & password",
"missing_data": "Missing data: please retry later or an other configuration",
"otp_failed": "Two-step authentication failed, retry with a new pass code"
"otp_failed": "Two-step authentication failed, retry with a new pass code",
"unknown": "Unknown error: please check logs to get more details"
},
"flow_title": "Synology DSM {name} ({host})",
"step": {
Expand All @@ -18,7 +20,6 @@
},
"link": {
"data": {
"api_version": "DSM version",
"password": "Password",
"port": "Port (Optional)",
"ssl": "Use SSL/TLS to connect to your NAS",
Expand All @@ -29,7 +30,6 @@
},
"user": {
"data": {
"api_version": "DSM version",
"host": "Host",
"password": "Password",
"port": "Port (Optional)",
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ python-sochain-api==0.0.2
python-songpal==0.11.2

# homeassistant.components.synology_dsm
python-synology==0.6.0
python-synology==0.7.0

# homeassistant.components.tado
python-tado==0.8.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ python-miio==0.5.0.1
python-nest==4.1.0

# homeassistant.components.synology_dsm
python-synology==0.6.0
python-synology==0.7.0

# homeassistant.components.tado
python-tado==0.8.1
Expand Down
Loading