Skip to content

Commit 2a2e55a

Browse files
authoredSep 29, 2023
Refactor HVAC
Total overhaul of the HVAC controlling engine Allow setting of `hvac_mode` when calling service `climate.set_temperature` on HVAC group Minor branding corrections
2 parents 4cac53a + 1c6334d commit 2a2e55a

File tree

5 files changed

+600
-225
lines changed

5 files changed

+600
-225
lines changed
 

‎config/configuration.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ default_config:
55
logger:
66
default: info
77
logs:
8-
custom_components.integration_blueprint: debug
8+
custom_components.hvac_group: debug

‎custom_components/hvac_group/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Custom integration to integrate integration_blueprint with Home Assistant.
1+
"""Custom helper integration for Home Assistant that groups thermostats.
22
33
For more details about this integration, please refer to
44
https://github.com/tetele/hvac_group

‎custom_components/hvac_group/climate.py

+569-181
Large diffs are not rendered by default.

‎scripts/develop

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if [[ ! -d "${PWD}/config" ]]; then
1111
fi
1212

1313
# Set the path to custom_components
14-
## This let's us have the structure we want <root>/custom_components/integration_blueprint
14+
## This let's us have the structure we want <root>/custom_components/hvac_group
1515
## while at the same time have Home Assistant configuration inside <root>/config
1616
## without resulting to symlinks.
1717
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"

‎tests/test_climate.py

+28-41
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import copy
55

66
import pytest
7-
from homeassistant.components.climate import ClimateEntityFeature, HVACAction, HVACMode
7+
from homeassistant.components.climate import ClimateEntityFeature, HVACMode
88
from homeassistant.const import PRECISION_HALVES, PRECISION_TENTHS
99
from homeassistant.core import HomeAssistant, State
1010
from homeassistant.exceptions import NoEntitySpecifiedError
@@ -16,6 +16,9 @@
1616
from custom_components.hvac_group import DOMAIN
1717
from custom_components.hvac_group.climate import (
1818
HvacGroupClimateEntity,
19+
HvacGroupActuator,
20+
HvacGroupCooler,
21+
HvacGroupHeater,
1922
async_setup_entry,
2023
)
2124

@@ -135,7 +138,7 @@ async def hvac_group(hass: HomeAssistant) -> HvacGroupClimateEntity:
135138

136139
mock_async_add_entities.assert_called()
137140

138-
hvac_entity: HvacGroupClimateEntity = mock_async_add_entities.call_args[0][0][0]
141+
hvac_entity: HvacGroupClimateEntity = mock_async_add_entities.call_args.args[0][0]
139142

140143
return hvac_entity
141144

@@ -144,7 +147,7 @@ async def hvac_group(hass: HomeAssistant) -> HvacGroupClimateEntity:
144147
async def test_entry(hvac_group: HvacGroupClimateEntity, hass: HomeAssistant) -> None:
145148
"""Test component creation."""
146149

147-
assert hvac_group.temperature_sensor_entity_id == "climate.heater"
150+
assert hvac_group._temperature_sensor_entity_id == "climate.heater"
148151

149152
assert hvac_group.precision == PRECISION_TENTHS
150153
assert hvac_group.target_temperature_step == PRECISION_HALVES
@@ -154,47 +157,31 @@ async def test_entry(hvac_group: HvacGroupClimateEntity, hass: HomeAssistant) ->
154157
assert HVACMode.HEAT not in hvac_group.hvac_modes
155158
assert HVACMode.COOL not in hvac_group.hvac_modes
156159

157-
assert hvac_group.hvac_mode == HVACMode.OFF
158-
assert hvac_group.hvac_action == HVACAction.OFF
159160

160-
161-
@pytest.mark.asyncio
162-
async def test_sensor_changes(
163-
hvac_group: HvacGroupClimateEntity, hass: HomeAssistant
164-
) -> None:
165-
"""Test behavior after temperature sensor change."""
166-
167-
with patch("homeassistant.core.ServiceRegistry.async_call") as hass_service_call:
168-
try:
169-
await hvac_group._async_sensor_changed(
170-
_generate_event(
171-
hass, "climate.heater", attributes={"current_temperature": 21.3}
172-
)
173-
)
174-
except NoEntitySpecifiedError:
175-
assert hvac_group.current_temperature == 21.3
176-
assert hass_service_call.called
177-
else:
178-
pass
179-
180-
181-
@pytest.mark.asyncio
182-
async def test_member_changes(
183-
initialize_actuators, hvac_group: HvacGroupClimateEntity, hass: HomeAssistant
161+
@pytest.mark.parametrize(
162+
("temperature", "temp_low", "temp_high", "actuator_class", "expected"),
163+
[
164+
(21, None, None, HvacGroupCooler, 21),
165+
(None, 19, 26, HvacGroupCooler, 26),
166+
(21, None, None, HvacGroupHeater, 21),
167+
(None, 19, 26, HvacGroupHeater, 19),
168+
(21, None, None, HvacGroupActuator, 21),
169+
(None, 12, 16, HvacGroupActuator, None),
170+
],
171+
)
172+
def test_guess_temperature(
173+
hass: HomeAssistant, temperature, temp_high, temp_low, actuator_class, expected
184174
) -> None:
185-
"""Test behavior after member min/max temperatures change."""
186-
187-
try:
188-
await hvac_group._async_member_changed(
189-
_generate_event(
190-
hass, "climate.hvac", attributes={"min_temp": 15, "max_temp": 32}
191-
)
175+
"""Test temperature guessing."""
176+
actuator = actuator_class(hass, "test.id")
177+
assert (
178+
actuator._guess_target_temperature(
179+
temperature=temperature,
180+
target_temp_low=temp_low,
181+
target_temp_high=temp_high,
192182
)
193-
except NoEntitySpecifiedError:
194-
assert hvac_group.min_temp == 16
195-
assert hvac_group.max_temp == 28
196-
else:
197-
pass
183+
== expected
184+
)
198185

199186

200187
@pytest.mark.asyncio

0 commit comments

Comments
 (0)
Please sign in to comment.