Add SSL configuration (#29038)
* OpenGarage: Add protocol configuration (#29037) * OpenGarage: Change CONF_PROTOCOL to CONF_SSL Resolves https://github.com/home-assistant/home-assistant/pull/29038#discussion_r350173095 * OpenGarage: Add `verify_ssl` as an option
This commit is contained in:
parent
112a3f5e9f
commit
d5db55354e
1 changed files with 13 additions and 2 deletions
|
@ -18,6 +18,8 @@ from homeassistant.const import (
|
||||||
CONF_COVERS,
|
CONF_COVERS,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
|
CONF_SSL,
|
||||||
|
CONF_VERIFY_SSL,
|
||||||
STATE_CLOSING,
|
STATE_CLOSING,
|
||||||
STATE_OPENING,
|
STATE_OPENING,
|
||||||
)
|
)
|
||||||
|
@ -42,6 +44,8 @@ COVER_SCHEMA = vol.Schema(
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
vol.Optional(CONF_NAME): cv.string,
|
vol.Optional(CONF_NAME): cv.string,
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
|
vol.Optional(CONF_SSL, default=False): cv.boolean,
|
||||||
|
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,6 +64,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
CONF_NAME: device_config.get(CONF_NAME),
|
CONF_NAME: device_config.get(CONF_NAME),
|
||||||
CONF_HOST: device_config.get(CONF_HOST),
|
CONF_HOST: device_config.get(CONF_HOST),
|
||||||
CONF_PORT: device_config.get(CONF_PORT),
|
CONF_PORT: device_config.get(CONF_PORT),
|
||||||
|
CONF_SSL: device_config.get(CONF_SSL),
|
||||||
|
CONF_VERIFY_SSL: device_config.get(CONF_VERIFY_SSL),
|
||||||
CONF_DEVICE_KEY: device_config.get(CONF_DEVICE_KEY),
|
CONF_DEVICE_KEY: device_config.get(CONF_DEVICE_KEY),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,13 +79,16 @@ class OpenGarageCover(CoverDevice):
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
"""Initialize the cover."""
|
"""Initialize the cover."""
|
||||||
self.opengarage_url = "http://{}:{}".format(args[CONF_HOST], args[CONF_PORT])
|
self.opengarage_url = "{}://{}:{}".format(
|
||||||
|
"https" if args[CONF_SSL] else "http", args[CONF_HOST], args[CONF_PORT]
|
||||||
|
)
|
||||||
self._name = args[CONF_NAME]
|
self._name = args[CONF_NAME]
|
||||||
self._device_key = args[CONF_DEVICE_KEY]
|
self._device_key = args[CONF_DEVICE_KEY]
|
||||||
self._state = None
|
self._state = None
|
||||||
self._state_before_move = None
|
self._state_before_move = None
|
||||||
self._device_state_attributes = {}
|
self._device_state_attributes = {}
|
||||||
self._available = True
|
self._available = True
|
||||||
|
self._verify_ssl = args[CONF_VERIFY_SSL]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -155,7 +164,9 @@ class OpenGarageCover(CoverDevice):
|
||||||
result = -1
|
result = -1
|
||||||
try:
|
try:
|
||||||
result = requests.get(
|
result = requests.get(
|
||||||
f"{self.opengarage_url}/cc?dkey={self._device_key}&click=1", timeout=10
|
f"{self.opengarage_url}/cc?dkey={self._device_key}&click=1",
|
||||||
|
timeout=10,
|
||||||
|
verify=self._verify_ssl,
|
||||||
).json()["result"]
|
).json()["result"]
|
||||||
except requests.exceptions.RequestException as ex:
|
except requests.exceptions.RequestException as ex:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
|
Loading…
Add table
Reference in a new issue