Skip to content

Commit

Permalink
fix: uses new enums instead of depricated ones
Browse files Browse the repository at this point in the history
closes: #90
  • Loading branch information
= authored and swingerman committed Jan 24, 2024
1 parent 15444bc commit b2ef5f4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
30 changes: 14 additions & 16 deletions custom_components/dual_smart_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/dual_smart_thermostat/services.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
reload:
name: Reload Dual Smart Thermostat
description: Reload all dual_smart_thermostat entities.
description: Reload all Dual Smart Thermostat entities.
11 changes: 5 additions & 6 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -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
37 changes: 36 additions & 1 deletion tests/test_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b2ef5f4

Please sign in to comment.