* Create config_flow.py
* Update __init__.py
* Create const.py
* Create strings.json
* Update sensor.py
* Update manifest.json
* Update manifest.json
* Add device name to entities
* Correcting health sensor
* Update manifest.json
* Adding integration_type
* Update sensor.py
* Update __init__.py
* Enums
* Update sensor.py
* Removed unused notify_create
* Switch to SensorDeviceClass.TEMPERATURE
* Update enums
* Remove SENSOR_TYPES from const.py
* Add SENSOR_TYPES to sensor.py
* Removed dependancies
* Removed import yaml
* Removed entity_registry_enabled_default
* Update const.py remove dups
* Update manifest.json removed dups
* Update __init__.py
* Update const.py
* Update manifest.json
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py remove unused
* Update sensor.py add docstring
* Update sensor.py add super
* Remove FOLDER sensors
* Remove VOLUME_NAME
* fix cli
* fix cli
* Add config flow tests
* Update requirements_test_all.txt
* Update CODEOWNERS
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update __init__.py
Change unload to walrus
Remove async_setup
* Update const.py remove PLATFORMS
* Update __init__.py add Platform Enum
As per epenet
* Update __init__.py
* Update config_flow.py
* Update sensor.py
* Update __init__.py
ruff
* Update config_flow.py
Ruff
* Update sensor.py
* Update const.py remove attrs
* Update sensor.py add attrs
* Revert tuple for sensor extend
* Update sensor.py
* Update coordinator.py
* Update coordinator.py
* Update sensor.py
* Update coordinator.py
* Update homeassistant/components/qnap/__init__.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/__init__.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update coordinator.py
* Update __init__.py
* Update coordinator.py
* Update sensor.py
* Add device_info
* Update sensor.py
* Update sensor.py self._attr_unique_id
* Update sensor.py
* Update sensor.py
* Type Hints
* Move tuples
* Drive sensor name
* Remove caps
* Remove caps
* Add YAML import
* Update sensor.py fix ruff
* Revert tuples
* Update sensor.py as per review
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* assert uid is not None
* Update homeassistant/components/qnap/sensor.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/sensor.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update .coveragerc
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update sensor.py
* Update config_flow.py add imports
* Update const.py
* Update sensor.py move confs to const
* Update config_flow.py add const
* Update test_config_flow.py remove const name
* Update test_config_flow.py remove standard result const
* Update test_config_flow.py
* Combine tests
* Update test_config_flow.py
* Update config_flow.py
* Update test_config_flow.py
* Update config_flow.py
* Update test_config_flow.py
* Update test_config_flow.py
* Update sensor.py change UID as requested
* Update sensor.py added check for monitor_device
* fix tests
* Remove rounding
* Revert "Remove rounding"
This reverts commit 61bf653c06
.
---------
Co-authored-by: starkillerOG <starkiller.og@gmail.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
99 lines
3.1 KiB
Python
99 lines
3.1 KiB
Python
"""Config flow to configure qnap component."""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from qnapstats import QNAPStats
|
|
from requests.exceptions import ConnectTimeout
|
|
import voluptuous as vol
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.const import (
|
|
CONF_HOST,
|
|
CONF_MONITORED_CONDITIONS,
|
|
CONF_PASSWORD,
|
|
CONF_PORT,
|
|
CONF_SSL,
|
|
CONF_USERNAME,
|
|
CONF_VERIFY_SSL,
|
|
)
|
|
from homeassistant.data_entry_flow import FlowResult
|
|
from homeassistant.helpers import config_validation as cv
|
|
|
|
from .const import (
|
|
CONF_DRIVES,
|
|
CONF_NICS,
|
|
CONF_VOLUMES,
|
|
DEFAULT_PORT,
|
|
DEFAULT_SSL,
|
|
DEFAULT_TIMEOUT,
|
|
DEFAULT_VERIFY_SSL,
|
|
DOMAIN,
|
|
)
|
|
|
|
DATA_SCHEMA = vol.Schema(
|
|
{
|
|
vol.Required(CONF_HOST): cv.string,
|
|
vol.Required(CONF_USERNAME): cv.string,
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
|
|
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
|
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
|
}
|
|
)
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
class QnapConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|
"""Qnap configuration flow."""
|
|
|
|
VERSION = 1
|
|
|
|
async def async_step_import(self, import_info: dict[str, Any]) -> FlowResult:
|
|
"""Set the config entry up from yaml."""
|
|
import_info.pop(CONF_MONITORED_CONDITIONS, None)
|
|
import_info.pop(CONF_NICS, None)
|
|
import_info.pop(CONF_DRIVES, None)
|
|
import_info.pop(CONF_VOLUMES, None)
|
|
return await self.async_step_user(import_info)
|
|
|
|
async def async_step_user(
|
|
self,
|
|
user_input: dict[str, Any] | None = None,
|
|
) -> FlowResult:
|
|
"""Handle a flow initialized by the user."""
|
|
errors = {}
|
|
if user_input is not None:
|
|
host = user_input[CONF_HOST]
|
|
protocol = "https" if user_input[CONF_SSL] else "http"
|
|
api = QNAPStats(
|
|
host=f"{protocol}://{host}",
|
|
port=user_input[CONF_PORT],
|
|
username=user_input[CONF_USERNAME],
|
|
password=user_input[CONF_PASSWORD],
|
|
verify_ssl=user_input[CONF_VERIFY_SSL],
|
|
timeout=DEFAULT_TIMEOUT,
|
|
)
|
|
try:
|
|
stats = await self.hass.async_add_executor_job(api.get_system_stats)
|
|
except ConnectTimeout:
|
|
errors["base"] = "cannot_connect"
|
|
except TypeError:
|
|
errors["base"] = "invalid_auth"
|
|
except Exception as error: # pylint: disable=broad-except
|
|
_LOGGER.error(error)
|
|
errors["base"] = "unknown"
|
|
else:
|
|
unique_id = stats["system"]["serial_number"]
|
|
await self.async_set_unique_id(unique_id)
|
|
self._abort_if_unique_id_configured()
|
|
title = stats["system"]["name"]
|
|
return self.async_create_entry(title=title, data=user_input)
|
|
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=self.add_suggested_values_to_schema(DATA_SCHEMA, user_input),
|
|
errors=errors,
|
|
)
|