Skip to content

Commit

Permalink
Separate write denied exception and consider that still a valid conne…
Browse files Browse the repository at this point in the history
…ction (#171)
  • Loading branch information
yozik04 authored Jul 27, 2024
2 parents 063745d + 4c77be6 commit 0d0df66
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
11 changes: 9 additions & 2 deletions nibe/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from abc import ABC, abstractmethod
from collections.abc import AsyncIterator, Iterable
from contextlib import suppress

from nibe.coil import Coil, CoilData
from nibe.exceptions import ReadException, ReadExceptionGroup
from nibe.exceptions import ReadException, ReadExceptionGroup, WriteDeniedException
from nibe.heatpump import HeatPump, ProductInfo, Series

DEFAULT_TIMEOUT: float = 5
Expand Down Expand Up @@ -82,6 +83,10 @@ async def verify_connectivity_read_write_alarm(
To verify connection, we read the alarm reset field and write it as 0
this will be ignored by the pump, this will throw exceptions on failure.
We ignore if the write was denied since that is still indicative of a
working connection. F-series pumps that is MyUplink upgraded seem to
reject these writes.
"""
if heatpump.series == Series.S:
coil = heatpump.get_coil_by_name("reset-alarm-40023")
Expand All @@ -93,4 +98,6 @@ async def verify_connectivity_read_write_alarm(
if coil.mappings:
value = coil.mappings[str(value)]
coil_data.value = value
await connection.write_coil(coil_data)

with suppress(WriteDeniedException):
await connection.write_coil(coil_data)
3 changes: 2 additions & 1 deletion nibe/connection/modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ReadIOException,
ReadTimeoutException,
ValidationError,
WriteDeniedException,
WriteIOException,
WriteTimeoutException,
)
Expand Down Expand Up @@ -153,7 +154,7 @@ async def write_coil(
raise ReadIOException(f"Unsupported entity type {entity_type}")

if not result:
raise WriteIOException(f"Heatpump denied writing {coil.name}")
raise WriteDeniedException(f"Heatpump denied writing {coil.name}")
else:
logger.info(f"Write succeeded for {coil.name}")
except ValidationError as exc:
Expand Down
4 changes: 2 additions & 2 deletions nibe/connection/nibegw.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
ReadIOException,
ReadSendException,
ReadTimeoutException,
WriteException,
WriteDeniedException,
WriteIOException,
WriteTimeoutException,
)
Expand Down Expand Up @@ -369,7 +369,7 @@ async def write_coil(
result = self._futures["write"].result()

if not result:
raise WriteException(f"Heatpump denied writing {coil.name}")
raise WriteDeniedException(f"Heatpump denied writing {coil.name}")
else:
logger.info(f"Write succeeded for {coil.name}")
except asyncio.TimeoutError:
Expand Down
4 changes: 4 additions & 0 deletions nibe/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class WriteException(NibeException):
pass


class WriteDeniedException(WriteException):
"""Raised a write of a value was rejected by the pump."""


class WriteIOException(WriteException):
"""Use this and child exceptions if IO has failed and you want to retry."""

Expand Down

0 comments on commit 0d0df66

Please sign in to comment.