Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate write denied exception and consider that still a valid connection #171

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@
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)

Check warning on line 103 in nibe/connection/__init__.py

View check run for this annotation

Codecov / codecov/patch

nibe/connection/__init__.py#L102-L103

Added lines #L102 - L103 were not covered by tests
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 @@
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}")

Check warning on line 157 in nibe/connection/modbus.py

View check run for this annotation

Codecov / codecov/patch

nibe/connection/modbus.py#L157

Added line #L157 was not covered by tests
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