Skip to content

Commit

Permalink
Merge pull request #29 from bieniu/fix-uptime
Browse files Browse the repository at this point in the history
Fix uptime
  • Loading branch information
bieniu authored May 18, 2021
2 parents 20cc4a2 + fea011d commit 7c81c52
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions brother/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
import logging
import re
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, Generator, Iterable, cast

import pysnmp.hlapi.asyncio as hlapi
Expand Down Expand Up @@ -130,10 +130,10 @@ async def async_update(self) -> DictToObj:
if not self._last_uptime:
data[ATTR_UPTIME] = self._last_uptime = ( # type: ignore[assignment]
datetime.utcnow() - timedelta(seconds=uptime)
).replace(microsecond=0)
).replace(microsecond=0, tzinfo=timezone.utc)
else:
new_uptime = (datetime.utcnow() - timedelta(seconds=uptime)).replace(
microsecond=0
microsecond=0, tzinfo=timezone.utc
)
if abs((new_uptime - self._last_uptime).total_seconds()) > 5:
data[ATTR_UPTIME] = self._last_uptime = new_uptime
Expand Down
Empty file added brother/py.typed
Empty file.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="brother",
version="1.0.1",
version="1.0.2",
author="Maciej Bieniek",
description="Python wrapper for getting data from Brother laser and inkjet \
printers via SNMP.",
Expand Down
8 changes: 4 additions & 4 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def test_hl_l2340dw_model():
assert getattr(sensors, "status") == "oczekiwanie"
assert getattr(sensors, "black_toner") == 80
assert getattr(sensors, "page_counter") == 986
assert getattr(sensors, "uptime").isoformat() == "2019-09-24T12:14:56"
assert getattr(sensors, "uptime").isoformat() == "2019-09-24T12:14:56+00:00"


@pytest.mark.asyncio
Expand Down Expand Up @@ -107,7 +107,7 @@ async def test_mfc_5490cn_model():
assert brother.serial == "serial_number"
assert getattr(sensors, "status") == "sleep mode"
assert getattr(sensors, "page_counter") == 8989
assert getattr(sensors, "uptime").isoformat() == "2019-11-02T23:44:02"
assert getattr(sensors, "uptime").isoformat() == "2019-11-02T23:44:02+00:00"


@pytest.mark.asyncio
Expand Down Expand Up @@ -153,7 +153,7 @@ async def test_dcp_7070dw_model():
assert getattr(sensors, "drum_counter") == 1603
assert getattr(sensors, "drum_remaining_life") == 88
assert getattr(sensors, "drum_remaining_pages") == 10397
assert getattr(sensors, "uptime").isoformat() == "2018-11-30T13:43:26"
assert getattr(sensors, "uptime").isoformat() == "2018-11-30T13:43:26+00:00"

# test uptime logic, uptime increased by 10 minutes
data["1.3.6.1.2.1.1.3.0"] = "2987742561"
Expand All @@ -164,7 +164,7 @@ async def test_dcp_7070dw_model():

brother.shutdown()

assert getattr(sensors, "uptime").isoformat() == "2018-11-30T13:53:26"
assert getattr(sensors, "uptime").isoformat() == "2018-11-30T13:53:26+00:00"


@pytest.mark.asyncio
Expand Down

0 comments on commit 7c81c52

Please sign in to comment.