Skip to content

Commit b0afdf3

Browse files
authored
Merge pull request #17 from dala318/log_levels
Log levels
2 parents 5fb9b71 + 756ba38 commit b0afdf3

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
_LOGGER = logging.getLogger(__name__)
2424

2525
UPDATE_TOPIC = f"{DOMAIN}_update"
26-
ERROR_ITERVAL_MAPPING = [10, 60, 300, 600, 3000, 6000]
26+
ERROR_ITERVAL_MAPPING = [0, 10, 60, 300, 600, 3000, 6000]
2727
NOTIFICATION_ID = "ph803w_device_notification"
2828
NOTIFICATION_TITLE = "PH-803W Device status"
2929

lib/device.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def _run(self, once: bool = True) -> bool:
9191
# from now on some cyclig bahavior
9292
data = bytes.fromhex("000000030400009002")
9393
self._socket.sendall(data)
94+
self._empty_counter = 0
9495

9596
# If continous reading ping/pong needs to be run cyclic
9697
if not once:
@@ -103,7 +104,7 @@ def _run(self, once: bool = True) -> bool:
103104
while self._loop:
104105
response = self._socket.recv(1024)
105106
if self._empty_counter > ABORT_AFTER_CONSECUTIVE_EMPTY:
106-
_LOGGER.error("Too many empty consecutive packages")
107+
_LOGGER.warning("Too many empty consecutive packages")
107108
raise DeviceError("Too many empty consecutive packages")
108109
if len(response) == 0:
109110
self._empty_counter += 1
@@ -267,7 +268,7 @@ def get(self) -> float:
267268
return val
268269
except StatisticsError:
269270
return self._values[-1]
270-
_LOGGER.error("No match in outlier filter shall never happen!")
271+
_LOGGER.warning("No match in outlier filter shall never happen!")
271272
return self._values[-1]
272273

273274

lib/discovery.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@ def run(self):
3737
# Receive device reaponse to discovery
3838
data, remote = self._socket.recvfrom(1024)
3939
if data[0] != 0 and data[1] != 0 and data[2] != 0 and data[2] != 3:
40-
_LOGGER.error("Ignore data package because invalid prefix: %s" % data[0:3])
40+
_LOGGER.warning(
41+
"Ignore data package because invalid prefix: %s" % data[0:3]
42+
)
4143
raise DiscoveryError("Ignore data package because invalid prefix")
4244
data_length = data[4]
4345
if len(data) != data_length + 5:
44-
_LOGGER.error(
46+
_LOGGER.warning(
4547
"Ignore data package because invalid length(%s): %s"
4648
% (data_length, data)
4749
)
4850
raise DiscoveryError("Ignore data package because invalid length")
4951
if data[7] == 3:
50-
_LOGGER.error("Unknown response message type")
52+
_LOGGER.warning("Unknown response message type")
5153
raise DiscoveryError("Unknown response message type")
5254
if data[7] != 4:
53-
_LOGGER.error("Ignore data package because invalid message type ${data[7]}")
55+
_LOGGER.warning(
56+
"Ignore data package because invalid message type ${data[7]}"
57+
)
5458
raise DiscoveryError("Ignore data package because invalid message type")
5559

5660
# Parsing result of correct type

0 commit comments

Comments
 (0)