Skip to content

Commit

Permalink
Fix sensibo test coverage to 100% (home-assistant#132202)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST authored Dec 4, 2024
1 parent f0c07d6 commit 5a1d580
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 3 additions & 8 deletions homeassistant/components/sensibo/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.unit_conversion import TemperatureConverter
Expand Down Expand Up @@ -108,7 +108,7 @@
}


def _find_valid_target_temp(target: int, valid_targets: list[int]) -> int:
def _find_valid_target_temp(target: float, valid_targets: list[int]) -> int:
if target <= valid_targets[0]:
return valid_targets[0]
if target >= valid_targets[-1]:
Expand Down Expand Up @@ -320,12 +320,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
translation_key="no_target_temperature_in_features",
)

if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="no_target_temperature",
)

temperature: float = kwargs[ATTR_TEMPERATURE]
if temperature == self.target_temperature:
return

Expand Down
3 changes: 0 additions & 3 deletions homeassistant/components/sensibo/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,6 @@
"no_target_temperature_in_features": {
"message": "Current mode doesn't support setting target temperature"
},
"no_target_temperature": {
"message": "No target temperature provided"
},
"no_fan_level_in_features": {
"message": "Current mode doesn't support setting fan level"
},
Expand Down
11 changes: 11 additions & 0 deletions tests/components/sensibo/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ async def test_climate_temperatures(
state2 = hass.states.get("climate.hallway")
assert state2.attributes["temperature"] == 20

with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_set_ac_state_property",
) as mock_call:
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: state1.entity_id, ATTR_TEMPERATURE: 20},
blocking=True,
)
assert not mock_call.called

with (
patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
Expand Down

0 comments on commit 5a1d580

Please sign in to comment.