diff --git a/custom_components/dual_smart_thermostat/climate.py b/custom_components/dual_smart_thermostat/climate.py index e1868eb..3b127f9 100644 --- a/custom_components/dual_smart_thermostat/climate.py +++ b/custom_components/dual_smart_thermostat/climate.py @@ -18,9 +18,7 @@ PRESET_HOME, PRESET_NONE, PRESET_SLEEP, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE, - SUPPORT_TARGET_TEMPERATURE_RANGE, + ClimateEntityFeature, ) from homeassistant.const import ( ATTR_ENTITY_ID, @@ -367,9 +365,9 @@ def __init__( self._min_floor_temp = min_floor_temp self._unit = unit self._unique_id = unique_id - self._support_flags = SUPPORT_TARGET_TEMPERATURE + self._support_flags = ClimateEntityFeature.TARGET_TEMPERATURE if len(presets): - self._support_flags |= SUPPORT_PRESET_MODE + self._support_flags |= ClimateEntityFeature.PRESET_MODE self._preset_modes = [PRESET_NONE] + list(presets.keys()) else: self._preset_modes = [PRESET_NONE] @@ -501,13 +499,13 @@ def _async_startup(*_): supp_feat = old_state.attributes.get(ATTR_SUPPORTED_FEATURES) hvac_mode = self._hvac_mode or old_state.state or HVACMode.OFF if ( - supp_feat & SUPPORT_TARGET_TEMPERATURE_RANGE + supp_feat & ClimateEntityFeature.TARGET_TEMPERATURE_RANGE and self._is_configured_for_heat_cool() and hvac_mode in (HVACMode.HEAT_COOL, HVACMode.OFF) ): - self._support_flags = SUPPORT_TARGET_TEMPERATURE_RANGE + self._support_flags = ClimateEntityFeature.TARGET_TEMPERATURE_RANGE if len(self._presets_range): - self._support_flags |= SUPPORT_PRESET_MODE + self._support_flags |= ClimateEntityFeature.PRESET_MODE self._set_default_target_temps() else: if hvac_mode not in self.hvac_modes: @@ -639,14 +637,14 @@ def hvac_modes(self): @property def preset_mode(self): """Return the current preset mode, e.g., home, away, temp.""" - if not self._support_flags & SUPPORT_PRESET_MODE: + if not self._support_flags & ClimateEntityFeature.PRESET_MODE: return None return self._preset_mode @property def preset_modes(self): """Return a list of available preset modes or PRESET_NONE.""" - if not self._support_flags & SUPPORT_PRESET_MODE: + if not self._support_flags & ClimateEntityFeature.PRESET_MODE: return None if self._is_range_mode(): return self._preset_range_modes @@ -1329,11 +1327,11 @@ def _is_configured_for_heat_cool(self) -> bool: def _is_target_mode(self): """Check if current support flag is for target temp mode.""" - return self._support_flags & SUPPORT_TARGET_TEMPERATURE + return self._support_flags & ClimateEntityFeature.TARGET_TEMPERATURE def _is_range_mode(self): """Check if current support flag is for range temp mode.""" - return self._support_flags & SUPPORT_TARGET_TEMPERATURE_RANGE + return self._support_flags & ClimateEntityFeature.TARGET_TEMPERATURE_RANGE def _set_default_target_temps(self): """Set default values for target temperatures.""" @@ -1401,16 +1399,16 @@ def _set_support_flags(self) -> None: self._preset_mode = PRESET_NONE self._target_temp_low = self._saved_target_temp_low self._target_temp_high = self._saved_target_temp_high - self._support_flags = SUPPORT_TARGET_TEMPERATURE + self._support_flags = ClimateEntityFeature.TARGET_TEMPERATURE if len(self._presets): - self._support_flags |= SUPPORT_PRESET_MODE + self._support_flags |= ClimateEntityFeature.PRESET_MODE else: if self._is_target_mode() and self._preset_mode != PRESET_NONE: self._preset_mode = PRESET_NONE self._target_temp = self._saved_target_temp - self._support_flags = SUPPORT_TARGET_TEMPERATURE_RANGE + self._support_flags = ClimateEntityFeature.TARGET_TEMPERATURE_RANGE if len(self._presets_range): - self._support_flags |= SUPPORT_PRESET_MODE + self._support_flags |= ClimateEntityFeature.PRESET_MODE self._set_default_target_temps() def _ran_long_enough(self, cooler_entity=False): diff --git a/custom_components/dual_smart_thermostat/services.yaml b/custom_components/dual_smart_thermostat/services.yaml index 7e1e4aa..7d512dc 100644 --- a/custom_components/dual_smart_thermostat/services.yaml +++ b/custom_components/dual_smart_thermostat/services.yaml @@ -1,3 +1,3 @@ reload: name: Reload Dual Smart Thermostat - description: Reload all dual_smart_thermostat entities. + description: Reload all Dual Smart Thermostat entities. diff --git a/requirements-test.txt b/requirements-test.txt index 45e51c4..8e0c362 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,7 +1,6 @@ # Strictly for tests -pytest -#pytest-cov==2.9.0 -#pytest-homeassistant -pytest-homeassistant-custom-component==0.8.7 -# From our manifest.json for our custom component -# gidgethub[aiohttp]==4.1.1 +coverage==7.2.1 +pytest==7.2.2 +pytest-asyncio==0.20.3 +pytest-cov==3.0.0 +pytest-homeassistant-custom-component==0.13.20 diff --git a/tests/test_thermostat.py b/tests/test_thermostat.py index f5cbf2d..d61ecec 100644 --- a/tests/test_thermostat.py +++ b/tests/test_thermostat.py @@ -95,7 +95,9 @@ async def setup_comp_1(hass): await hass.async_block_till_done() +@pytest.mark.asyncio async def test_heater_mode(hass, setup_comp_1): + await setup_comp_1 """Test thermostat heater switch in heating mode.""" heater_switch = "input_boolean.test" assert await async_setup_component( @@ -141,7 +143,9 @@ async def test_heater_mode(hass, setup_comp_1): assert hass.states.get(heater_switch).state == STATE_OFF +@pytest.mark.asyncio async def test_heater_mode_secondary_heater(hass, setup_comp_1): + await setup_comp_1 """Test thermostat secondary heater switch in heating mode.""" secondaty_heater_timeout = 10 @@ -220,7 +224,9 @@ async def test_heater_mode_secondary_heater(hass, setup_comp_1): assert hass.states.get(secondary_heater_switch).state == STATE_ON +@pytest.mark.asyncio async def test_heater_mode_tolerance(hass, setup_comp_1): + await setup_comp_1 """Test thermostat heater switch in heating mode.""" heater_switch = "input_boolean.test" assert await async_setup_component( @@ -281,7 +287,9 @@ async def test_heater_mode_tolerance(hass, setup_comp_1): assert hass.states.get(heater_switch).state == STATE_OFF +@pytest.mark.asyncio async def test_heater_mode_floor_temp(hass, setup_comp_1): + await setup_comp_1 """Test thermostat heater switch with floor temp in heating mode.""" heater_switch = "input_boolean.test" assert await async_setup_component( @@ -381,7 +389,9 @@ async def test_heater_mode_floor_temp(hass, setup_comp_1): (timedelta(seconds=30), STATE_OFF), ], ) +@pytest.mark.asyncio async def test_heater_mode_cycle(hass, duration, result_state, setup_comp_1): + await setup_comp_1 """Test thermostat heater switch in heating mode with min_cycle_duration.""" heater_switch = "input_boolean.test" assert await async_setup_component( @@ -432,7 +442,9 @@ async def test_heater_mode_cycle(hass, duration, result_state, setup_comp_1): assert hass.states.get(heater_switch).state == result_state +@pytest.mark.asyncio async def test_cooler_mode(hass, setup_comp_1): + await setup_comp_1 """Test thermostat cooler switch in cooling mode.""" cooler_switch = "input_boolean.test" assert await async_setup_component( @@ -479,7 +491,9 @@ async def test_cooler_mode(hass, setup_comp_1): assert hass.states.get(cooler_switch).state == STATE_OFF +@pytest.mark.asyncio async def test_mode_change(hass, setup_comp_1): + await setup_comp_1 """Test thermostat switch state iif HVAc mode changes.""" cooler_switch = "input_boolean.test" assert await async_setup_component( @@ -526,7 +540,9 @@ async def test_mode_change(hass, setup_comp_1): assert hass.states.get(cooler_switch).state == STATE_OFF +@pytest.mark.asyncio async def test_cooler_mode_tolerance(hass, setup_comp_1): + await setup_comp_1 """Test thermostat cooler switch in cooling mode.""" cooler_switch = "input_boolean.test" assert await async_setup_component( @@ -590,7 +606,9 @@ async def test_cooler_mode_tolerance(hass, setup_comp_1): (timedelta(seconds=30), STATE_OFF), ], ) +@pytest.mark.asyncio async def test_cooler_mode_cycle(hass, duration, result_state, setup_comp_1): + await setup_comp_1 """Test thermostat cooler switch in cooling mode with cycle duration.""" cooler_switch = "input_boolean.test" assert await async_setup_component( @@ -642,7 +660,9 @@ async def test_cooler_mode_cycle(hass, duration, result_state, setup_comp_1): assert hass.states.get(cooler_switch).state == result_state +@pytest.mark.asyncio async def test_cooler_mode_dual(hass, setup_comp_1): + await setup_comp_1 """Test thermostat cooler switch in cooling mode.""" heater_switch = "input_boolean.heater" cooler_switch = "input_boolean.cooler" @@ -702,7 +722,9 @@ async def test_cooler_mode_dual(hass, setup_comp_1): (timedelta(seconds=30), STATE_OFF), ], ) +@pytest.mark.asyncio async def test_cooler_mode_dual_cycle(hass, duration, result_state, setup_comp_1): + await setup_comp_1 """Test thermostat cooler switch in cooling mode with cycle duration.""" heater_switch = "input_boolean.heater" cooler_switch = "input_boolean.cooler" @@ -760,7 +782,9 @@ async def test_cooler_mode_dual_cycle(hass, duration, result_state, setup_comp_1 assert hass.states.get(cooler_switch).state == result_state +@pytest.mark.asyncio async def test_cooler_mode_opening(hass, setup_comp_1): + await setup_comp_1 """Test thermostat cooler switch in cooling mode.""" cooler_switch = "input_boolean.test" opening_1 = "input_boolean.opening_1" @@ -839,7 +863,9 @@ async def test_cooler_mode_opening(hass, setup_comp_1): assert hass.states.get(cooler_switch).state == STATE_ON +@pytest.mark.asyncio async def test_heater_cooler_mode(hass, setup_comp_1): + await setup_comp_1 """Test thermostat heater and cooler switch in heat/cool mode.""" heater_switch = "input_boolean.heater" @@ -933,7 +959,9 @@ async def test_heater_cooler_mode(hass, setup_comp_1): assert hass.states.get(heater_switch).state == STATE_OFF +@pytest.mark.asyncio async def test_heater_cooler_mode_floor_temp(hass, setup_comp_1): + await setup_comp_1 """Test thermostat heater and cooler switch in heat/cool mode. with floor temp caps""" heater_switch = "input_boolean.heater" @@ -1042,11 +1070,12 @@ async def test_heater_cooler_mode_floor_temp(hass, setup_comp_1): (timedelta(seconds=30), STATE_OFF), ], ) +@pytest.mark.asyncio async def test_heater_cooler_mode_cycle_heat( hass, duration, result_state, setup_comp_1 ): """Test thermostat heater and cooler switch in heat mode with min_cycle_duration.""" - + await setup_comp_1 heater_switch = "input_boolean.heater" cooler_switch = "input_boolean.cooler" fake_changed = dt.utcnow() - duration @@ -1115,11 +1144,13 @@ async def test_heater_cooler_mode_cycle_heat( (timedelta(seconds=30), STATE_OFF), ], ) +@pytest.mark.asyncio async def test_heater_cooler_mode_cycle_cool( hass, duration, result_state, setup_comp_1 ): """Test thermostat heater and cooler switch in cool mode with min_cycle_duration.""" + await setup_comp_1 heater_switch = "input_boolean.heater" cooler_switch = "input_boolean.cooler" fake_changed = dt.utcnow() - duration @@ -1181,9 +1212,11 @@ async def test_heater_cooler_mode_cycle_cool( assert hass.states.get(cooler_switch).state == result_state +@pytest.mark.asyncio async def test_heater_cooler_switch_hvac_modes(hass, setup_comp_1): """Test thermostat heater and cooler switch to heater only mode.""" + await setup_comp_1 heater_switch = "input_boolean.heater" cooler_switch = "input_boolean.cooler" assert await async_setup_component( @@ -1232,9 +1265,11 @@ async def test_heater_cooler_switch_hvac_modes(hass, setup_comp_1): assert hass.states.get("climate.test").state == HVAC_MODE_COOL +@pytest.mark.asyncio async def test_heater_cooler_mode_tolerances(hass, setup_comp_1): """Test thermostat heater and cooler mode tolerances.""" + await setup_comp_1 heater_switch = "input_boolean.heater" cooler_switch = "input_boolean.cooler" assert await async_setup_component(