Use nymea plugintimer
This commit is contained in:
parent
f966532b57
commit
4099443c1c
@ -21,7 +21,6 @@ def startPairing(info):
|
|||||||
info.oAuthUrl = authorizationUrl
|
info.oAuthUrl = authorizationUrl
|
||||||
info.finish(nymea.ThingErrorNoError)
|
info.finish(nymea.ThingErrorNoError)
|
||||||
|
|
||||||
|
|
||||||
def confirmPairing(info, username, secret):
|
def confirmPairing(info, username, secret):
|
||||||
# The user has successfully logged in at neato. Obtain the token from the OAuth session
|
# The user has successfully logged in at neato. Obtain the token from the OAuth session
|
||||||
token = oauthSessions[info.transactionId].fetch_token(secret)
|
token = oauthSessions[info.transactionId].fetch_token(secret)
|
||||||
@ -31,7 +30,6 @@ def confirmPairing(info, username, secret):
|
|||||||
del oauthSessions[info.transactionId]
|
del oauthSessions[info.transactionId]
|
||||||
info.finish(nymea.ThingErrorNoError)
|
info.finish(nymea.ThingErrorNoError)
|
||||||
|
|
||||||
|
|
||||||
def setupThing(info):
|
def setupThing(info):
|
||||||
# Setup for the account
|
# Setup for the account
|
||||||
if info.thing.thingClassId == accountThingClassId:
|
if info.thing.thingClassId == accountThingClassId:
|
||||||
@ -90,12 +88,11 @@ def setupThing(info):
|
|||||||
autoThingsAppeared(thingDescriptors)
|
autoThingsAppeared(thingDescriptors)
|
||||||
|
|
||||||
# If no poll timer is set up yet, start it now
|
# If no poll timer is set up yet, start it now
|
||||||
logger.log("Creating polltimer")
|
logger.log("Creating polltimer @ setupThing")
|
||||||
global pollTimer
|
global pollTimer
|
||||||
if pollTimer is None:
|
if pollTimer is None:
|
||||||
pollTimer = threading.Timer(5, pollService)
|
pollTimer = nymea.PluginTimer(30, pollService)
|
||||||
pollTimer.start()
|
logger.log("timer interval @ setupThing", pollTimer.interval)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Setup for the robots
|
# Setup for the robots
|
||||||
@ -118,7 +115,6 @@ def setupThing(info):
|
|||||||
info.finish(nymea.ThingErrorNoError)
|
info.finish(nymea.ThingErrorNoError)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def refreshRobot(thing):
|
def refreshRobot(thing):
|
||||||
robot = thingsAndRobots[thing]
|
robot = thingsAndRobots[thing]
|
||||||
logger.log("Refreshing robot:", robot)
|
logger.log("Refreshing robot:", robot)
|
||||||
@ -161,8 +157,8 @@ def refreshRobot(thing):
|
|||||||
thing.setStateValue(robotRobotStateStateTypeId, "error")
|
thing.setStateValue(robotRobotStateStateTypeId, "error")
|
||||||
thing.setStateValue(robotErrorMessageStateTypeId, rbtError)
|
thing.setStateValue(robotErrorMessageStateTypeId, rbtError)
|
||||||
|
|
||||||
|
|
||||||
def pollService():
|
def pollService():
|
||||||
|
logger.log("pollTimer triggered")
|
||||||
# Poll all robots we know
|
# Poll all robots we know
|
||||||
for thing in myThings():
|
for thing in myThings():
|
||||||
if thing.thingClassId == robotThingClassId:
|
if thing.thingClassId == robotThingClassId:
|
||||||
@ -170,11 +166,8 @@ def pollService():
|
|||||||
refreshRobot(thing)
|
refreshRobot(thing)
|
||||||
except:
|
except:
|
||||||
logger.warn("Error refreshing robot state")
|
logger.warn("Error refreshing robot state")
|
||||||
# restart the timer for next poll
|
|
||||||
global pollTimer
|
global pollTimer
|
||||||
pollTimer = threading.Timer(60, pollService)
|
logger.log("timer interval @ pollService", pollTimer.interval)
|
||||||
pollTimer.start()
|
|
||||||
|
|
||||||
|
|
||||||
def executeAction(info):
|
def executeAction(info):
|
||||||
if info.actionTypeId == robotStartCleaningActionTypeId:
|
if info.actionTypeId == robotStartCleaningActionTypeId:
|
||||||
@ -255,7 +248,6 @@ def cleanWithRobot(robotThing, mapID, boundaryID):
|
|||||||
logger.log("Settings: Eco:", boolEco, "Care:", boolCare, "Enable nogo:", boolNogo, "mapID:", mapID, "boundaryID:", boundaryID)
|
logger.log("Settings: Eco:", boolEco, "Care:", boolCare, "Enable nogo:", boolNogo, "mapID:", mapID, "boundaryID:", boundaryID)
|
||||||
thingsAndRobots[robotThing].start_cleaning(mode=intEco, navigation_mode=intCare, category=intNogo, boundary_id=boundaryID, map_id=mapID)
|
thingsAndRobots[robotThing].start_cleaning(mode=intEco, navigation_mode=intCare, category=intNogo, boundary_id=boundaryID, map_id=mapID)
|
||||||
|
|
||||||
|
|
||||||
def browseThing(browseResult):
|
def browseThing(browseResult):
|
||||||
robotThing = browseResult.thing
|
robotThing = browseResult.thing
|
||||||
robot = thingsAndRobots[browseResult.thing]
|
robot = thingsAndRobots[browseResult.thing]
|
||||||
@ -270,7 +262,6 @@ def browseThing(browseResult):
|
|||||||
browseResult.finish(nymea.ThingErrorAuthenticationFailure)
|
browseResult.finish(nymea.ThingErrorAuthenticationFailure)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
# Top level entries -> return maps
|
# Top level entries -> return maps
|
||||||
if browseResult.itemId == "" or browseResult.itemId == "maps":
|
if browseResult.itemId == "" or browseResult.itemId == "maps":
|
||||||
maps = account.persistent_maps
|
maps = account.persistent_maps
|
||||||
@ -303,7 +294,6 @@ def browseThing(browseResult):
|
|||||||
browseResult.finish(nymea.ThingErrorNoError)
|
browseResult.finish(nymea.ThingErrorNoError)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def executeBrowserItem(info):
|
def executeBrowserItem(info):
|
||||||
logger.log("Browser item clicked:", info.itemId)
|
logger.log("Browser item clicked:", info.itemId)
|
||||||
if info.itemId.startswith("boundary-"):
|
if info.itemId.startswith("boundary-"):
|
||||||
@ -320,9 +310,17 @@ def executeBrowserItem(info):
|
|||||||
logger.warn("Can't execute browser item:", info.itemId)
|
logger.warn("Can't execute browser item:", info.itemId)
|
||||||
info.finish(nymea.ThingErrorItemNotExecutable)
|
info.finish(nymea.ThingErrorItemNotExecutable)
|
||||||
|
|
||||||
|
|
||||||
def deinit():
|
def deinit():
|
||||||
global pollTimer
|
global pollTimer
|
||||||
# If we started a poll timer, cancel it on shutdown.
|
# If we started a poll timer, cancel it on shutdown.
|
||||||
if pollTimer is not None:
|
if pollTimer is not None:
|
||||||
pollTimer.cancel()
|
pollTimer = None
|
||||||
|
|
||||||
|
def thingRemoved(thing):
|
||||||
|
global pollTimer
|
||||||
|
logger.log("removeThing called for", thing.name)
|
||||||
|
# Clean up all data related to this thing
|
||||||
|
logger.log("len myThings", len(myThings()))
|
||||||
|
if len(myThings()) == 0 and pollTimer is not None:
|
||||||
|
logger.log("cancelling plugintimer")
|
||||||
|
pollTimer = None
|
||||||
Loading…
x
Reference in New Issue
Block a user