Give mFi options to control TLS usage

The default configuration of the mFi controller generates self-signed
certificates which are valid for short periods of time, and which are
regnerated on start or as needed. This makes requests mad. Since most
people will be using the self-signed certificates anyway, add options
to let them choose non-TLS, or unverified connections if they want/need.

This bumps the mficlient requirement to 0.3.0 for proper handling of
verify=False.
This commit is contained in:
Dan Smith committed 2016-02-29 17:37:41 -08:00
1 parent 87e23e7d73
commit be04ebf9ed
4 files changed
+36 -9

No files matched your search

+9 -3
View File
@@ -13,7 +13,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, TEMP_CELCIUS
from homeassistant.helpers import validate_config
from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['mficlient==0.2.2']
REQUIREMENTS = ['mficlient==0.3.0']
_LOGGER = logging.getLogger(__name__)
@@ -32,6 +32,8 @@ SENSOR_MODELS = [
'Input Analog',
'Input Digital',
]
CONF_TLS = 'use_tls'
CONF_VERIFY_TLS = 'verify_tls'
# pylint: disable=unused-variable
@@ -46,14 +48,18 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
return False
host = config.get('host')
port = int(config.get('port', 6443))
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
use_tls = bool(config.get(CONF_TLS, True))
verify_tls = bool(config.get(CONF_VERIFY_TLS, True))
default_port = use_tls and 6443 or 6080
port = int(config.get('port', default_port))
from mficlient.client import FailedToLogin, MFiClient
try:
client = MFiClient(host, username, password, port=port)
client = MFiClient(host, username, password, port=port,
use_tls=use_tls, verify=verify_tls)
except (FailedToLogin, requests.exceptions.ConnectionError) as ex:
_LOGGER.error('Unable to connect to mFi: %s', str(ex))
return False