Cleanup init code
Cleanup init code from adding IOT
This commit is contained in:
Vendored
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
"--debug",
|
"--debug",
|
||||||
"spotclean",
|
"spotclean",
|
||||||
"0",
|
"0",
|
||||||
"60"
|
"1"
|
||||||
],
|
],
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal"
|
||||||
},
|
},
|
||||||
|
|||||||
+20
-30
@@ -353,7 +353,8 @@ class VacBot():
|
|||||||
|
|
||||||
if vacuum['iot']:
|
if vacuum['iot']:
|
||||||
self.iot = EcoVacsIOT(user, domain, resource, secret, continent, vacuum)
|
self.iot = EcoVacsIOT(user, domain, resource, secret, continent, vacuum)
|
||||||
self.iot.subscribe_to_ctls(self._handle_ctl)
|
#TODO: How to handle subscriptions for IOT
|
||||||
|
#self.iot.subscribe_to_ctls(self._handle_ctl)
|
||||||
else:
|
else:
|
||||||
self.xmpp = EcoVacsXMPP(user, domain, resource, secret, continent, server_address)
|
self.xmpp = EcoVacsXMPP(user, domain, resource, secret, continent, server_address)
|
||||||
self.xmpp.subscribe_to_ctls(self._handle_ctl)
|
self.xmpp.subscribe_to_ctls(self._handle_ctl)
|
||||||
@@ -361,17 +362,21 @@ class VacBot():
|
|||||||
|
|
||||||
def connect_and_wait_until_ready(self):
|
def connect_and_wait_until_ready(self):
|
||||||
if not self.vacuum['iot']:
|
if not self.vacuum['iot']:
|
||||||
#self.iot.connect_and_wait_until_ready()
|
|
||||||
#self.iot.schedule('Ping', 30, lambda: self.send_ping(), repeat=True)
|
|
||||||
|
|
||||||
#else:
|
|
||||||
self.xmpp.connect_and_wait_until_ready()
|
self.xmpp.connect_and_wait_until_ready()
|
||||||
self.xmpp.schedule('Ping', 30, lambda: self.send_ping(), repeat=True)
|
self.xmpp.schedule('Ping', 30, lambda: self.send_ping(), repeat=True)
|
||||||
|
|
||||||
|
#else: #ToDo identify the best way to handle similar for IOT devices
|
||||||
|
#self.iot.connect_and_wait_until_ready()
|
||||||
|
#self.iot.schedule('Ping', 30, lambda: self.send_ping(), repeat=True)
|
||||||
|
|
||||||
if self._monitor:
|
if self._monitor:
|
||||||
# Do a first ping, which will also fetch initial statuses if the ping succeeds
|
# Do a first ping, which will also fetch initial statuses if the ping succeeds
|
||||||
self.send_ping()
|
self.send_ping()
|
||||||
|
if not self.vacuum['iot']:
|
||||||
self.xmpp.schedule('Components', 3600, lambda: self.refresh_components(), repeat=True)
|
self.xmpp.schedule('Components', 3600, lambda: self.refresh_components(), repeat=True)
|
||||||
|
else:
|
||||||
|
#For IOT go ahead and refresh components
|
||||||
|
self.refresh_components()
|
||||||
|
|
||||||
def _handle_ctl(self, ctl):
|
def _handle_ctl(self, ctl):
|
||||||
method = '_handle_' + ctl['event']
|
method = '_handle_' + ctl['event']
|
||||||
@@ -391,7 +396,6 @@ class VacBot():
|
|||||||
_LOGGER.warning("Unknown component type: '" + type + "'")
|
_LOGGER.warning("Unknown component type: '" + type + "'")
|
||||||
|
|
||||||
if 'val' in event:
|
if 'val' in event:
|
||||||
|
|
||||||
lifespan = int(event['val']) / 100
|
lifespan = int(event['val']) / 100
|
||||||
else:
|
else:
|
||||||
lifespan = int(event['left']) / 60 #This works for a D901
|
lifespan = int(event['left']) / 60 #This works for a D901
|
||||||
@@ -470,10 +474,7 @@ class VacBot():
|
|||||||
return self.vacuum_status in CLEANING_STATES
|
return self.vacuum_status in CLEANING_STATES
|
||||||
|
|
||||||
def send_ping(self):
|
def send_ping(self):
|
||||||
if self.vacuum['iot']:
|
if not self.vacuum['iot']:
|
||||||
#TODO
|
|
||||||
print("IOT Ping")
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
self.xmpp.send_ping(self._vacuum_address())
|
self.xmpp.send_ping(self._vacuum_address())
|
||||||
except XMPPError as err:
|
except XMPPError as err:
|
||||||
@@ -495,6 +496,8 @@ class VacBot():
|
|||||||
if self.vacuum_status == 'offline':
|
if self.vacuum_status == 'offline':
|
||||||
self.vacuum_status = None
|
self.vacuum_status = None
|
||||||
self.statusEvents.notify(self.vacuum_status)
|
self.statusEvents.notify(self.vacuum_status)
|
||||||
|
#else: #TODO determine how to handle send_ping for IOT device
|
||||||
|
#print("IOT Ping")
|
||||||
|
|
||||||
def refresh_components(self):
|
def refresh_components(self):
|
||||||
try:
|
try:
|
||||||
@@ -549,11 +552,11 @@ class EcoVacsIOT():
|
|||||||
self.ctl_subscribers = []
|
self.ctl_subscribers = []
|
||||||
self.ready_flag = Event()
|
self.ready_flag = Event()
|
||||||
|
|
||||||
|
#TODO: Determine what to do with IOT connect and wait
|
||||||
def connect_and_wait_until_ready(self):
|
# def connect_and_wait_until_ready(self):
|
||||||
self.connect(EcoVacsAPI._EcoVacsAPI__call_portal_api())
|
# self.connect(EcoVacsAPI._EcoVacsAPI__call_portal_api())
|
||||||
self.process()
|
# self.process()
|
||||||
self.wait_until_ready()
|
# self.wait_until_ready()
|
||||||
|
|
||||||
def send_command(self, action, recipient):
|
def send_command(self, action, recipient):
|
||||||
c = self._wrap_command(action, recipient)
|
c = self._wrap_command(action, recipient)
|
||||||
@@ -562,7 +565,6 @@ class EcoVacsIOT():
|
|||||||
|
|
||||||
|
|
||||||
def _wrap_command(self, cmd, recipient):
|
def _wrap_command(self, cmd, recipient):
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'auth': {
|
'auth': {
|
||||||
'realm': EcoVacsAPI.REALM,
|
'realm': EcoVacsAPI.REALM,
|
||||||
@@ -581,10 +583,8 @@ class EcoVacsIOT():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# def subscribe_to_ctls(self, function):
|
||||||
|
# self.ctl_subscribers.append(function)
|
||||||
def subscribe_to_ctls(self, function):
|
|
||||||
self.ctl_subscribers.append(function)
|
|
||||||
|
|
||||||
|
|
||||||
def _handle_ctl(self, action, message):
|
def _handle_ctl(self, action, message):
|
||||||
@@ -618,16 +618,6 @@ class EcoVacsIOT():
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def session_start(self, event):
|
|
||||||
_LOGGER.debug("----------------- starting session ----------------")
|
|
||||||
_LOGGER.debug("event = {}".format(event))
|
|
||||||
#self.register_handler(Callback("general",
|
|
||||||
# MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}'),
|
|
||||||
# self._handle_ctl))
|
|
||||||
self.ready_flag.set()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EcoVacsXMPP(ClientXMPP):
|
class EcoVacsXMPP(ClientXMPP):
|
||||||
def __init__(self, user, domain, resource, secret, continent, server_address=None):
|
def __init__(self, user, domain, resource, secret, continent, server_address=None):
|
||||||
ClientXMPP.__init__(self, user + '@' + domain, '0/' + resource + '/' + secret)
|
ClientXMPP.__init__(self, user + '@' + domain, '0/' + resource + '/' + secret)
|
||||||
|
|||||||
Reference in New Issue
Block a user