Skip to content

Commit

Permalink
1.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
thehappydinoa committed Jul 19, 2018
1 parent 234b14d commit af449fc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 69 deletions.
2 changes: 2 additions & 0 deletions itachip2ir/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""__init__ for itachip2ir"""
from itachip2ir.device import VirtualDevice, iTach
from itachip2ir.exception import iTachException


# from itachip2ir.test_listener import iTachTester
4 changes: 2 additions & 2 deletions itachip2ir/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import socket
from contextlib import closing

from .exception import iTachException
from itachip2ir.exception import iTachException


class iTach(object):
Expand Down Expand Up @@ -90,7 +90,7 @@ def send_command(self, command_name, byte_size=4096, timeout=3):
sock.sendall(self.format_command_name(command_name))
return self.format_message(sock.recv(byte_size))
except socket.error as error:
return iTachException(error)
raise iTachException(str(error))
finally:
sock.close()

Expand Down
121 changes: 61 additions & 60 deletions itachip2ir/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,71 @@
class iTachException(Exception):
"""iTachException Exception"""

def __init__(self, response):
def __init__(self, msg):
"""init method"""
message = self.error_handler(response)
message = self.error_handler(msg)
super(iTachException, self).__init__(message)
self.message = message

def error_handler(self, response):
def error_handler(self, msg):
"""error handler"""
if response.startswith("ERR_01"):
response = self.invalid_error("command. Command not found.")
elif response.startswith("ERR_02"):
response = self.invalid_error("module address (does not exist).")
elif response.startswith("ERR_03"):
response = self.invalid_error("connector address (does not exist).")
elif response.startswith("ERR_04"):
response = self.invalid_error("ID value.")
elif response.startswith("ERR_05"):
response = self.invalid_error("frequency value")
elif response.startswith("ERR_06"):
response = self.invalid_error("repeat value.")
elif response.startswith("ERR_07"):
response = self.invalid_error("offset value.")
elif response.startswith("ERR_08"):
response = self.invalid_error("pulse count.")
elif response.startswith("ERR_09"):
response = self.invalid_error("pulse data.")
elif response.startswith("ERR_10"):
response = "Uneven amount of <on|off> statements."
elif response.startswith("ERR_11"):
response = "No carriage return found."
elif response.startswith("ERR_12"):
response = "Repeat count exceeded."
elif response.startswith("ERR_13"):
response = "IR command sent to input connector."
elif response.startswith("ERR_14"):
response = "Blaster command sent to non-blaster connector."
elif response.startswith("ERR_15"):
response = "No carriage return before buffer full."
elif response.startswith("ERR_16"):
response = "No carriage return."
elif response.startswith("ERR_17"):
response = "Bad command syntax."
elif response.startswith("ERR_18"):
response = "Sensor command sent to non-input connector."
elif response.startswith("ERR_19"):
response = "Repeated IR transmission failure."
elif response.startswith("ERR_20"):
response = "Above designated IR <on|off> pair limit."
elif response.startswith("ERR_21"):
response = "Symbol odd boundary."
elif response.startswith("ERR_22"):
response = "Undefined symbol."
elif response.startswith("ERR_23"):
response = "Unknown option."
elif response.startswith("ERR_24"):
response = self.invalid_error("baud rate setting.")
elif response.startswith("ERR_25"):
response = self.invalid_error("flow control setting.")
elif response.startswith("ERR_26"):
response = self.invalid_error("parity setting.")
elif response.startswith("ERR_27"):
response = "Settings are locked."
return response
if msg.startswith("ERR_01"):
msg = self.invalid_error("command. Command not found.")
elif msg.startswith("ERR_02"):
msg = self.invalid_error("module address (does not exist).")
elif msg.startswith("ERR_03"):
msg = self.invalid_error(
"connector address (does not exist).")
elif msg.startswith("ERR_04"):
msg = self.invalid_error("ID value.")
elif msg.startswith("ERR_05"):
msg = self.invalid_error("frequency value")
elif msg.startswith("ERR_06"):
msg = self.invalid_error("repeat value.")
elif msg.startswith("ERR_07"):
msg = self.invalid_error("offset value.")
elif msg.startswith("ERR_08"):
msg = self.invalid_error("pulse count.")
elif msg.startswith("ERR_09"):
msg = self.invalid_error("pulse data.")
elif msg.startswith("ERR_10"):
msg = "Uneven amount of <on|off> statements."
elif msg.startswith("ERR_11"):
msg = "No carriage return found."
elif msg.startswith("ERR_12"):
msg = "Repeat count exceeded."
elif msg.startswith("ERR_13"):
msg = "IR command sent to input connector."
elif msg.startswith("ERR_14"):
msg = "Blaster command sent to non-blaster connector."
elif msg.startswith("ERR_15"):
msg = "No carriage return before buffer full."
elif msg.startswith("ERR_16"):
msg = "No carriage return."
elif msg.startswith("ERR_17"):
msg = "Bad command syntax."
elif msg.startswith("ERR_18"):
msg = "Sensor command sent to non-input connector."
elif msg.startswith("ERR_19"):
msg = "Repeated IR transmission failure."
elif msg.startswith("ERR_20"):
msg = "Above designated IR <on|off> pair limit."
elif msg.startswith("ERR_21"):
msg = "Symbol odd boundary."
elif msg.startswith("ERR_22"):
msg = "Undefined symbol."
elif msg.startswith("ERR_23"):
msg = "Unknown option."
elif msg.startswith("ERR_24"):
msg = self.invalid_error("baud rate setting.")
elif msg.startswith("ERR_25"):
msg = self.invalid_error("flow control setting.")
elif msg.startswith("ERR_26"):
msg = self.invalid_error("parity setting.")
elif msg.startswith("ERR_27"):
msg = "Settings are locked."
return msg

def invalid_error(self, message):
def invalid_error(self, msg):
"""invalid error"""
return "Invalid " + message
return "Invalid " + msg
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.8',
version='1.3.9',
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
13 changes: 7 additions & 6 deletions tests/test_itach.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest

import itachip2ir
from itachip2ir import VirtualDevice, iTach
from itachip2ir.exception import iTachException


class TestITach(object):
class TestiTach(object):
def test_itach(self):
itach = iTach(ipaddress="192.168.1.111", port=4998)
itach = iTach(ipaddress="192.168.1.111")
assert itach.ipaddress == "192.168.1.111"
assert itach.port == 4998
assert itach.devices == {}
Expand Down Expand Up @@ -39,13 +39,14 @@ def test_devices(self):
assert device2.commands == commands

def test_exception(self):
with pytest.raises(iTachException):
raise iTachException("ERR_01")
with pytest.raises(itachip2ir.iTachException):
raise itachip2ir.iTachException("ERR_01")

def test_command(self):
name = "device"
commands = {"test_command": "test_ir"}
itach = iTach(ipaddress="localhost", port=4998)
device = itach.add(VirtualDevice(
name=name, commands=commands))
assert isinstance(device.test_command(), iTachException)
with pytest.raises(itachip2ir.iTachException):
response = device.test_command()

0 comments on commit af449fc

Please sign in to comment.