-
-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct range for nibe_heatpump numbers (#102553)
- Loading branch information
Showing
7 changed files
with
277 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
tests/components/nibe_heatpump/snapshots/test_number.ambr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# serializer version: 1 | ||
# name: test_update[Model.F1155-47011-number.heat_offset_s1_47011--10] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'F1155 Heat Offset S1', | ||
'max': 10.0, | ||
'min': -10.0, | ||
'mode': <NumberMode.AUTO: 'auto'>, | ||
'step': 1.0, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.heat_offset_s1_47011', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '-10.0', | ||
}) | ||
# --- | ||
# name: test_update[Model.F1155-47011-number.heat_offset_s1_47011-10] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'F1155 Heat Offset S1', | ||
'max': 10.0, | ||
'min': -10.0, | ||
'mode': <NumberMode.AUTO: 'auto'>, | ||
'step': 1.0, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.heat_offset_s1_47011', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '10.0', | ||
}) | ||
# --- | ||
# name: test_update[Model.F1155-47062-number.heat_offset_s1_47011-None] | ||
None | ||
# --- | ||
# name: test_update[Model.F750-47062-number.hw_charge_offset_47062--10] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'F750 HW charge offset', | ||
'max': 12.7, | ||
'min': -12.8, | ||
'mode': <NumberMode.AUTO: 'auto'>, | ||
'step': 0.1, | ||
'unit_of_measurement': '°C', | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.hw_charge_offset_47062', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '-10.0', | ||
}) | ||
# --- | ||
# name: test_update[Model.F750-47062-number.hw_charge_offset_47062-10] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'F750 HW charge offset', | ||
'max': 12.7, | ||
'min': -12.8, | ||
'mode': <NumberMode.AUTO: 'auto'>, | ||
'step': 0.1, | ||
'unit_of_measurement': '°C', | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.hw_charge_offset_47062', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '10.0', | ||
}) | ||
# --- | ||
# name: test_update[Model.F750-47062-number.hw_charge_offset_47062-None] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'F750 HW charge offset', | ||
'max': 12.7, | ||
'min': -12.8, | ||
'mode': <NumberMode.AUTO: 'auto'>, | ||
'step': 0.1, | ||
'unit_of_measurement': '°C', | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.hw_charge_offset_47062', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': 'unavailable', | ||
}) | ||
# --- | ||
# name: test_update[Model.S320-40031-number.heating_offset_climate_system_1_40031--10] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'S320 Heating offset climate system 1', | ||
'max': 10.0, | ||
'min': -10.0, | ||
'mode': <NumberMode.AUTO: 'auto'>, | ||
'step': 1.0, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.heating_offset_climate_system_1_40031', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '-10.0', | ||
}) | ||
# --- | ||
# name: test_update[Model.S320-40031-number.heating_offset_climate_system_1_40031-10] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'S320 Heating offset climate system 1', | ||
'max': 10.0, | ||
'min': -10.0, | ||
'mode': <NumberMode.AUTO: 'auto'>, | ||
'step': 1.0, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.heating_offset_climate_system_1_40031', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': '10.0', | ||
}) | ||
# --- | ||
# name: test_update[Model.S320-40031-number.heating_offset_climate_system_1_40031-None] | ||
StateSnapshot({ | ||
'attributes': ReadOnlyDict({ | ||
'friendly_name': 'S320 Heating offset climate system 1', | ||
'max': 10.0, | ||
'min': -10.0, | ||
'mode': <NumberMode.AUTO: 'auto'>, | ||
'step': 1.0, | ||
}), | ||
'context': <ANY>, | ||
'entity_id': 'number.heating_offset_climate_system_1_40031', | ||
'last_changed': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': 'unavailable', | ||
}) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
"""Test the Nibe Heat Pump config flow.""" | ||
from typing import Any | ||
from unittest.mock import AsyncMock, patch | ||
|
||
from nibe.coil import CoilData | ||
from nibe.heatpump import Model | ||
import pytest | ||
from syrupy import SnapshotAssertion | ||
|
||
from homeassistant.components.number import ( | ||
ATTR_VALUE, | ||
DOMAIN as PLATFORM_DOMAIN, | ||
SERVICE_SET_VALUE, | ||
) | ||
from homeassistant.const import ATTR_ENTITY_ID, Platform | ||
from homeassistant.core import HomeAssistant | ||
|
||
from . import async_add_model | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
async def fixture_single_platform(): | ||
"""Only allow this platform to load.""" | ||
with patch("homeassistant.components.nibe_heatpump.PLATFORMS", [Platform.NUMBER]): | ||
yield | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("model", "address", "entity_id", "value"), | ||
[ | ||
# Tests for S series coils with min/max | ||
(Model.S320, 40031, "number.heating_offset_climate_system_1_40031", 10), | ||
(Model.S320, 40031, "number.heating_offset_climate_system_1_40031", -10), | ||
(Model.S320, 40031, "number.heating_offset_climate_system_1_40031", None), | ||
# Tests for F series coils with min/max | ||
(Model.F1155, 47011, "number.heat_offset_s1_47011", 10), | ||
(Model.F1155, 47011, "number.heat_offset_s1_47011", -10), | ||
(Model.F1155, 47062, "number.heat_offset_s1_47011", None), | ||
# Tests for F series coils without min/max | ||
(Model.F750, 47062, "number.hw_charge_offset_47062", 10), | ||
(Model.F750, 47062, "number.hw_charge_offset_47062", -10), | ||
(Model.F750, 47062, "number.hw_charge_offset_47062", None), | ||
], | ||
) | ||
async def test_update( | ||
hass: HomeAssistant, | ||
model: Model, | ||
entity_id: str, | ||
address: int, | ||
value: Any, | ||
coils: dict[int, Any], | ||
entity_registry_enabled_by_default: None, | ||
snapshot: SnapshotAssertion, | ||
) -> None: | ||
"""Test setting of value.""" | ||
coils[address] = value | ||
|
||
await async_add_model(hass, model) | ||
|
||
await hass.async_block_till_done() | ||
state = hass.states.get(entity_id) | ||
assert state == snapshot | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("model", "address", "entity_id", "value"), | ||
[ | ||
(Model.S320, 40031, "number.heating_offset_climate_system_1_40031", 10), | ||
(Model.S320, 40031, "number.heating_offset_climate_system_1_40031", -10), | ||
(Model.F1155, 47011, "number.heat_offset_s1_47011", 10), | ||
(Model.F1155, 47011, "number.heat_offset_s1_47011", -10), | ||
(Model.F750, 47062, "number.hw_charge_offset_47062", 10), | ||
], | ||
) | ||
async def test_set_value( | ||
hass: HomeAssistant, | ||
mock_connection: AsyncMock, | ||
model: Model, | ||
entity_id: str, | ||
address: int, | ||
value: Any, | ||
coils: dict[int, Any], | ||
entity_registry_enabled_by_default: None, | ||
) -> None: | ||
"""Test setting of value.""" | ||
coils[address] = 0 | ||
|
||
await async_add_model(hass, model) | ||
|
||
await hass.async_block_till_done() | ||
assert hass.states.get(entity_id) | ||
|
||
# Write value | ||
await hass.services.async_call( | ||
PLATFORM_DOMAIN, | ||
SERVICE_SET_VALUE, | ||
{ATTR_ENTITY_ID: entity_id, ATTR_VALUE: value}, | ||
blocking=True, | ||
) | ||
|
||
await hass.async_block_till_done() | ||
|
||
# Verify written | ||
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 |