Beispiel #1
0
 def test_connect(self):
     bot = fb.Farmbot(fake_token)
     fake_handler = 'In real life, this would be a class'
     bot._connection.start_connection = mock.MagicMock()
     bot.connect(fake_handler)
     assert bot._handler == fake_handler
     bot._connection.start_connection.assert_called()
Beispiel #2
0
    def test_various_rpcs(self):
        bot = fb.Farmbot(fake_token)
        bot._do_cs = mock.MagicMock()

        bot.send_message("Hello, world!")
        self.expected_rpc(bot, 'send_message', {
            'message': 'Hello, world!',
            'message_type': 'info'
        })

        bot.emergency_lock()
        self.expected_rpc(bot, "emergency_lock", {})

        bot.emergency_unlock()
        self.expected_rpc(bot, "emergency_unlock", {})

        bot.find_home()
        self.expected_rpc(bot, "find_home", {"speed": 100, "axis": "all"})

        bot.find_length()
        self.expected_rpc(bot, "calibrate", {"axis": "all"})

        bot.flash_farmduino("express_k10")
        self.expected_rpc(bot, "flash_firmware", {"package": "express_k10"})

        bot.go_to_home()
        self.expected_rpc(bot, "home", {"speed": 100, "axis": "all"})

        lua_str = "print('Hello, world!')"
        bot.lua(lua_str)
        self.expected_rpc(bot, "lua", {"lua": lua_str})

        bot.move_absolute(x=1.2, y=3.4, z=5.6)
        self.expected_rpc(
            bot, 'move_absolute', {
                'location': {
                    'kind': 'coordinate',
                    'args': {
                        'x': 1.2,
                        'y': 3.4,
                        'z': 5.6
                    }
                },
                'speed': 100.0,
                'offset': {
                    'kind': 'coordinate',
                    'args': {
                        'x': 0,
                        'y': 0,
                        'z': 0
                    }
                }
            })

        bot.move_relative(x=1.2, y=3.4, z=5.6)
        self.expected_rpc(bot, "move_relative", {
            "x": 1.2,
            "y": 3.4,
            "z": 5.6,
            "speed": 100
        })

        bot.power_off()
        self.expected_rpc(bot, "power_off", {})

        bot.read_status()
        self.expected_rpc(bot, "read_status", {})

        bot.reboot()
        self.expected_rpc(bot, "reboot", {"package": "farmbot_os"})

        bot.reboot_farmduino()
        self.expected_rpc(bot, "reboot", {"package": "arduino_firmware"})

        bot.factory_reset()
        self.expected_rpc(bot, "factory_reset", {"package": "farmbot_os"})

        bot.sync()
        self.expected_rpc(bot, "sync", {})

        bot.take_photo()
        self.expected_rpc(bot, "take_photo", {})

        bot.toggle_pin(12)
        self.expected_rpc(bot, "toggle_pin", {"pin_number": 12})

        bot.update_farmbot_os()
        self.expected_rpc(bot, "check_updates", {"package": "farmbot_os"})

        bot.read_pin(21)
        self.expected_rpc(bot, "read_pin", {
            'label': 'pin21',
            'pin_mode': 0,
            'pin_number': 21
        })

        bot.write_pin(45, 67)
        self.expected_rpc(bot, "write_pin", {
            'pin_mode': 0,
            'pin_number': 45,
            'pin_value': 67
        })

        bot.set_servo_angle(5, 90)
        self.expected_rpc(bot, "set_servo_angle", {
            'pin_number': 5,
            'pin_value': 90
        })
Beispiel #3
0
 def test__do_cs(self):
     fake_rpc = {"kind": "nothing", "args": {}, "body": []}
     bot = fb.Farmbot(fake_token)
     bot._connection.send_rpc = mock.MagicMock()
     bot._do_cs("nothing", {})
     bot._connection.send_rpc.assert_called_with(fake_rpc)
Beispiel #4
0
 def test_position(self):
     bot = fb.Farmbot(fake_token)
     assert bot.position() == (-0.0, -0.0, -0.0)