Skip to content

Commit

Permalink
Removes poweer_entity_id from vtherm non central config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Jan 5, 2025
1 parent 8b58e69 commit a38b800
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 71 deletions.
22 changes: 7 additions & 15 deletions custom_components/versatile_thermostat/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ def _init_feature_flags(self, _):
CONF_USE_MOTION_FEATURE, False
) and (self._infos.get(CONF_MOTION_SENSOR) is not None or is_central_config)

self._infos[CONF_USE_POWER_FEATURE] = self._infos.get(
CONF_USE_POWER_CENTRAL_CONFIG, False
) or (
self._infos.get(CONF_POWER_SENSOR) is not None
and self._infos.get(CONF_MAX_POWER_SENSOR) is not None
self._infos[CONF_USE_POWER_FEATURE] = (
self._infos.get(CONF_USE_POWER_CENTRAL_CONFIG, False)
or self._infos.get(CONF_USE_POWER_FEATURE, False)
or (is_central_config and self._infos.get(CONF_POWER_SENSOR) is not None and self._infos.get(CONF_MAX_POWER_SENSOR) is not None)
)
self._infos[CONF_USE_PRESENCE_FEATURE] = (
self._infos.get(CONF_USE_PRESENCE_CENTRAL_CONFIG, False)
Expand Down Expand Up @@ -184,7 +183,7 @@ async def validate_input(self, data: dict, step_id) -> None:
Data has the keys from STEP_*_DATA_SCHEMA with values provided by the user.
"""

# check the heater_entity_id
# check the entity_ids
for conf in [
CONF_UNDERLYING_LIST,
CONF_TEMP_SENSOR,
Expand Down Expand Up @@ -330,14 +329,7 @@ def check_config_complete(self, infos) -> bool:
):
return False

if (
infos.get(CONF_USE_POWER_FEATURE, False) is True
and infos.get(CONF_USE_POWER_CENTRAL_CONFIG, False) is False
and (
infos.get(CONF_POWER_SENSOR, None) is None
or infos.get(CONF_MAX_POWER_SENSOR, None) is None
)
):
if infos.get(CONF_USE_POWER_FEATURE, False) is True and infos.get(CONF_USE_POWER_CENTRAL_CONFIG, False) is False and infos.get(CONF_PRESET_POWER, None) is None:
return False

if (
Expand Down Expand Up @@ -815,7 +807,7 @@ async def async_step_spec_power(self, user_input: dict | None = None) -> FlowRes
"""Handle the specific power flow steps"""
_LOGGER.debug("Into ConfigFlow.async_step_spec_power user_input=%s", user_input)

schema = STEP_CENTRAL_POWER_DATA_SCHEMA
schema = STEP_NON_CENTRAL_POWER_DATA_SCHEMA

self._infos[COMES_FROM] = "async_step_spec_power"

Expand Down
15 changes: 6 additions & 9 deletions tests/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
MOCK_TH_OVER_CLIMATE_TYPE_AC_CONFIG,
MOCK_TH_OVER_CLIMATE_TYPE_NOT_REGULATED_CONFIG,
MOCK_TH_OVER_SWITCH_TPI_CONFIG,
MOCK_PRESETS_CONFIG,
MOCK_PRESETS_AC_CONFIG,
MOCK_WINDOW_CONFIG,
MOCK_MOTION_CONFIG,
MOCK_POWER_CONFIG,
Expand Down Expand Up @@ -89,7 +87,7 @@
| MOCK_TH_OVER_SWITCH_CENTRAL_MAIN_CONFIG
| MOCK_TH_OVER_SWITCH_TYPE_CONFIG
| MOCK_TH_OVER_SWITCH_TPI_CONFIG
| MOCK_PRESETS_CONFIG
# | MOCK_PRESETS_CONFIG
| MOCK_FULL_FEATURES
| MOCK_WINDOW_CONFIG
| MOCK_MOTION_CONFIG
Expand All @@ -104,7 +102,6 @@
| MOCK_TH_OVER_SWITCH_CENTRAL_MAIN_CONFIG
| MOCK_TH_OVER_SWITCH_AC_TYPE_CONFIG
| MOCK_TH_OVER_SWITCH_TPI_CONFIG
| MOCK_PRESETS_AC_CONFIG
| MOCK_FULL_FEATURES
| MOCK_WINDOW_CONFIG
| MOCK_MOTION_CONFIG
Expand All @@ -118,7 +115,7 @@
| MOCK_TH_OVER_CLIMATE_MAIN_CONFIG
| MOCK_TH_OVER_CLIMATE_CENTRAL_MAIN_CONFIG
| MOCK_TH_OVER_CLIMATE_TYPE_CONFIG
| MOCK_PRESETS_CONFIG
# | MOCK_PRESETS_CONFIG
| MOCK_ADVANCED_CONFIG
)

Expand All @@ -127,7 +124,7 @@
| MOCK_TH_OVER_CLIMATE_MAIN_CONFIG
| MOCK_TH_OVER_CLIMATE_CENTRAL_MAIN_CONFIG
| MOCK_TH_OVER_CLIMATE_TYPE_USE_DEVICE_TEMP_CONFIG
| MOCK_PRESETS_CONFIG
# | MOCK_PRESETS_CONFIG
| MOCK_ADVANCED_CONFIG
)

Expand All @@ -136,7 +133,7 @@
| MOCK_TH_OVER_CLIMATE_MAIN_CONFIG
| MOCK_TH_OVER_CLIMATE_CENTRAL_MAIN_CONFIG
| MOCK_TH_OVER_CLIMATE_TYPE_NOT_REGULATED_CONFIG
| MOCK_PRESETS_CONFIG
# | MOCK_PRESETS_CONFIG
| MOCK_ADVANCED_CONFIG
)

Expand All @@ -145,15 +142,15 @@
| MOCK_TH_OVER_CLIMATE_TYPE_AC_CONFIG
| MOCK_TH_OVER_CLIMATE_MAIN_CONFIG
| MOCK_TH_OVER_CLIMATE_CENTRAL_MAIN_CONFIG
| MOCK_PRESETS_CONFIG
# | MOCK_PRESETS_CONFIG
| MOCK_ADVANCED_CONFIG
)

FULL_4SWITCH_CONFIG = (
MOCK_TH_OVER_4SWITCH_USER_CONFIG
| MOCK_TH_OVER_4SWITCH_TYPE_CONFIG
| MOCK_TH_OVER_SWITCH_TPI_CONFIG
| MOCK_PRESETS_CONFIG
# | MOCK_PRESETS_CONFIG
| MOCK_WINDOW_CONFIG
| MOCK_MOTION_CONFIG
| MOCK_POWER_CONFIG
Expand Down
25 changes: 5 additions & 20 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,6 @@
CONF_AUTO_REGULATION_PERIOD_MIN: 1,
}

# TODO remove this later
MOCK_PRESETS_CONFIG = {
PRESET_FROST_PROTECTION + PRESET_TEMP_SUFFIX: 7,
PRESET_ECO + PRESET_TEMP_SUFFIX: 16,
PRESET_COMFORT + PRESET_TEMP_SUFFIX: 17,
PRESET_BOOST + PRESET_TEMP_SUFFIX: 18,
}

# TODO remove this later
MOCK_PRESETS_AC_CONFIG = {
PRESET_FROST_PROTECTION + PRESET_TEMP_SUFFIX: 7,
PRESET_ECO + PRESET_TEMP_SUFFIX: 17,
PRESET_COMFORT + PRESET_TEMP_SUFFIX: 19,
PRESET_BOOST + PRESET_TEMP_SUFFIX: 20,
PRESET_ECO + PRESET_AC_SUFFIX + PRESET_TEMP_SUFFIX: 25,
PRESET_COMFORT + PRESET_AC_SUFFIX + PRESET_TEMP_SUFFIX: 23,
PRESET_BOOST + PRESET_AC_SUFFIX + PRESET_TEMP_SUFFIX: 21,
}

MOCK_WINDOW_CONFIG = {
CONF_WINDOW_SENSOR: "binary_sensor.window_sensor",
# Not used normally only for tests to avoid rewrite all tests
Expand All @@ -184,12 +165,16 @@
CONF_NO_MOTION_PRESET: PRESET_ECO,
}

MOCK_POWER_CONFIG = {
MOCK_CENTRAL_POWER_CONFIG = {
CONF_POWER_SENSOR: "sensor.power_sensor",
CONF_MAX_POWER_SENSOR: "sensor.power_max_sensor",
CONF_PRESET_POWER: 10,
}

MOCK_POWER_CONFIG = {
CONF_PRESET_POWER: 10,
}

MOCK_PRESENCE_CONFIG = {
CONF_PRESENCE_SENSOR: "person.presence_sensor",
}
Expand Down
4 changes: 1 addition & 3 deletions tests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,6 @@ async def test_bug_500_3(hass: HomeAssistant, init_vtherm_api) -> None:
CONF_USE_WINDOW_CENTRAL_CONFIG: False,
CONF_WINDOW_SENSOR: "sensor.theWindowSensor",
CONF_USE_POWER_CENTRAL_CONFIG: False,
CONF_POWER_SENSOR: "sensor.thePowerSensor",
CONF_MAX_POWER_SENSOR: "sensor.theMaxPowerSensor",
CONF_USE_PRESENCE_CENTRAL_CONFIG: False,
CONF_PRESENCE_SENSOR: "sensor.thePresenceSensor",
CONF_USE_MOTION_FEATURE: True, # motion sensor need to be checked AND a motion sensor set
Expand All @@ -492,7 +490,7 @@ async def test_bug_500_3(hass: HomeAssistant, init_vtherm_api) -> None:
flow = VersatileThermostatBaseConfigFlow(config)

assert flow._infos[CONF_USE_WINDOW_FEATURE] is True
assert flow._infos[CONF_USE_POWER_FEATURE] is True
assert flow._infos[CONF_USE_POWER_FEATURE] is False
assert flow._infos[CONF_USE_PRESENCE_FEATURE] is True
assert flow._infos[CONF_USE_MOTION_FEATURE] is True

Expand Down
27 changes: 24 additions & 3 deletions tests/test_overclimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ async def test_underlying_change_follow(
tz = get_tz(hass) # pylint: disable=invalid-name
now: datetime = datetime.now(tz=tz)

temps = {
PRESET_FROST_PROTECTION: 7,
PRESET_ECO: 16,
PRESET_COMFORT: 17,
PRESET_BOOST: 18,
}

entry = MockConfigEntry(
domain=DOMAIN,
title="TheOverClimateMockName",
Expand All @@ -232,7 +239,7 @@ async def test_underlying_change_follow(
) as mock_find_climate, patch(
"custom_components.versatile_thermostat.underlyings.UnderlyingClimate.set_hvac_mode"
) as mock_underlying_set_hvac_mode:
entity = await create_thermostat(hass, entry, "climate.theoverclimatemockname")
entity = await create_thermostat(hass, entry, "climate.theoverclimatemockname", temps)

assert entity
assert entity.name == "TheOverClimateMockName"
Expand Down Expand Up @@ -354,6 +361,13 @@ async def test_underlying_change_not_follow(
tz = get_tz(hass) # pylint: disable=invalid-name
now: datetime = datetime.now(tz=tz)

temps = {
PRESET_FROST_PROTECTION: 7,
PRESET_ECO: 16,
PRESET_COMFORT: 17,
PRESET_BOOST: 18,
}

entry = MockConfigEntry(
domain=DOMAIN,
title="TheOverClimateMockName",
Expand All @@ -374,7 +388,7 @@ async def test_underlying_change_not_follow(
) as mock_find_climate, patch(
"custom_components.versatile_thermostat.underlyings.UnderlyingClimate.set_hvac_mode"
) as mock_underlying_set_hvac_mode:
entity = await create_thermostat(hass, entry, "climate.theoverclimatemockname")
entity = await create_thermostat(hass, entry, "climate.theoverclimatemockname", temps)

assert entity

Expand Down Expand Up @@ -726,6 +740,13 @@ async def test_ignore_temp_outside_minmax_range(
tz = get_tz(hass) # pylint: disable=invalid-name
now: datetime = datetime.now(tz=tz)

temps = {
PRESET_FROST_PROTECTION: 7,
PRESET_ECO: 16,
PRESET_COMFORT: 17,
PRESET_BOOST: 18,
}

entry = MockConfigEntry(
domain=DOMAIN,
title="TheOverClimateMockName",
Expand All @@ -746,7 +767,7 @@ async def test_ignore_temp_outside_minmax_range(
) as mock_find_climate, patch(
"custom_components.versatile_thermostat.underlyings.UnderlyingClimate.set_hvac_mode"
) as mock_underlying_set_hvac_mode:
entity = await create_thermostat(hass, entry, "climate.theoverclimatemockname")
entity = await create_thermostat(hass, entry, "climate.theoverclimatemockname", temps)

assert entity

Expand Down
2 changes: 0 additions & 2 deletions tests/test_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,6 @@ async def test_power_management_energy_over_climate(
CONF_MINIMAL_ACTIVATION_DELAY: 30,
CONF_SAFETY_DELAY_MIN: 5,
CONF_SAFETY_MIN_ON_PERCENT: 0.3,
CONF_POWER_SENSOR: "sensor.mock_power_sensor",
CONF_MAX_POWER_SENSOR: "sensor.mock_power_max_sensor",
CONF_DEVICE_POWER: 100,
CONF_PRESET_POWER: 12,
},
Expand Down
2 changes: 0 additions & 2 deletions tests/test_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ async def test_sensors_over_climate(
CONF_MINIMAL_ACTIVATION_DELAY: 30,
CONF_SAFETY_DELAY_MIN: 5,
CONF_SAFETY_MIN_ON_PERCENT: 0.3,
CONF_POWER_SENSOR: "sensor.mock_power_sensor",
CONF_MAX_POWER_SENSOR: "sensor.mock_power_max_sensor",
CONF_DEVICE_POWER: 1.5,
CONF_PRESET_POWER: 12,
},
Expand Down
33 changes: 18 additions & 15 deletions tests/test_switch_ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ async def test_over_switch_ac_full_start(
): # pylint: disable=unused-argument
"""Test the normal full start of a thermostat in thermostat_over_switch type"""

temps = {
PRESET_FROST_PROTECTION: 7,
PRESET_ECO: 17,
PRESET_COMFORT: 19,
PRESET_BOOST: 20,
PRESET_ECO + PRESET_AC_SUFFIX: 25,
PRESET_COMFORT + PRESET_AC_SUFFIX: 23,
PRESET_BOOST + PRESET_AC_SUFFIX: 21,
PRESET_FROST_PROTECTION + PRESET_AWAY_SUFFIX: 7,
PRESET_ECO + PRESET_AWAY_SUFFIX: 16,
PRESET_COMFORT + PRESET_AWAY_SUFFIX: 17,
PRESET_BOOST + PRESET_AWAY_SUFFIX: 18,
PRESET_ECO + PRESET_AC_SUFFIX + PRESET_AWAY_SUFFIX: 27,
PRESET_COMFORT + PRESET_AC_SUFFIX + PRESET_AWAY_SUFFIX: 26,
PRESET_BOOST + PRESET_AC_SUFFIX + PRESET_AWAY_SUFFIX: 25,
}

entry = MockConfigEntry(
domain=DOMAIN,
title="TheOverSwitchACMockName",
Expand Down Expand Up @@ -57,21 +74,7 @@ def find_my_entity(entity_id) -> ClimateEntity:
assert isinstance(entity, ThermostatOverSwitch)

# Initialise the preset temp
await set_climate_preset_temp(
entity, PRESET_FROST_PROTECTION + PRESET_AWAY_SUFFIX, 7
)
await set_climate_preset_temp(entity, PRESET_ECO + PRESET_AWAY_SUFFIX, 16)
await set_climate_preset_temp(entity, PRESET_COMFORT + PRESET_AWAY_SUFFIX, 17)
await set_climate_preset_temp(entity, PRESET_BOOST + PRESET_AWAY_SUFFIX, 18)
await set_climate_preset_temp(
entity, PRESET_ECO + PRESET_AC_SUFFIX + PRESET_AWAY_SUFFIX, 27
)
await set_climate_preset_temp(
entity, PRESET_COMFORT + PRESET_AC_SUFFIX + PRESET_AWAY_SUFFIX, 26
)
await set_climate_preset_temp(
entity, PRESET_BOOST + PRESET_AC_SUFFIX + PRESET_AWAY_SUFFIX, 25
)
await set_all_climate_preset_temp(hass, entity, temps, "theoverswitchmockname")

assert entity.name == "TheOverSwitchMockName"
assert entity.is_over_climate is False # pylint: disable=protected-access
Expand Down
2 changes: 0 additions & 2 deletions tests/test_valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ async def test_over_valve_full_start(
CONF_MOTION_OFF_DELAY: 30,
CONF_MOTION_PRESET: PRESET_COMFORT,
CONF_NO_MOTION_PRESET: PRESET_ECO,
CONF_POWER_SENSOR: "sensor.power_sensor",
CONF_MAX_POWER_SENSOR: "sensor.power_max_sensor",
CONF_PRESENCE_SENSOR: "person.presence_sensor",
PRESET_FROST_PROTECTION + PRESET_AWAY_SUFFIX + PRESET_TEMP_SUFFIX: 7,
PRESET_ECO + PRESET_AWAY_SUFFIX + PRESET_TEMP_SUFFIX: 17.1,
Expand Down

0 comments on commit a38b800

Please sign in to comment.