Clean up ssl usage (#33960)

* Clean up ssl usage

* Revert config[CONF_SSL] from sonarr, radarr and mfi
This commit is contained in:
springstan 2020-04-10 22:01:57 +02:00 committed by GitHub
parent cfef8ee961
commit 8198970af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 44 additions and 55 deletions

View File

@ -43,7 +43,7 @@ def get_scanner(hass, config):
config[CONF_HOST],
config[CONF_USERNAME],
config[CONF_PASSWORD],
config.get(CONF_SSL),
config[CONF_SSL],
config.get(CONF_VERIFY_SSL),
)
if not controller.is_logged_in():

View File

@ -71,7 +71,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
host = config.get(CONF_HOST)
key = config.get(CONF_API_KEY)
port = config.get(CONF_PORT)
ssl = config.get(CONF_SSL)
ssl = config[CONF_SSL]
if port is None:
port = DEFAULT_SSL_PORT if ssl else DEFAULT_PORT

View File

@ -107,7 +107,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
port=config.get(CONF_PORT),
username=config.get(CONF_USERNAME),
password=config.get(CONF_PASSWORD),
is_https=config.get(CONF_SSL),
is_https=config[CONF_SSL],
prefer_picon=config.get(CONF_USE_CHANNEL_ICON),
mac_address=config.get(CONF_MAC_ADDRESS),
turn_off_to_deep=config.get(CONF_DEEP_STANDBY),

View File

@ -90,7 +90,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
ssl = config.get(CONF_SSL)
ssl = config[CONF_SSL]
epson_proj = EpsonProjector(
async_get_clientsession(hass, verify_ssl=False), name, host, port, ssl

View File

@ -90,10 +90,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
customize = config.get(CONF_CUSTOMIZE)
if config.get(CONF_SSL):
protocol = "https"
else:
protocol = "http"
protocol = "https" if config[CONF_SSL] else "http"
url = f"{protocol}://{host}"

View File

@ -222,7 +222,7 @@ def setup(hass, config):
"password": rconfig.get(CONF_PASSWORD),
"callbackip": rconfig.get(CONF_CALLBACK_IP),
"callbackport": rconfig.get(CONF_CALLBACK_PORT),
"ssl": rconfig.get(CONF_SSL),
"ssl": rconfig[CONF_SSL],
"verify_ssl": rconfig.get(CONF_VERIFY_SSL),
"connect": True,
}

View File

@ -75,7 +75,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"host": config[CONF_HOST],
"password": config.get(CONF_PASSWORD),
"port": config.get(CONF_PORT),
"ssl": config.get(CONF_SSL),
"ssl": config[CONF_SSL],
"username": config.get(CONF_USERNAME),
"verify_ssl": config.get(CONF_VERIFY_SSL),
}
@ -203,7 +203,7 @@ class InfluxSensorData:
points = list(self.influx.query(self.query).get_points())
if not points:
_LOGGER.warning(
"Query returned no points, sensor state set to UNKNOWN: %s", self.query,
"Query returned no points, sensor state set to UNKNOWN: %s", self.query
)
self.value = None
else:

View File

@ -198,7 +198,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
config.get(CONF_NAME),
config.get(CONF_HOST),
config.get(CONF_PORT),
config.get(CONF_SSL),
config[CONF_SSL],
add_entities,
)
]

View File

@ -40,7 +40,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
host = config.get(CONF_HOST)
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
use_tls = config.get(CONF_SSL)
use_tls = config[CONF_SSL]
verify_tls = config.get(CONF_VERIFY_SSL)
default_port = 6443 if use_tls else 6080
port = int(config.get(CONF_PORT, default_port))

View File

@ -144,9 +144,9 @@ def setup(hass, config):
for printer in config[DOMAIN]:
name = printer[CONF_NAME]
ssl = "s" if printer[CONF_SSL] else ""
protocol = "https" if printer[CONF_SSL] else "http"
base_url = (
f"http{ssl}://{printer[CONF_HOST]}:{printer[CONF_PORT]}"
f"{protocol}://{printer[CONF_HOST]}:{printer[CONF_PORT]}"
f"{printer[CONF_PATH]}api/"
)
api_key = printer[CONF_API_KEY]

View File

@ -64,7 +64,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
CONF_NAME: device_config.get(CONF_NAME),
CONF_HOST: device_config.get(CONF_HOST),
CONF_PORT: device_config.get(CONF_PORT),
CONF_SSL: device_config.get(CONF_SSL),
CONF_SSL: device_config[CONF_SSL],
CONF_VERIFY_SSL: device_config.get(CONF_VERIFY_SSL),
CONF_DEVICE_KEY: device_config.get(CONF_DEVICE_KEY),
}
@ -80,7 +80,7 @@ class OpenGarageCover(CoverDevice):
def __init__(self, args):
"""Initialize the cover."""
self.opengarage_url = (
f"http{'s' if args[CONF_SSL] else ''}://"
f"{'https' if args[CONF_SSL] else 'http'}://"
f"{args[CONF_HOST]}:{args[CONF_PORT]}"
)
self._name = args[CONF_NAME]

View File

@ -100,10 +100,10 @@ def _async_setup_plex(hass, config):
if MP_DOMAIN in server_config:
hass.data.setdefault(PLEX_MEDIA_PLAYER_OPTIONS, server_config.pop(MP_DOMAIN))
if CONF_HOST in server_config:
prefix = "https" if server_config.pop(CONF_SSL) else "http"
protocol = "https" if server_config.pop(CONF_SSL) else "http"
server_config[
CONF_URL
] = f"{prefix}://{server_config.pop(CONF_HOST)}:{server_config.pop(CONF_PORT)}"
] = f"{protocol}://{server_config.pop(CONF_HOST)}:{server_config.pop(CONF_PORT)}"
hass.async_create_task(
hass.config_entries.flow.async_init(
PLEX_DOMAIN,

View File

@ -51,12 +51,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the pyLoad sensors."""
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
ssl = "s" if config.get(CONF_SSL) else ""
protocol = "https" if config[CONF_SSL] else "http"
name = config.get(CONF_NAME)
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
monitored_types = config.get(CONF_MONITORED_VARIABLES)
url = f"http{ssl}://{host}:{port}/api/"
url = f"{protocol}://{host}:{port}/api/"
try:
pyloadapi = PyLoadAPI(api_url=url, username=username, password=password)

View File

@ -175,7 +175,7 @@ class QNAPStatsAPI:
def __init__(self, config):
"""Initialize the API wrapper."""
protocol = "https" if config.get(CONF_SSL) else "http"
protocol = "https" if config[CONF_SSL] else "http"
self._api = QNAPStats(
"{}://{}".format(protocol, config.get(CONF_HOST)),
config.get(CONF_PORT),

View File

@ -53,11 +53,11 @@ SENSOR_TYPES = {
}
ENDPOINTS = {
"diskspace": "http{0}://{1}:{2}/{3}api/diskspace",
"upcoming": "http{0}://{1}:{2}/{3}api/calendar?start={4}&end={5}",
"movies": "http{0}://{1}:{2}/{3}api/movie",
"commands": "http{0}://{1}:{2}/{3}api/command",
"status": "http{0}://{1}:{2}/{3}api/system/status",
"diskspace": "{0}://{1}:{2}/{3}api/diskspace",
"upcoming": "{0}://{1}:{2}/{3}api/calendar?start={4}&end={5}",
"movies": "{0}://{1}:{2}/{3}api/movie",
"commands": "{0}://{1}:{2}/{3}api/command",
"status": "{0}://{1}:{2}/{3}api/system/status",
}
# Support to Yottabytes for the future, why not
@ -110,7 +110,7 @@ class RadarrSensor(Entity):
self.apikey = conf.get(CONF_API_KEY)
self.included = conf.get(CONF_INCLUDED)
self.days = int(conf.get(CONF_DAYS))
self.ssl = "s" if conf.get(CONF_SSL) else ""
self.ssl = "https" if conf.get(CONF_SSL) else "http"
self._state = None
self.data = []
self._tz = timezone(str(hass.config.time_zone))

View File

@ -134,7 +134,7 @@ async def async_setup(hass, config):
conf = config.get(DOMAIN)
if conf is not None:
use_ssl = conf.get(CONF_SSL)
use_ssl = conf[CONF_SSL]
name = conf.get(CONF_NAME)
api_key = conf.get(CONF_API_KEY)
await async_configure_sabnzbd(hass, conf, use_ssl, name, api_key)

View File

@ -131,7 +131,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
session = async_get_clientsession(hass, verify_ssl=config[CONF_VERIFY_SSL])
grp = config[CONF_GROUP]
url = "http{}://{}".format("s" if config[CONF_SSL] else "", config[CONF_HOST])
protocol = "https" if config[CONF_SSL] else "http"
url = f"{protocol}://{config[CONF_HOST]}"
sma = pysma.SMA(session, url, config[CONF_PASSWORD], group=grp)

View File

@ -52,13 +52,13 @@ SENSOR_TYPES = {
}
ENDPOINTS = {
"diskspace": "http{0}://{1}:{2}/{3}api/diskspace",
"queue": "http{0}://{1}:{2}/{3}api/queue",
"upcoming": "http{0}://{1}:{2}/{3}api/calendar?start={4}&end={5}",
"wanted": "http{0}://{1}:{2}/{3}api/wanted/missing",
"series": "http{0}://{1}:{2}/{3}api/series",
"commands": "http{0}://{1}:{2}/{3}api/command",
"status": "http{0}://{1}:{2}/{3}api/system/status",
"diskspace": "{0}://{1}:{2}/{3}api/diskspace",
"queue": "{0}://{1}:{2}/{3}api/queue",
"upcoming": "{0}://{1}:{2}/{3}api/calendar?start={4}&end={5}",
"wanted": "{0}://{1}:{2}/{3}api/wanted/missing",
"series": "{0}://{1}:{2}/{3}api/series",
"commands": "{0}://{1}:{2}/{3}api/command",
"status": "{0}://{1}:{2}/{3}api/system/status",
}
# Support to Yottabytes for the future, why not
@ -111,7 +111,7 @@ class SonarrSensor(Entity):
self.apikey = conf.get(CONF_API_KEY)
self.included = conf.get(CONF_INCLUDED)
self.days = int(conf.get(CONF_DAYS))
self.ssl = "s" if conf.get(CONF_SSL) else ""
self.ssl = "https" if conf.get(CONF_SSL) else "http"
self._state = None
self.data = []
self._tz = timezone(str(hass.config.time_zone))

View File

@ -70,7 +70,7 @@ def setup(hass, config):
host = conf.get(CONF_HOST)
port = conf.get(CONF_PORT)
token = conf.get(CONF_TOKEN)
use_ssl = conf.get(CONF_SSL)
use_ssl = conf[CONF_SSL]
verify_ssl = conf.get(CONF_VERIFY_SSL)
name = conf.get(CONF_NAME)
entity_filter = conf[CONF_FILTER]

View File

@ -59,7 +59,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
api_key = config[CONF_API_KEY]
monitored_conditions = config.get(CONF_MONITORED_CONDITIONS)
user = config.get(CONF_MONITORED_USERS)
use_ssl = config.get(CONF_SSL)
use_ssl = config[CONF_SSL]
verify_ssl = config.get(CONF_VERIFY_SSL)
session = async_get_clientsession(hass, verify_ssl)

View File

@ -82,10 +82,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
timeout = config.get(CONF_TIMEOUT)
humidifier = config.get(CONF_HUMIDIFIER)
if config.get(CONF_SSL):
proto = "https"
else:
proto = "http"
protocol = "https" if config[CONF_SSL] else "http"
client = VenstarColorTouch(
addr=host,
@ -93,7 +90,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
user=username,
password=password,
pin=pin,
proto=proto,
proto=protocol,
)
add_entities([VenstarThermostat(client, humidifier)], True)

View File

@ -40,12 +40,9 @@ def setup(hass, config):
"""Set up the Zabbix component."""
conf = config[DOMAIN]
if conf[CONF_SSL]:
schema = "https"
else:
schema = "http"
protocol = "https" if config[CONF_SSL] else "http"
url = urljoin("{}://{}".format(schema, conf[CONF_HOST]), conf[CONF_PATH])
url = urljoin(f"{protocol}://{conf[CONF_HOST]}", conf[CONF_PATH])
username = conf.get(CONF_USERNAME)
password = conf.get(CONF_PASSWORD)

View File

@ -58,13 +58,10 @@ def setup(hass, config):
success = True
for conf in config[DOMAIN]:
if conf[CONF_SSL]:
schema = "https"
else:
schema = "http"
protocol = "https" if config[CONF_SSL] else "http"
host_name = conf[CONF_HOST]
server_origin = f"{schema}://{host_name}"
server_origin = f"{protocol}://{host_name}"
zm_client = ZoneMinder(
server_origin,
conf.get(CONF_USERNAME),