Bump python-synology to 0.7.0 (#34534)

This commit is contained in:
Quentame authored and GitHub committed 2020-04-22 16:28:47 -05:00
1 parent 6631bbc6f5
commit a8cd7203df
9 files changed
+62 -71

No files matched your search

@@ -9,7 +9,6 @@ import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
CONF_API_VERSION,
CONF_DISKS,
CONF_HOST,
CONF_PASSWORD,
@@ -22,14 +21,13 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
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,
@@ -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()
@@ -109,7 +104,6 @@ class SynoApi:
temp_unit: str,
use_ssl: bool,
device_token: str,
api_version: int,
):
"""Initialize the API wrapper class."""
self._hass = hass
@@ -119,7 +113,6 @@ class SynoApi:
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
@@ -143,7 +136,6 @@ class SynoApi:
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)
@@ -4,16 +4,17 @@ from urllib.parse import urlparse
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,
@@ -23,13 +24,7 @@ from homeassistant.const import (
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__)
@@ -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
),
}
@@ -111,7 +100,6 @@ class SynologyDSMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
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:
@@ -120,9 +108,7 @@ class SynologyDSMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
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(
@@ -134,8 +120,12 @@ class SynologyDSMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
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"
@@ -152,7 +142,6 @@ class SynologyDSMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
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
@@ -216,28 +205,21 @@ class SynologyDSMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
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."""
@@ -12,7 +12,6 @@ CONF_VOLUMES = "volumes"
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"],
@@ -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": [
@@ -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"
}
@@ -24,7 +23,6 @@
"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)"
@@ -32,9 +30,11 @@
}
},
"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" }
}
@@ -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": {
@@ -18,7 +20,6 @@
},
"link": {
"data": {
"api_version": "DSM version",
"password": "Password",
"port": "Port (Optional)",
"ssl": "Use SSL/TLS to connect to your NAS",
@@ -29,7 +30,6 @@
},
"user": {
"data": {
"api_version": "DSM version",
"host": "Host",
"password": "Password",
"port": "Port (Optional)",