mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Handle when heat pump rejects same value writes in nibe_heatpump (#148366)
This commit is contained in:
parent
4b8dcc39b4
commit
19951d9403
@ -52,6 +52,7 @@ class NibeAlarmResetButton(CoordinatorEntity[CoilCoordinator], ButtonEntity):
|
|||||||
|
|
||||||
async def async_press(self) -> None:
|
async def async_press(self) -> None:
|
||||||
"""Execute the command."""
|
"""Execute the command."""
|
||||||
|
await self.coordinator.async_write_coil(self._reset_coil, 0)
|
||||||
await self.coordinator.async_write_coil(self._reset_coil, 1)
|
await self.coordinator.async_write_coil(self._reset_coil, 1)
|
||||||
await self.coordinator.async_read_coil(self._alarm_coil)
|
await self.coordinator.async_read_coil(self._alarm_coil)
|
||||||
|
|
||||||
|
@ -143,15 +143,12 @@ class CoilCoordinator(ContextCoordinator[dict[int, CoilData], int]):
|
|||||||
data = CoilData(coil, value)
|
data = CoilData(coil, value)
|
||||||
try:
|
try:
|
||||||
await self.connection.write_coil(data)
|
await self.connection.write_coil(data)
|
||||||
except WriteDeniedException as e:
|
except WriteDeniedException:
|
||||||
raise HomeAssistantError(
|
LOGGER.debug(
|
||||||
translation_domain=DOMAIN,
|
"Denied write on address %d with value %s. This is likely already the value the pump has internally",
|
||||||
translation_key="write_denied",
|
coil.address,
|
||||||
translation_placeholders={
|
value,
|
||||||
"address": str(coil.address),
|
)
|
||||||
"value": str(value),
|
|
||||||
},
|
|
||||||
) from e
|
|
||||||
except WriteTimeoutException as e:
|
except WriteTimeoutException as e:
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
|
@ -47,9 +47,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
"write_denied": {
|
|
||||||
"message": "Writing of coil {address} with value `{value}` was denied"
|
|
||||||
},
|
|
||||||
"write_timeout": {
|
"write_timeout": {
|
||||||
"message": "Timeout while writing coil {address}"
|
"message": "Timeout while writing coil {address}"
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,22 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
|
# name: test_set_value_same
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'F1155 Room sensor setpoint S1',
|
||||||
|
'max': 30.0,
|
||||||
|
'min': 5.0,
|
||||||
|
'mode': <NumberMode.AUTO: 'auto'>,
|
||||||
|
'step': 0.1,
|
||||||
|
'unit_of_measurement': '°C',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'number.room_sensor_setpoint_s1_47398',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '25.0',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_update[Model.F1155-47011-number.heat_offset_s1_47011--10]
|
# name: test_update[Model.F1155-47011-number.heat_offset_s1_47011--10]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
|
@ -115,11 +115,6 @@ async def test_set_value(
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("exception", "translation_key", "translation_placeholders"),
|
("exception", "translation_key", "translation_placeholders"),
|
||||||
[
|
[
|
||||||
(
|
|
||||||
WriteDeniedException("denied"),
|
|
||||||
"write_denied",
|
|
||||||
{"address": "47398", "value": "25.0"},
|
|
||||||
),
|
|
||||||
(
|
(
|
||||||
WriteTimeoutException("timeout writing"),
|
WriteTimeoutException("timeout writing"),
|
||||||
"write_timeout",
|
"write_timeout",
|
||||||
@ -171,3 +166,45 @@ async def test_set_value_fail(
|
|||||||
assert exc_info.value.translation_domain == "nibe_heatpump"
|
assert exc_info.value.translation_domain == "nibe_heatpump"
|
||||||
assert exc_info.value.translation_key == translation_key
|
assert exc_info.value.translation_key == translation_key
|
||||||
assert exc_info.value.translation_placeholders == translation_placeholders
|
assert exc_info.value.translation_placeholders == translation_placeholders
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
|
async def test_set_value_same(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_connection: AsyncMock,
|
||||||
|
coils: dict[int, Any],
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test setting a value, which the pump will reject."""
|
||||||
|
|
||||||
|
value = 25
|
||||||
|
model = Model.F1155
|
||||||
|
address = 47398
|
||||||
|
entity_id = "number.room_sensor_setpoint_s1_47398"
|
||||||
|
coils[address] = 0
|
||||||
|
|
||||||
|
await async_add_model(hass, model)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get(entity_id)
|
||||||
|
|
||||||
|
mock_connection.write_coil.side_effect = WriteDeniedException()
|
||||||
|
|
||||||
|
# Write value
|
||||||
|
await hass.services.async_call(
|
||||||
|
PLATFORM_DOMAIN,
|
||||||
|
SERVICE_SET_VALUE,
|
||||||
|
{ATTR_ENTITY_ID: entity_id, ATTR_VALUE: value},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify attempt was done
|
||||||
|
args = mock_connection.write_coil.call_args
|
||||||
|
assert args
|
||||||
|
coil = args.args[0]
|
||||||
|
assert isinstance(coil, CoilData)
|
||||||
|
assert coil.coil.address == address
|
||||||
|
assert coil.value == value
|
||||||
|
|
||||||
|
# State should have been set
|
||||||
|
assert hass.states.get(entity_id) == snapshot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user