from nperipherals_core.model.device import CashDrawer


class CashDrawerOpenInteractor(object):
    def __init__(self, device):
        # type: (CashDrawer) -> None

        self.device = device

    def open_drawer(self):
        connected = False
        try:
            self.device.initialize()
            self.device.connect()
            connected = True

            self.device.open_drawer()
            return 0

        finally:
            if connected:
                self.device.disconnect()
