Skip to content

Commit

Permalink
verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
thehappydinoa committed Jul 20, 2018
1 parent af449fc commit 521f392
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions itachip2ir/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class iTach(object):
"""iTach class"""
devices = {}

def __init__(self, ipaddress="192.168.1.111", port=4998):
def __init__(self, ipaddress="192.168.1.111", port=4998, verbose=False):
"""init method"""
self.ipaddress = ipaddress
self.port = port
self.verbose = verbose

def __repr__(self):
return "iTach(devices=%s, ipaddress=%s, port=%d)" % (
Expand All @@ -37,7 +38,7 @@ def add(self, *args):
def send_command(self, device_name, command_name):
"""sends command to device"""
device = self.devices[device_name]
return device.send_command(command_name)
return device.send_command(command_name, verbose=self.verbose)


class VirtualDevice(object):
Expand Down Expand Up @@ -81,14 +82,19 @@ def format_command_name(self, command_name):
command = self.commands[command_name]
return self.format_command(command).encode()

def send_command(self, command_name, byte_size=4096, timeout=3):
def send_command(self, command_name, byte_size=4096, timeout=3, verbose=False):
"""send command from commands"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
try:
sock.connect((self.ipaddress, self.port))
sock.sendall(self.format_command_name(command_name))
return self.format_message(sock.recv(byte_size))
command = self.format_command_name(command_name)
sock.sendall(command)
response = self.format_message(sock.recv(byte_size))
if verbose:
print("Sent: " + command)
print("Received: " + response)
return response
except socket.error as error:
raise iTachException(str(error))
finally:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='itachip2ir',
version='1.3.9',
version='1.3.10',
description='A small Python module for interacting with the Global Cache iTach WF2IR or IP2IR',
long_description=long_description,
url='https://github.com/thehappydinoa/itachip2ir',
Expand Down

0 comments on commit 521f392

Please sign in to comment.