Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f970c18eaf | |||
| af51ef62e0 | |||
| b38fbd9d78 | |||
| 6e8e72e343 | |||
| 2bebe3e210 | |||
| aa3b87762d | |||
| f4cabbf2c0 | |||
| 24b59e545b |
@@ -141,9 +141,9 @@ template:
|
|||||||
device_class: energy
|
device_class: energy
|
||||||
state_class: total_increasing
|
state_class: total_increasing
|
||||||
state: >
|
state: >
|
||||||
{% set energy = state_attr('climate.thermostat_switch_1', 'total_energy') %}
|
{% set energy = state_attr('climate.thermostat_switch_1', 'total_energy') | float(default=-1) %}
|
||||||
{% if energy == 'unavailable' or energy is none%}unavailable{% else %}
|
{% if energy < 0 %}{{none}}{% else %}
|
||||||
{{ ((energy | float) / 1.0) | round(2, default=0) }}
|
{{ energy | round(2, default=0) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- name: "Total énergie climate 2"
|
- name: "Total énergie climate 2"
|
||||||
unique_id: total_energie_climate2
|
unique_id: total_energie_climate2
|
||||||
@@ -151,9 +151,9 @@ template:
|
|||||||
device_class: energy
|
device_class: energy
|
||||||
state_class: total_increasing
|
state_class: total_increasing
|
||||||
state: >
|
state: >
|
||||||
{% set energy = state_attr('climate.thermostat_climate_2', 'total_energy') %}
|
{% set energy = state_attr('climate.thermostat_climate_2', 'total_energy') | float(default=-1) %}
|
||||||
{% if energy == 'unavailable' or energy is none%}unavailable{% else %}
|
{% if energy < 0 %}{{none}}{% else %}
|
||||||
{{ ((energy | float) / 1.0) | round(2, default=0) }}
|
{{ energy | round(2, default=0) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- name: "Total énergie chambre"
|
- name: "Total énergie chambre"
|
||||||
unique_id: total_energie_chambre
|
unique_id: total_energie_chambre
|
||||||
@@ -161,9 +161,9 @@ template:
|
|||||||
device_class: energy
|
device_class: energy
|
||||||
state_class: total_increasing
|
state_class: total_increasing
|
||||||
state: >
|
state: >
|
||||||
{% set energy = state_attr('climate.thermostat_chambre', 'total_energy') %}
|
{% set energy = state_attr('climate.thermostat_chambre', 'total_energy') | float(default=-1) %}
|
||||||
{% if energy == 'unavailable' or energy is none%}unavailable{% else %}
|
{% if energy < 0 %}{{none}}{% else %}
|
||||||
{{ ((energy | float) / 1.0) | round(2, default=0) }}
|
{{ energy | round(2, default=0) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
switch:
|
switch:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from homeassistant.core import (
|
|||||||
from homeassistant.components.climate import ClimateEntity
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.helpers.entity import DeviceInfo, DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceInfo, DeviceEntryType
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.reload import async_setup_reload_service
|
from homeassistant.helpers.reload import async_setup_reload_service
|
||||||
@@ -505,7 +505,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
if len(presets):
|
if len(presets):
|
||||||
self._support_flags = SUPPORT_FLAGS | ClimateEntityFeature.PRESET_MODE
|
self._support_flags = SUPPORT_FLAGS | ClimateEntityFeature.PRESET_MODE
|
||||||
|
|
||||||
for key, val in CONF_PRESETS.items(): # TODO before presets.items():
|
for key, val in CONF_PRESETS.items():
|
||||||
if val != 0.0:
|
if val != 0.0:
|
||||||
self._attr_preset_modes.append(key)
|
self._attr_preset_modes.append(key)
|
||||||
|
|
||||||
@@ -1582,6 +1582,8 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
if not new_state:
|
if not new_state:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
new_hvac_mode = new_state.state
|
||||||
|
|
||||||
old_state = event.data.get("old_state")
|
old_state = event.data.get("old_state")
|
||||||
old_hvac_action = (
|
old_hvac_action = (
|
||||||
old_state.attributes.get("hvac_action")
|
old_state.attributes.get("hvac_action")
|
||||||
@@ -1594,16 +1596,21 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Issue 99 - some AC turn hvac_mode=cool and hvac_action=idle when sending a HVACMode_OFF command
|
||||||
|
if self._hvac_mode == HVACMode.OFF and new_hvac_action == HVACAction.IDLE:
|
||||||
|
_LOGGER.debug("The underlying switch to idle instead of OFF. We will consider it as OFF")
|
||||||
|
new_hvac_mode = HVACMode.OFF
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"%s - Underlying climate changed. Event.new_state is %s, current_hvac_mode=%s, new_hvac_action=%s, old_hvac_action=%s",
|
"%s - Underlying climate changed. Event.new_hvac_mode is %s, current_hvac_mode=%s, new_hvac_action=%s, old_hvac_action=%s",
|
||||||
self,
|
self,
|
||||||
new_state,
|
new_hvac_mode,
|
||||||
self._hvac_mode,
|
self._hvac_mode,
|
||||||
new_hvac_action,
|
new_hvac_action,
|
||||||
old_hvac_action,
|
old_hvac_action,
|
||||||
)
|
)
|
||||||
|
|
||||||
if new_state.state in [
|
if new_hvac_mode in [
|
||||||
HVACMode.OFF,
|
HVACMode.OFF,
|
||||||
HVACMode.HEAT,
|
HVACMode.HEAT,
|
||||||
HVACMode.COOL,
|
HVACMode.COOL,
|
||||||
@@ -1611,8 +1618,9 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
HVACMode.DRY,
|
HVACMode.DRY,
|
||||||
HVACMode.AUTO,
|
HVACMode.AUTO,
|
||||||
HVACMode.FAN_ONLY,
|
HVACMode.FAN_ONLY,
|
||||||
|
None
|
||||||
]:
|
]:
|
||||||
self._hvac_mode = new_state.state
|
self._hvac_mode = new_hvac_mode
|
||||||
|
|
||||||
# Interpretation of hvac
|
# Interpretation of hvac
|
||||||
HVAC_ACTION_ON = [ # pylint: disable=invalid-name
|
HVAC_ACTION_ON = [ # pylint: disable=invalid-name
|
||||||
@@ -2098,9 +2106,18 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
switch_cond,
|
switch_cond,
|
||||||
)
|
)
|
||||||
|
|
||||||
ret = False
|
# Issue 99 - a climate is regulated by the device itself and not by VTherm. So a VTherm should never be in security !
|
||||||
if mode_cond and temp_cond and climate_cond:
|
shouldClimateBeInSecurity = False # temp_cond and climate_cond
|
||||||
if not self._security_state:
|
shouldSwitchBeInSecurity = temp_cond and switch_cond
|
||||||
|
shouldBeInSecurity = shouldClimateBeInSecurity or shouldSwitchBeInSecurity
|
||||||
|
|
||||||
|
shouldStartSecurity = mode_cond and not self._security_state and shouldBeInSecurity
|
||||||
|
# attr_preset_mode is not necessary normaly. It is just here to be sure
|
||||||
|
shouldStopSecurity = self._security_state and not shouldBeInSecurity and self._attr_preset_mode == PRESET_SECURITY
|
||||||
|
|
||||||
|
# Logging and event
|
||||||
|
if shouldStartSecurity:
|
||||||
|
if shouldClimateBeInSecurity:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"%s - No temperature received for more than %.1f minutes (dt=%.1f, dext=%.1f) and underlying climate is %s. Set it into security mode",
|
"%s - No temperature received for more than %.1f minutes (dt=%.1f, dext=%.1f) and underlying climate is %s. Set it into security mode",
|
||||||
self,
|
self,
|
||||||
@@ -2109,10 +2126,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
delta_ext_temp,
|
delta_ext_temp,
|
||||||
self.hvac_action,
|
self.hvac_action,
|
||||||
)
|
)
|
||||||
ret = True
|
elif shouldSwitchBeInSecurity:
|
||||||
|
|
||||||
if mode_cond and temp_cond and switch_cond:
|
|
||||||
if not self._security_state:
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"%s - No temperature received for more than %.1f minutes (dt=%.1f, dext=%.1f) and on_percent (%.2f) is over defined value (%.2f). Set it into security mode",
|
"%s - No temperature received for more than %.1f minutes (dt=%.1f, dext=%.1f) and on_percent (%.2f) is over defined value (%.2f). Set it into security mode",
|
||||||
self,
|
self,
|
||||||
@@ -2122,9 +2136,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
self._prop_algorithm.on_percent,
|
self._prop_algorithm.on_percent,
|
||||||
self._security_min_on_percent,
|
self._security_min_on_percent,
|
||||||
)
|
)
|
||||||
ret = True
|
|
||||||
|
|
||||||
if mode_cond and temp_cond and not self._security_state:
|
|
||||||
self.send_event(
|
self.send_event(
|
||||||
EventType.TEMPERATURE_EVENT,
|
EventType.TEMPERATURE_EVENT,
|
||||||
{
|
{
|
||||||
@@ -2140,8 +2152,8 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if not self._security_state and ret:
|
if shouldStartSecurity:
|
||||||
self._security_state = ret
|
self._security_state = True
|
||||||
self.save_hvac_mode()
|
self.save_hvac_mode()
|
||||||
self.save_preset_mode()
|
self.save_preset_mode()
|
||||||
await self._async_set_preset_mode_internal(PRESET_SECURITY)
|
await self._async_set_preset_mode_internal(PRESET_SECURITY)
|
||||||
@@ -2167,18 +2179,14 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if shouldStopSecurity:
|
||||||
self._security_state
|
|
||||||
and self._attr_preset_mode == PRESET_SECURITY
|
|
||||||
and not ret
|
|
||||||
):
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"%s - End of security mode. restoring hvac_mode to %s and preset_mode to %s",
|
"%s - End of security mode. restoring hvac_mode to %s and preset_mode to %s",
|
||||||
self,
|
self,
|
||||||
self._saved_hvac_mode,
|
self._saved_hvac_mode,
|
||||||
self._saved_preset_mode,
|
self._saved_preset_mode,
|
||||||
)
|
)
|
||||||
self._security_state = ret
|
self._security_state = False
|
||||||
# Restore hvac_mode if previously saved
|
# Restore hvac_mode if previously saved
|
||||||
if self._is_over_climate or self._security_default_on_percent <= 0.0:
|
if self._is_over_climate or self._security_default_on_percent <= 0.0:
|
||||||
await self.restore_hvac_mode(False)
|
await self.restore_hvac_mode(False)
|
||||||
@@ -2201,7 +2209,7 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return ret
|
return shouldBeInSecurity
|
||||||
|
|
||||||
async def _async_control_heating(self, force=False, _=None):
|
async def _async_control_heating(self, force=False, _=None):
|
||||||
"""The main function used to run the calculation at each cycle"""
|
"""The main function used to run the calculation at each cycle"""
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ from datetime import timedelta
|
|||||||
from homeassistant.core import HomeAssistant, callback, Event
|
from homeassistant.core import HomeAssistant, callback, Event
|
||||||
from homeassistant.components.climate import ClimateEntity, DOMAIN as CLIMATE_DOMAIN
|
from homeassistant.components.climate import ClimateEntity, DOMAIN as CLIMATE_DOMAIN
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import Entity, DeviceInfo, DeviceEntryType
|
from homeassistant.helpers.entity import Entity
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo, DeviceEntryType
|
||||||
from homeassistant.helpers.event import async_track_state_change_event, async_call_later
|
from homeassistant.helpers.event import async_track_state_change_event, async_call_later
|
||||||
|
|
||||||
from .climate import VersatileThermostat
|
from .climate import VersatileThermostat
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
homeassistant
|
homeassistant==2023.9.0
|
||||||
ffmpeg
|
ffmpeg
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# -r requirements_dev.txt
|
-r requirements_dev.txt
|
||||||
# aiodiscover
|
# aiodiscover
|
||||||
ulid_transform
|
ulid_transform
|
||||||
pytest-homeassistant-custom-component
|
pytest-homeassistant-custom-component
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
reload:
|
reload:
|
||||||
|
name: Reload
|
||||||
description: Reload all Versatile Thermostat entities.
|
description: Reload all Versatile Thermostat entities.
|
||||||
|
|
||||||
set_presence:
|
set_presence:
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from custom_components.versatile_thermostat.const import (
|
|||||||
CONF_THERMOSTAT_CLIMATE,
|
CONF_THERMOSTAT_CLIMATE,
|
||||||
CONF_THERMOSTAT_SWITCH,
|
CONF_THERMOSTAT_SWITCH,
|
||||||
CONF_THERMOSTAT_TYPE,
|
CONF_THERMOSTAT_TYPE,
|
||||||
|
CONF_AC_MODE,
|
||||||
CONF_TEMP_SENSOR,
|
CONF_TEMP_SENSOR,
|
||||||
CONF_EXTERNAL_TEMP_SENSOR,
|
CONF_EXTERNAL_TEMP_SENSOR,
|
||||||
CONF_CYCLE_MIN,
|
CONF_CYCLE_MIN,
|
||||||
@@ -112,6 +113,7 @@ MOCK_TH_OVER_SWITCH_TPI_CONFIG = {
|
|||||||
|
|
||||||
MOCK_TH_OVER_CLIMATE_TYPE_CONFIG = {
|
MOCK_TH_OVER_CLIMATE_TYPE_CONFIG = {
|
||||||
CONF_CLIMATE: "climate.mock_climate",
|
CONF_CLIMATE: "climate.mock_climate",
|
||||||
|
CONF_AC_MODE: False,
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_PRESETS_CONFIG = {
|
MOCK_PRESETS_CONFIG = {
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ async def test_window_management_time_not_enough(
|
|||||||
await try_window_condition(None)
|
await try_window_condition(None)
|
||||||
assert entity.window_state == STATE_OFF
|
assert entity.window_state == STATE_OFF
|
||||||
|
|
||||||
await entity.remove_thermostat()
|
entity.remove_thermostat()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
@@ -234,7 +234,7 @@ async def test_window_management_time_enough(
|
|||||||
assert entity.preset_mode is PRESET_BOOST
|
assert entity.preset_mode is PRESET_BOOST
|
||||||
|
|
||||||
# Clean the entity
|
# Clean the entity
|
||||||
await entity.remove_thermostat()
|
entity.remove_thermostat()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
@@ -418,7 +418,7 @@ async def test_window_auto_fast(hass: HomeAssistant, skip_hass_states_is_state):
|
|||||||
assert entity.hvac_mode is HVACMode.HEAT
|
assert entity.hvac_mode is HVACMode.HEAT
|
||||||
|
|
||||||
# Clean the entity
|
# Clean the entity
|
||||||
await entity.remove_thermostat()
|
entity.remove_thermostat()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
@@ -561,7 +561,7 @@ async def test_window_auto_auto_stop(hass: HomeAssistant, skip_hass_states_is_st
|
|||||||
assert entity.preset_mode is PRESET_BOOST
|
assert entity.preset_mode is PRESET_BOOST
|
||||||
|
|
||||||
# Clean the entity
|
# Clean the entity
|
||||||
await entity.remove_thermostat()
|
entity.remove_thermostat()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
@@ -670,4 +670,4 @@ async def test_window_auto_no_on_percent(
|
|||||||
assert entity.hvac_mode is HVACMode.HEAT
|
assert entity.hvac_mode is HVACMode.HEAT
|
||||||
|
|
||||||
# Clean the entity
|
# Clean the entity
|
||||||
await entity.remove_thermostat()
|
entity.remove_thermostat()
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ class UnderlyingSwitch(UnderlyingEntity):
|
|||||||
self._on_time_sec,
|
self._on_time_sec,
|
||||||
)
|
)
|
||||||
|
|
||||||
await self._cancel_cycle()
|
self._cancel_cycle()
|
||||||
|
|
||||||
if self._hvac_mode == HVACMode.OFF:
|
if self._hvac_mode == HVACMode.OFF:
|
||||||
_LOGGER.debug("%s - End of cycle (HVAC_MODE_OFF - 2)", self)
|
_LOGGER.debug("%s - End of cycle (HVAC_MODE_OFF - 2)", self)
|
||||||
@@ -327,7 +327,7 @@ class UnderlyingSwitch(UnderlyingEntity):
|
|||||||
self._should_relaunch_control_heating,
|
self._should_relaunch_control_heating,
|
||||||
self._off_time_sec,
|
self._off_time_sec,
|
||||||
)
|
)
|
||||||
await self._cancel_cycle()
|
self._cancel_cycle()
|
||||||
|
|
||||||
if self._hvac_mode == HVACMode.OFF:
|
if self._hvac_mode == HVACMode.OFF:
|
||||||
_LOGGER.debug("%s - End of cycle (HVAC_MODE_OFF - 2)", self)
|
_LOGGER.debug("%s - End of cycle (HVAC_MODE_OFF - 2)", self)
|
||||||
@@ -446,7 +446,7 @@ class UnderlyingClimate(UnderlyingEntity):
|
|||||||
def is_device_active(self):
|
def is_device_active(self):
|
||||||
"""If the toggleable device is currently active."""
|
"""If the toggleable device is currently active."""
|
||||||
if self.is_initialized:
|
if self.is_initialized:
|
||||||
return self._underlying_climate.hvac_action not in [
|
return self._underlying_climate.hvac_mode != HVACMode.OFF and self._underlying_climate.hvac_action not in [
|
||||||
HVACAction.IDLE,
|
HVACAction.IDLE,
|
||||||
HVACAction.OFF,
|
HVACAction.OFF,
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user