Refinements
This commit is contained in:
@@ -177,9 +177,9 @@ ValueError
|
|||||||
'URL_path': 'Epson_IPP_Printer',
|
'URL_path': 'Epson_IPP_Printer',
|
||||||
'UpTime': '00:57:48',
|
'UpTime': '00:57:48',
|
||||||
'WiFi': '....',
|
'WiFi': '....',
|
||||||
'data': 'MFG:EPSON;CMD:ESCPL2,BDC,D4,D4PX,ESCPR1;MDL:XP-205 207 '
|
'device_id': 'MFG:EPSON;CMD:ESCPL2,BDC,D4,D4PX,ESCPR1;MDL:XP-205 207 '
|
||||||
'Series;CLS:PRINTER;DES:EPSON XP-205 207 '
|
'Series;CLS:PRINTER;DES:EPSON XP-205 207 '
|
||||||
'Series;CID:EpsonRGB;FID:FXN,DPN,WFA,ETN,AFN,DAN;RID:40;',
|
'Series;CID:EpsonRGB;FID:FXN,DPN,WFA,ETN,AFN,DAN;RID:40;',
|
||||||
'hex_data': 'A4 EE 57 DE FD 03'},
|
'hex_data': 'A4 EE 57 DE FD 03'},
|
||||||
'stats': {'First TI received time': '...',
|
'stats': {'First TI received time': '...',
|
||||||
'Ink replacement cleaning counter': 78,
|
'Ink replacement cleaning counter': 78,
|
||||||
|
|||||||
@@ -2,17 +2,17 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Epson Printer Configuration accessed via SNMP (TCP/IP)
|
Epson Printer Configuration via SNMP (TCP/IP)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
import datetime
|
import datetime
|
||||||
import easysnmp # pip3 install easysnmp
|
|
||||||
import time
|
import time
|
||||||
import textwrap
|
import textwrap
|
||||||
import ast
|
import ast
|
||||||
|
import easysnmpeasysnmpeasys # pip3 install easysnmp
|
||||||
|
|
||||||
|
|
||||||
class EpsonPrinter:
|
class EpsonPrinter:
|
||||||
@@ -187,9 +187,9 @@ class EpsonPrinter:
|
|||||||
# to be completed
|
# to be completed
|
||||||
},
|
},
|
||||||
"XP-610": {
|
"XP-610": {
|
||||||
|
"alias": ["XP-611", "XP-615", "XP-510"],
|
||||||
"read_key": [121, 4],
|
"read_key": [121, 4],
|
||||||
"write_key": b'Gossypiu',
|
"write_key": b'Gossypiu',
|
||||||
"alias": ["XP-611", "XP-615", "XP-510"],
|
|
||||||
"main_waste": {"oids": [16, 17], "divider": 84.5}, # divider to be changed
|
"main_waste": {"oids": [16, 17], "divider": 84.5}, # divider to be changed
|
||||||
"borderless_waste": {"oids": [18, 19], "divider": 33.7}, # divider to be changed
|
"borderless_waste": {"oids": [18, 19], "divider": 33.7}, # divider to be changed
|
||||||
# to be completed
|
# to be completed
|
||||||
@@ -208,9 +208,9 @@ class EpsonPrinter:
|
|||||||
# to be completed
|
# to be completed
|
||||||
},
|
},
|
||||||
"XP-830": {
|
"XP-830": {
|
||||||
|
"alias": ["XP-530", "XP-630", "XP-635"],
|
||||||
"read_key": [40, 9],
|
"read_key": [40, 9],
|
||||||
"write_key": b'Irisgarm', # (Iris graminea with typo?)
|
"write_key": b'Irisgarm', # (Iris graminea with typo?)
|
||||||
"alias": ["XP-530", "XP-630", "XP-635"],
|
|
||||||
"main_waste": {"oids": [0x10, 0x11], "divider": 84.5}, # To be changed
|
"main_waste": {"oids": [0x10, 0x11], "divider": 84.5}, # To be changed
|
||||||
"borderless_waste": {"oids": [0x12, 0x13], "divider": 33.7}, # To be changed
|
"borderless_waste": {"oids": [0x12, 0x13], "divider": 33.7}, # To be changed
|
||||||
"idProduct": 0x110b,
|
"idProduct": 0x110b,
|
||||||
@@ -266,7 +266,7 @@ class EpsonPrinter:
|
|||||||
"URL": "1.3.6.1.4.1.1248.1.1.3.1.4.46.1.2.1",
|
"URL": "1.3.6.1.4.1.1248.1.1.3.1.4.46.1.2.1",
|
||||||
"WiFi": "1.3.6.1.4.1.1248.1.1.3.1.29.2.1.9.0",
|
"WiFi": "1.3.6.1.4.1.1248.1.1.3.1.29.2.1.9.0",
|
||||||
"hex_data": "1.3.6.1.4.1.1248.1.1.3.1.1.5.0",
|
"hex_data": "1.3.6.1.4.1.1248.1.1.3.1.1.5.0",
|
||||||
"data": "1.3.6.1.4.1.11.2.3.9.1.1.7.0",
|
"device_id": "1.3.6.1.4.1.11.2.3.9.1.1.7.0",
|
||||||
}
|
}
|
||||||
|
|
||||||
SNMP_OID_ENTERPRISE = "1.3.6.1.4.1"
|
SNMP_OID_ENTERPRISE = "1.3.6.1.4.1"
|
||||||
@@ -310,7 +310,7 @@ class EpsonPrinter:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def valid_printers(self):
|
def valid_printers(self):
|
||||||
"""Return list of valid printers."""
|
"""Return list of defined printers."""
|
||||||
return {
|
return {
|
||||||
printer_name
|
printer_name
|
||||||
for printer_name in self.PRINTER_CONFIG.keys()
|
for printer_name in self.PRINTER_CONFIG.keys()
|
||||||
@@ -319,12 +319,12 @@ class EpsonPrinter:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def list_methods(self):
|
def list_methods(self):
|
||||||
"""Return list of available information methods about the printer."""
|
"""Return list of available information methods about a printer."""
|
||||||
return(filter(lambda x: x.startswith("get_") and x not in dir(
|
return(filter(lambda x: x.startswith("get_") and x not in dir(
|
||||||
easysnmp.Session), dir(self.session)))
|
easysnmp.Session), dir(self.session)))
|
||||||
|
|
||||||
def stats(self):
|
def stats(self):
|
||||||
"""Return all available information about the printer."""
|
"""Return all available information about a printer."""
|
||||||
stat_set = {}
|
stat_set = {}
|
||||||
for method in self.list_methods:
|
for method in self.list_methods:
|
||||||
ret = self.session.__getattribute__(method)()
|
ret = self.session.__getattribute__(method)()
|
||||||
@@ -336,6 +336,7 @@ class EpsonPrinter:
|
|||||||
return stat_set
|
return stat_set
|
||||||
|
|
||||||
def caesar(self, key):
|
def caesar(self, key):
|
||||||
|
"""Convert the string write key to a sequence of numbers"""
|
||||||
return ".".join(str(b + 1) for b in key)
|
return ".".join(str(b + 1) for b in key)
|
||||||
|
|
||||||
|
|
||||||
@@ -363,10 +364,16 @@ class EpsonSession(easysnmp.Session):
|
|||||||
oid: int,
|
oid: int,
|
||||||
msb: int = 0,
|
msb: int = 0,
|
||||||
label: str = "unknown method") -> str:
|
label: str = "unknown method") -> str:
|
||||||
"""Return address for reading from EEPROM for specified OID."""
|
"""
|
||||||
|
Return the OID string to read the value of the EEPROM address 'oid'.
|
||||||
|
oid can be a number between 0x0000 and 0xffff.
|
||||||
|
Return None in case of error.
|
||||||
|
"""
|
||||||
if oid > 255:
|
if oid > 255:
|
||||||
msb = oid // 256
|
msb = oid // 256
|
||||||
oid = oid % 256
|
oid = oid % 256
|
||||||
|
if msb > 255:
|
||||||
|
return None
|
||||||
if 'read_key' not in self.printer.parm:
|
if 'read_key' not in self.printer.parm:
|
||||||
return None
|
return None
|
||||||
return (
|
return (
|
||||||
@@ -385,10 +392,16 @@ class EpsonSession(easysnmp.Session):
|
|||||||
value: Any,
|
value: Any,
|
||||||
msb: int = 0,
|
msb: int = 0,
|
||||||
label: str = "unknown method") -> str:
|
label: str = "unknown method") -> str:
|
||||||
"""Return address for writing to EEPROM for specified OID."""
|
"""
|
||||||
|
Return the OID string to write a value to the EEPROM address 'oid'.
|
||||||
|
oid can be a number between 0x0000 and 0xffff.
|
||||||
|
Return None in case of error.
|
||||||
|
"""
|
||||||
if oid > 255:
|
if oid > 255:
|
||||||
msb = oid // 256
|
msb = oid // 256
|
||||||
oid = oid % 256
|
oid = oid % 256
|
||||||
|
if msb > 255:
|
||||||
|
return None
|
||||||
if ('write_key' not in self.printer.parm
|
if ('write_key' not in self.printer.parm
|
||||||
or 'read_key' not in self.printer.parm):
|
or 'read_key' not in self.printer.parm):
|
||||||
return None
|
return None
|
||||||
@@ -409,7 +422,7 @@ class EpsonSession(easysnmp.Session):
|
|||||||
return write_op
|
return write_op
|
||||||
|
|
||||||
def read_value(self, oids: str):
|
def read_value(self, oids: str):
|
||||||
"""Return value of OIDs."""
|
"""Generic SNMP query, returning value of OIDs."""
|
||||||
try:
|
try:
|
||||||
value = self.get(oids).value
|
value = self.get(oids).value
|
||||||
except easysnmp.exceptions.EasySNMPTimeoutError as e:
|
except easysnmp.exceptions.EasySNMPTimeoutError as e:
|
||||||
@@ -422,7 +435,7 @@ class EpsonSession(easysnmp.Session):
|
|||||||
self,
|
self,
|
||||||
oid: int,
|
oid: int,
|
||||||
label: str = "unknown method") -> str:
|
label: str = "unknown method") -> str:
|
||||||
"""Read EEPROM data."""
|
"""Read a single byte from the Epson EEPROM address 'oid'."""
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print(
|
print(
|
||||||
f"EEPROM_DUMP {label}:\n"
|
f"EEPROM_DUMP {label}:\n"
|
||||||
@@ -453,7 +466,9 @@ class EpsonSession(easysnmp.Session):
|
|||||||
self,
|
self,
|
||||||
oids: list,
|
oids: list,
|
||||||
label: str = "unknown method"):
|
label: str = "unknown method"):
|
||||||
"""Read EEPROM data with multiple values."""
|
"""
|
||||||
|
Read a list of bytes from the list of Epson EEPROM addresses 'oids'.
|
||||||
|
"""
|
||||||
return [self.read_eeprom(oid, label=label) for oid in oids]
|
return [self.read_eeprom(oid, label=label) for oid in oids]
|
||||||
|
|
||||||
def write_eeprom(
|
def write_eeprom(
|
||||||
@@ -461,7 +476,7 @@ class EpsonSession(easysnmp.Session):
|
|||||||
oid: int,
|
oid: int,
|
||||||
value: int,
|
value: int,
|
||||||
label: str = "unknown method") -> None:
|
label: str = "unknown method") -> None:
|
||||||
"""Write value to OID with specified type to EEPROM."""
|
"""Write a single byte 'value' to the Epson EEPROM address 'oid'."""
|
||||||
if "write_key" not in self.printer.parm:
|
if "write_key" not in self.printer.parm:
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print(f"Missing 'write_key' parameter in configuration.")
|
print(f"Missing 'write_key' parameter in configuration.")
|
||||||
|
|||||||
Reference in New Issue
Block a user