Merge pull request #9 from bmartin5692/bumper-certs

change str_to_bool func
This commit is contained in:
Brian Martin
2019-06-14 08:14:02 -05:00
committed by GitHub
2 changed files with 21 additions and 5 deletions
+13 -4
View File
@@ -10,6 +10,7 @@ import random
import ssl
import requests
import stringcase
import os
from sleekxmppfs import ClientXMPP, Callback, MatchXPath
from sleekxmppfs.xmlstream import ET
from sleekxmppfs.exceptions import XMPPError
@@ -122,13 +123,21 @@ COMPONENT_FROM_ECOVACS = {
'dust_case_heap': COMPONENT_FILTER
}
def str_to_bool(s):
def str_to_bool_or_cert(s):
if s == 'True' or s == True:
return True
elif s == 'False' or s == False:
return False
else:
raise ValueError("Cannot covert {} to a bool".format(s))
if not s == None:
if os.path.exists(s): # User could provide a path to a CA Cert as well, which is useful for Bumper
if os.path.isfile(s):
return s
else:
raise ValueError("Certificate path provided is not a file - {}".format(s))
raise ValueError("Cannot covert {} to a bool or certificate path".format(s))
class EcoVacsAPI:
CLIENT_KEY = "eJUWrzRv34qFSaYk"
@@ -160,7 +169,7 @@ class EcoVacsAPI:
#'deviceType': '2' - iphone
}
self.verify_ssl = str_to_bool(verify_ssl)
self.verify_ssl = str_to_bool_or_cert(verify_ssl)
_LOGGER.debug("Setting up EcoVacsAPI")
self.resource = device_id[0:8]
self.country = country
@@ -632,7 +641,7 @@ class EcoVacsIOTMQ(ClientMQTT):
self.vacuum = vacuum
self.scheduler = sched.scheduler(time.time, time.sleep)
self.scheduler_thread = threading.Thread(target=self.scheduler.run, daemon=True, name="mqtt_schedule_thread")
self.verify_ssl = str_to_bool(verify_ssl)
self.verify_ssl = str_to_bool_or_cert(verify_ssl)
if server_address is None:
self.hostname = ('mq-{}.ecouser.net'.format(self.continent))
+8 -1
View File
@@ -387,5 +387,12 @@ def a_vacbot(bot=None, iotmq=False, monitor=False):
bot, 'na', monitor=monitor)
def test_str_to_bool():
assert_raises(ValueError, str_to_bool, None) #Value error if str_to_bool can't convert
assert_raises(ValueError, str_to_bool_or_cert, None) #Value error if str_to_bool can't convert
assert_equals(True, str_to_bool_or_cert("True"))
assert_equals(False, str_to_bool_or_cert("False"))
assert_equals(
os.path.abspath(os.path.join(".", "tests", "test_vacbot.py")),
str_to_bool_or_cert(os.path.abspath(os.path.join(".","tests","test_vacbot.py")))
)
assert_raises(ValueError, str_to_bool_or_cert ,(os.path.abspath(os.path.join(".","tests"))))