Skip to content

Commit

Permalink
issue #683 - incorrect temperature reversion on window close
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marc Collin committed Dec 22, 2024
1 parent 6c5ddc3 commit df41df0
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 75 deletions.
113 changes: 56 additions & 57 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,68 +1,67 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
// "image": "ghcr.io/ludeeus/devcontainer/integration:latest",
{
"build": {
"dockerfile": "Dockerfile"
},
"name": "Versatile Thermostat integration",
"appPort": [
"8123:8123"
],
// "postCreateCommand": "container install",
"postCreateCommand": "./container dev-setup",
"build": {
"dockerfile": "Dockerfile"
},
"name": "Versatile Thermostat integration",
"appPort": ["8123:8123"],
// "postCreateCommand": "container install",
"postCreateCommand": "./container dev-setup",

"mounts": [
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached",
// uncomment this to get the versatile-thermostat-ui-card
"source=${localEnv:HOME}/SugarSync/Projets/home-assistant/versatile-thermostat-ui-card/dist,target=/workspaces/versatile_thermostat/config/www/community/versatile-thermostat-ui-card,type=bind,consistency=cached"
],

"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.pylint",
// Doesn't work (crash). Default in python is to use Jedi see Settings / Python / Default Language
// "ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.black-formatter",
"visualstudioexptteam.vscodeintellicode",
"redhat.vscode-yaml",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ferrierbenjamin.fold-unfold-all-icone",
"LittleFoxTeam.vscode-python-test-adapter",
"donjayamanne.githistory",
"waderyan.gitblame",
"keesschollaart.vscode-home-assistant",
"vscode.markdown-math",
"yzhang.markdown-all-in-one",
"github.vscode-github-actions",
"azuretools.vscode-docker"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"args": []
}
},
"terminal.integrated.defaultProfile.linux": "bash",
// "terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": true,
"pylint.lintOnChange": false,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
// "python.experiments.optOutFrom": ["pythonTestAdapter"],
// "python.analysis.logLevel": "Trace"
}
}
}
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.pylint",
// Doesn't work (crash). Default in python is to use Jedi see Settings / Python / Default Language
// "ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.black-formatter",
"visualstudioexptteam.vscodeintellicode",
"redhat.vscode-yaml",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ferrierbenjamin.fold-unfold-all-icone",
"LittleFoxTeam.vscode-python-test-adapter",
"donjayamanne.githistory",
"waderyan.gitblame",
"keesschollaart.vscode-home-assistant",
"vscode.markdown-math",
"yzhang.markdown-all-in-one",
"github.vscode-github-actions",
"azuretools.vscode-docker",
"huizhou.githd",
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"args": []
}
},
"terminal.integrated.defaultProfile.linux": "bash",
// "terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": true,
"pylint.lintOnChange": false,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
// "python.experiments.optOutFrom": ["pythonTestAdapter"],
// "python.analysis.logLevel": "Trace"
}
}
}
}
42 changes: 26 additions & 16 deletions custom_components/versatile_thermostat/base_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ async def async_set_preset_mode(
):
"""Set new preset mode."""

# Wer accept a new preset when:
# We accept a new preset when:
# 1. last_central_mode is not set,
# 2. or last_central_mode is AUTO,
# 3. or last_central_mode is CENTRAL_MODE_FROST_PROTECTION and preset_mode is PRESET_FROST_PROTECTION (to be abel to re-set the preset_mode)
Expand Down Expand Up @@ -1326,6 +1326,7 @@ async def _async_set_preset_mode_internal(
return

old_preset_mode = self._attr_preset_mode
recalculate = True
if preset_mode == PRESET_NONE:
self._attr_preset_mode = PRESET_NONE
if self._saved_target_temp:
Expand All @@ -1337,16 +1338,24 @@ async def _async_set_preset_mode_internal(
if self._attr_preset_mode == PRESET_NONE:
self._saved_target_temp = self._target_temp
self._attr_preset_mode = preset_mode
await self._async_internal_set_temperature(
self.find_preset_temp(preset_mode)
)
# Switch the temperature if window is not 'on'
if self.window_state != STATE_ON:
await self._async_internal_set_temperature(
self.find_preset_temp(preset_mode)
)
else:
# Window is on, so we just save the new expected temp
# so that closing the window will restore it
recalculate = False
self._saved_target_temp = self.find_preset_temp(preset_mode)

self.reset_last_temperature_time(old_preset_mode)
if recalculate:
self.reset_last_temperature_time(old_preset_mode)

if overwrite_saved_preset:
self.save_preset_mode()
if overwrite_saved_preset:
self.save_preset_mode()

self.recalculate()
self.recalculate()
# Notify only if there was a real change
if self._attr_preset_mode != old_preset_mode:
self.send_event(EventType.PRESET_EVENT, {"preset": self._attr_preset_mode})
Expand Down Expand Up @@ -1455,19 +1464,20 @@ async def async_set_temperature(self, **kwargs):
_LOGGER.info("%s - Set target temp: %s", self, temperature)
if temperature is None:
return
await self._async_internal_set_temperature(temperature)

self._attr_preset_mode = PRESET_NONE
self.recalculate()
self.reset_last_change_time_from_vtherm()
await self.async_control_heating(force=True)
if self.window_state != STATE_ON:
await self._async_internal_set_temperature(temperature)
self.recalculate()
self.reset_last_change_time_from_vtherm()
await self.async_control_heating(force=True)
else:
self._saved_target_temp = temperature

async def _async_internal_set_temperature(self, temperature: float):
"""Set the target temperature and the target temperature of underlying climate if any
For testing purpose you can pass an event_timestamp.
"""
"""Set the target temperature and the target temperature of underlying climate if any"""
if temperature:
self._target_temp = temperature
return

def get_state_date_or_now(self, state: State) -> datetime:
"""Extract the last_changed state from State or return now if not available"""
Expand Down
Loading

0 comments on commit df41df0

Please sign in to comment.