def set_device(name): global robots global robot for r in robots["robots"]: if (r["name"] == name): try: robot = Robot(r["serial"], r["secret"], r["name"]) update_state() except requests.exceptions.HTTPError as e: # Whoops it wasn't a 200 pyotherside.send("httperror", str(e)) break
def botvacGetValues(self): robot = Robot(self.DEVICE_SERIAL, self.API_SECRET, self.DEVICE_NAME) response = robot.state Domoticz.Debug(str(response)) isCharging = response['details']['isCharging'] isDocked = response['details']['isDocked'] isScheduleEnabled = response['details']['isScheduleEnabled'] charge = response['details']['charge'] state = response['state'] action = response['action'] device_on = 1 if state == 2 else 0 controlValue = 0 if state == 1: # Idle if isDocked: statusValue = self.actions.get(102) + " (" + str( charge) + "%)" if isCharging else self.actions.get( 101) #Charging or Base else: statusValue = self.actions.get(100) #Stopped controlValue = 20 if isDocked else 50 #Base or Stop elif state == 2: #Busy statusValue = self.actions.get(action) if action in [1, 3, 11 ]: #House cleaning, Manual cleaning or Map cleaning controlValue = 10 #Clean elif action == 2: #Spot controlValue = 30 #Spot elif state in [3, 4]: #Pause or Error statusValue = self.states.get(state) controlValue = 40 if state == 3 else 50 #Pause or Stop UpdateDevice(self.statusUnit, device_on, statusValue) UpdateDevice(self.controlUnit, 1, controlValue) UpdateDevice(self.scheduleUnit, int(isScheduleEnabled), '')
def setupThing(info): # Setup for the account if info.thing.thingClassId == accountThingClassId: logger.log("SetupThing for account:", info.thing.name) pluginStorage().beginGroup(info.thing.id) token = json.loads(pluginStorage().value("token")) logger.log("setup", token) pluginStorage().endGroup() try: oAuthSession = OAuthSession(token=token) # Login went well, finish the setup info.finish(nymea.ThingErrorNoError) except Exception as e: # Login error logger.warn("Error setting up neato account:", str(e)) info.finish(nymea.ThingErrorAuthenticationFailure, str(e)) return # Mark the account as logged-in and connected info.thing.setStateValue(accountLoggedInStateTypeId, True) info.thing.setStateValue(accountConnectedStateTypeId, True) # Create an account session on the session to get info about the login account = Account(oAuthSession) accountsMap[info.thing] = account # List all robots associated with account logger.log("account created. Robots:", account.robots) thingDescriptors = [] for robot in account.robots: logger.log("Found new robot:", robot.serial) # Check if this robot is already added in nymea found = False for thing in myThings(): logger.log("Comparing to existing robot:", thing.name) if thing.thingClassId == robotThingClassId and thing.paramValue( robotThingSerialParamTypeId) == robot.serial: logger.log("Already have this robot in the system") # Yep, already here... skip it found = True break if found: continue logger.log("Adding new robot to the system with parent", info.thing.id) thingDescriptor = nymea.ThingDescriptor(robotThingClassId, robot.name, parentId=info.thing.id) thingDescriptor.params = [ nymea.Param(robotThingSerialParamTypeId, robot.serial), nymea.Param(robotThingSecretParamTypeId, robot.secret) ] thingDescriptors.append(thingDescriptor) # And let nymea know about all the users robots autoThingsAppeared(thingDescriptors) # If no poll timer is set up yet, start it now logger.log("Creating polltimer") global pollTimer if pollTimer is None: pollTimer = threading.Timer(5, pollService) pollTimer.start() return # Setup for the robots if info.thing.thingClassId == robotThingClassId: logger.log("SetupThing for robot:", info.thing.name) serial = info.thing.paramValue(robotThingSerialParamTypeId) secret = info.thing.paramValue(robotThingSecretParamTypeId) try: robot = Robot(serial, secret, info.thing.name) thingsAndRobots[info.thing] = robot refreshRobot(info.thing) except Exception as e: logger.warn("Error setting up robot:", e) info.finish(nymea.ThingErrorHardwareFailure, str(e)) return info.thing.setStateValue(robotConnectedStateTypeId, True) # set up polling for robot status info.finish(nymea.ThingErrorNoError) return
def setupThing(info): # Setup for the account if info.thing.thingClassId == accountThingClassId: pluginStorage().beginGroup(info.thing.id) token = json.loads(pluginStorage().value("token")) logger.log("setup", token) pluginStorage().endGroup() try: oAuthSession = OAuthSession(token=token) # Login went well, finish the setup info.finish(nymea.ThingErrorNoError) except: # Login error info.finish(nymea.ThingErrorAuthenticationFailure, "Login error") return # Mark the account as logged-in and connected info.thing.setStateValue(accountLoggedInStateTypeId, True) info.thing.setStateValue(accountConnectedStateTypeId, True) # Create an account session on the session to get info about the login account = Account(oAuthSession) # List all robots associated with account logger.log("account created. Robots:", account.robots) logger.log("Persistent maps: ", account.persistent_maps) mapDict = account.persistent_maps mapKeys = mapDict.keys() logger.log("Keys: ", mapKeys) mapValues = mapDict.values() logger.log("Values: ", mapValues) thingDescriptors = [] for robot in account.robots: logger.log(robot) # Check if this robot is already added in nymea found = False for thing in myThings(): if thing.paramValue( robotThingSerialParamTypeId) == robot.serial: # Yep, already here... skip it found = True continue if found: continue thingDescriptor = nymea.ThingDescriptor(robotThingClassId, robot.name) logger.log("MapID for Serial: ", robot.serial, mapDict[robot.serial]) mapInfo = mapDict[robot.serial] logger.log("Type mapInfo: ", type(mapInfo)) logger.log("Contents mapInfo: ", mapInfo) mapInfo2 = mapInfo[0] logger.log("MapInfo2 type: ", type(mapInfo2), " MapInfo2 contents: ", mapInfo2) mapId = mapInfo2['id'] logger.log("MapId type: ", type(mapId), " MapId contents: ", mapId) mapName = mapInfo2['name'] logger.log("MapName type: ", type(mapName), " MapName contents: ", mapName) mapIDshort = mapId thingDescriptor.params = [ nymea.Param(robotThingSerialParamTypeId, robot.serial), nymea.Param(robotThingSecretParamTypeId, robot.secret), nymea.Param(robotThingMapIdParamTypeId, mapIDshort) ] thingDescriptors.append(thingDescriptor) # And let nymea know about all the users robots autoThingsAppeared(thingDescriptors) # return # If no poll timer is set up yet, start it now logger.log("Creating polltimer") global pollTimer pollTimer = threading.Timer(5, pollService) pollTimer.start() return # Setup for the robots if info.thing.thingClassId == robotThingClassId: serial = info.thing.paramValue(robotThingSerialParamTypeId) secret = info.thing.paramValue(robotThingSecretParamTypeId) robot = Robot(serial, secret, info.thing.name) thingsAndRobots[info.thing] = robot logger.log(robot.get_robot_state()) # set up polling for robot status info.finish(nymea.ThingErrorNoError) return
def onCommand(self, Unit, Command, Level, Hue): Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level)) robot = Robot(self.DEVICE_SERIAL, self.API_SECRET, self.DEVICE_NAME) response = robot.state state = response['state'] action = response['action'] category = response['cleaning']['category'] if self.statusUnit not in Devices: Domoticz.Error('Status device is required') return if self.statusUnit == Unit: if 'On' == Command and self.isOFF: robot.start_cleaning() UpdateDevice(self.statusUnit, 1, self.actions.get(103)) elif 'Off' == Command and self.isON: robot.send_to_base() UpdateDevice(self.statusUnit, 0, self.actions.get(4)) if self.controlUnit == Unit: if Level == 10 and self.isOFF: # Clean if state == 1: #Idle robot.start_cleaning() elif state == 3: #Pause robot.resume_cleaning() UpdateDevice(self.statusUnit, 1, self.actions.get(103)) elif Level == 20: # Base robot.send_to_base() UpdateDevice(self.statusUnit, 0, self.actions.get(4)) elif Level == 30 and self.isOFF: # Spot robot.start_spot_cleaning() UpdateDevice(self.statusUnit, 1, self.actions.get(2)) elif Level == 40 and self.isON: # Pause robot.pause_cleaning() UpdateDevice(self.statusUnit, 0, self.actions.get(3)) elif Level == 50 and self.isON: # Stop robot.stop_cleaning() UpdateDevice(self.statusUnit, 0, self.actions.get(100)) if self.scheduleUnit == Unit: if Command == 'On': robot.enable_schedule() UpdateDevice(self.scheduleUnit, 1, '') elif Command == 'Off': robot.disable_schedule() UpdateDevice(self.scheduleUnit, 0, '')
from pybotvac import Robot import os import json import time import requests robot_identity_raw = open(os.path.expanduser("~/.robot_identity.json")).read() robot_identity = json.loads(robot_identity_raw) robot = Robot(serial=robot_identity["serial"], secret=robot_identity["secret"], name=robot_identity["name"], traits=robot_identity["traits"]) while True: try: robot_state = robot.state if robot_state['details']['isDocked']: print("Neato is docked") if robot.state['details']['charge'] >= 60: print("Neato is charged") print("Neato is ready") requests.get('http://10.2.3.13/cgi-bin/neato-ready') else: print("Neato is not ready, because it is not charged") requests.get('http://10.2.3.13/cgi-bin/neato-not-ready') else: print("Neato is not ready, because it is not docked") requests.get('http://10.2.3.13/cgi-bin/neato-not-ready') except: print("Neato is not ready, because something went wrong") requests.get('http://10.2.3.13/cgi-bin/neato-not-ready')