mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix QVR Pro connection error and add port option (#33070)
* Allow port specification. Handle connection error gracefully. * Allow port specification. Handle connection error gracefully. * Alias exception. Requested changes.
This commit is contained in:
parent
0249daef2e
commit
f0472f2dc2
@ -4,10 +4,11 @@ import logging
|
|||||||
|
|
||||||
from pyqvrpro import Client
|
from pyqvrpro import Client
|
||||||
from pyqvrpro.client import AuthenticationError, InsufficientPermissionsError
|
from pyqvrpro.client import AuthenticationError, InsufficientPermissionsError
|
||||||
|
from requests.exceptions import ConnectionError as RequestsConnectionError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.discovery import load_platform
|
from homeassistant.helpers.discovery import load_platform
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
|
vol.Optional(CONF_PORT): cv.port,
|
||||||
vol.Optional(CONF_EXCLUDE_CHANNELS, default=[]): vol.All(
|
vol.Optional(CONF_EXCLUDE_CHANNELS, default=[]): vol.All(
|
||||||
cv.ensure_list_csv, [cv.positive_int]
|
cv.ensure_list_csv, [cv.positive_int]
|
||||||
),
|
),
|
||||||
@ -49,10 +51,11 @@ def setup(hass, config):
|
|||||||
user = conf[CONF_USERNAME]
|
user = conf[CONF_USERNAME]
|
||||||
password = conf[CONF_PASSWORD]
|
password = conf[CONF_PASSWORD]
|
||||||
host = conf[CONF_HOST]
|
host = conf[CONF_HOST]
|
||||||
|
port = conf.get(CONF_PORT)
|
||||||
excluded_channels = conf[CONF_EXCLUDE_CHANNELS]
|
excluded_channels = conf[CONF_EXCLUDE_CHANNELS]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
qvrpro = Client(user, password, host)
|
qvrpro = Client(user, password, host, port=port)
|
||||||
|
|
||||||
channel_resp = qvrpro.get_channel_list()
|
channel_resp = qvrpro.get_channel_list()
|
||||||
|
|
||||||
@ -62,6 +65,9 @@ def setup(hass, config):
|
|||||||
except AuthenticationError:
|
except AuthenticationError:
|
||||||
_LOGGER.error("Authentication failed")
|
_LOGGER.error("Authentication failed")
|
||||||
return False
|
return False
|
||||||
|
except RequestsConnectionError:
|
||||||
|
_LOGGER.error("Error connecting to QVR server")
|
||||||
|
return False
|
||||||
|
|
||||||
channels = []
|
channels = []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user