Skip to content

Commit

Permalink
Merge pull request #7 from bieniu/dev
Browse files Browse the repository at this point in the history
Version 0.1.5
  • Loading branch information
bieniu authored Feb 21, 2020
2 parents d73ddcc + 3be74fc commit 17566ca
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
29 changes: 22 additions & 7 deletions brother/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import logging

import chardet
from pysnmp.error import PySnmpError
import pysnmp.hlapi.asyncio as hlapi
from pysnmp.hlapi.asyncore.cmdgen import lcd
Expand Down Expand Up @@ -60,13 +61,27 @@ async def async_update(self):
)
try:
self.firmware = raw_data[OIDS[ATTR_FIRMWARE]]
data[ATTR_STATUS] = (
raw_data[OIDS[ATTR_STATUS]]
.strip()
.encode("latin1")
.decode("iso_8859_2")
.lower()
)
code_page = chardet.detect(raw_data[OIDS[ATTR_STATUS]].encode("latin1"))[
"encoding"
]
# chardet detects Polish as ISO-8859-1 but Polish should use ISO-8859-2
print(code_page)
if code_page == "ISO-8859-1":
data[ATTR_STATUS] = (
raw_data[OIDS[ATTR_STATUS]]
.strip()
.encode("latin1")
.decode("iso_8859_2")
.lower()
)
else:
data[ATTR_STATUS] = (
raw_data[OIDS[ATTR_STATUS]]
.strip()
.encode("latin1")
.decode(code_page)
.lower()
)
data[ATTR_PAGE_COUNT] = raw_data[OIDS[ATTR_PAGE_COUNT]]
data[ATTR_UPTIME] = round(int(raw_data[OIDS[ATTR_UPTIME]]) / 8640000)
except (AttributeError, KeyError, TypeError):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="brother",
version="0.1.4",
version="0.1.5",
author="Maciej Bieniek",
author_email="[email protected]",
description="Python wrapper for getting data from Brother laser and inkjet \
Expand All @@ -14,7 +14,7 @@
license="Apache 2",
packages=["brother"],
python_requires=">=3.6",
install_requires=["pysnmp"],
install_requires=["pysnmp", "chardet"],
classifiers=[
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
Expand Down
19 changes: 19 additions & 0 deletions tests/data/dcp-l2540dn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.10.0": ["0001040000014d"],
"1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.17.0": "R1906110243",
"1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.8.0": [
"63010400000001",
"1101040000014d",
"41010400002648",
"31010400000001",
"6f01040000157c",
"8101040000003c",
"86010400000010"
],
"1.3.6.1.4.1.2435.2.4.3.2435.5.13.3.0": "Brother DCP-L2540DN series",
"1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.11.0": ["82010400002d93"],
"1.3.6.1.2.1.43.10.2.1.4.1.1": "333",
"1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.1.0": "serial_number",
"1.3.6.1.4.1.2435.2.3.9.4.2.1.5.4.5.2.0": "ÁßïéØÙ àÕÖØÜ ",
"1.3.6.1.2.1.1.3.0": "1171125"
}
20 changes: 20 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ async def test_dcp_j132w_model():
assert brother.data["page_counter"] == 879


@pytest.mark.asyncio
async def test_dcp_l2540dw_model():
"""Test with valid data from DCP-L2540DN printer with status in Russian."""
with open("tests/data/dcp-l2540dn.json") as file:
data = json.load(file)

with patch("brother.Brother._get_data", return_value=data):

brother = Brother(HOST, kind="laser")
await brother.async_update()

assert brother.available == True
assert brother.model == "DCP-L2540DN"
assert brother.firmware == "R1906110243"
assert brother.serial == "serial_number"
assert brother.data["status"] == "спящий режим"
assert brother.data["black_toner_remaining"] == 55
assert brother.data["page_counter"] == 333


@pytest.mark.asyncio
async def test_mfc_j680dw_model():
"""Test with valid data from MFC-J680DW printer."""
Expand Down

0 comments on commit 17566ca

Please sign in to comment.