Merge pull request #14 from OverloadUT/fix-command-formatting
Fix for commands that need to be CamelCased
This commit is contained in:
+9
-7
@@ -195,6 +195,7 @@ class VacBot(ClientXMPP):
|
|||||||
|
|
||||||
def send_command(self, xml):
|
def send_command(self, xml):
|
||||||
c = self.wrap_command(xml)
|
c = self.wrap_command(xml)
|
||||||
|
logging.debug('Sending command {0}'.format(c))
|
||||||
c.send()
|
c.send()
|
||||||
|
|
||||||
def wrap_command(self, ctl):
|
def wrap_command(self, ctl):
|
||||||
@@ -228,7 +229,7 @@ class VacBot(ClientXMPP):
|
|||||||
|
|
||||||
|
|
||||||
class VacBotCommand:
|
class VacBotCommand:
|
||||||
def __init__(self, name, args, wait=None, terminal=False):
|
def __init__(self, name, args=None, wait=None, terminal=False):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.args = args
|
self.args = args
|
||||||
self.wait = wait
|
self.wait = wait
|
||||||
@@ -240,8 +241,9 @@ class VacBotCommand:
|
|||||||
time.sleep(self.wait)
|
time.sleep(self.wait)
|
||||||
|
|
||||||
def to_xml(self):
|
def to_xml(self):
|
||||||
ctl = ET.Element('ctl', {'td': self.name.capitalize()})
|
ctl = ET.Element('ctl', {'td': self.name})
|
||||||
inner = ET.Element(self.name, self.args)
|
if self.args:
|
||||||
|
inner = ET.Element(self.name.lower(), self.args)
|
||||||
ctl.append(inner)
|
ctl.append(inner)
|
||||||
return ctl
|
return ctl
|
||||||
|
|
||||||
@@ -254,17 +256,17 @@ class VacBotCommand:
|
|||||||
|
|
||||||
class Clean(VacBotCommand):
|
class Clean(VacBotCommand):
|
||||||
def __init__(self, wait):
|
def __init__(self, wait):
|
||||||
super().__init__('clean', {'type': 'auto', 'speed': 'standard'}, wait)
|
super().__init__('Clean', {'type': 'auto', 'speed': 'standard'}, wait)
|
||||||
|
|
||||||
|
|
||||||
class Edge(VacBotCommand):
|
class Edge(VacBotCommand):
|
||||||
def __init__(self, wait):
|
def __init__(self, wait):
|
||||||
super().__init__('clean', {'type': 'border', 'speed': 'strong'}, wait)
|
super().__init__('Clean', {'type': 'border', 'speed': 'strong'}, wait)
|
||||||
|
|
||||||
|
|
||||||
class Charge(VacBotCommand):
|
class Charge(VacBotCommand):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('charge', {'type': 'go'}, terminal=True)
|
super().__init__('Charge', {'type': 'go'}, terminal=True)
|
||||||
|
|
||||||
def wait_for_completion(self, bot):
|
def wait_for_completion(self, bot):
|
||||||
logging.debug("waiting in " + self.name)
|
logging.debug("waiting in " + self.name)
|
||||||
@@ -276,7 +278,7 @@ class Charge(VacBotCommand):
|
|||||||
|
|
||||||
class Stop(VacBotCommand):
|
class Stop(VacBotCommand):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('clean', {'type': 'stop', 'speed': 'standard'}, terminal=True)
|
super().__init__('Clean', {'type': 'stop', 'speed': 'standard'}, terminal=True)
|
||||||
|
|
||||||
def wait_for_completion(self, bot):
|
def wait_for_completion(self, bot):
|
||||||
logging.debug("waiting in " + self.name)
|
logging.debug("waiting in " + self.name)
|
||||||
|
|||||||
@@ -10,6 +10,20 @@ from sucks import *
|
|||||||
# the library's design and its multithreaded nature, and b) I'm manually testing every change anyhow,
|
# the library's design and its multithreaded nature, and b) I'm manually testing every change anyhow,
|
||||||
# as it's not clear how the robot really behaves.
|
# as it's not clear how the robot really behaves.
|
||||||
|
|
||||||
|
def test_custom_command():
|
||||||
|
# Ensure a custom-built command generates the expected XML payload
|
||||||
|
c = VacBotCommand('CustomCommand', {'type': 'customtype'})
|
||||||
|
assert_equals(ElementTree.tostring(c.to_xml()),
|
||||||
|
|
||||||
|
b'<ctl td="CustomCommand"><customcommand type="customtype" /></ctl>')
|
||||||
|
|
||||||
|
def test_custom_command_noargs():
|
||||||
|
# Ensure a custom-built command with no args generates XML without an args element
|
||||||
|
c = VacBotCommand('CustomCommand')
|
||||||
|
assert_equals(ElementTree.tostring(c.to_xml()),
|
||||||
|
b'<ctl td="CustomCommand" />')
|
||||||
|
|
||||||
|
|
||||||
def test_clean_command():
|
def test_clean_command():
|
||||||
c = Clean(10)
|
c = Clean(10)
|
||||||
assert_equals(c.terminal, False)
|
assert_equals(c.terminal, False)
|
||||||
|
|||||||
Reference in New Issue
Block a user