Skip to content

Commit

Permalink
Reset temporary values before write (#1885)
Browse files Browse the repository at this point in the history
* Update requirements

* Reset temporary values before write
  • Loading branch information
SukramJ authored Nov 30, 2024
1 parent ca41659 commit 9d44c8c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
exclude_types: [csv, json]
exclude: ^tests/fixtures/|hahomematic/rega_scripts
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
rev: 1.8.0
hooks:
- id: bandit
args:
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 2024.11.11 (2024-11-25)

- Enable central link management for HmIP-wired
- Reset temporary values before write

# Version 2024.11.10 (2024-11-24)

Expand Down
10 changes: 8 additions & 2 deletions hahomematic/model/data_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ def register_data_point_updated_callback(self, cb: Callable, custom_id: str) ->
)
return None

def _reset_temporary_timestamps(self) -> None:
"""Reset the temporary timestamps."""
self._set_temporary_modified_at(now=INIT_DATETIME)
self._set_temporary_refreshed_at(now=INIT_DATETIME)

@abstractmethod
def _get_path_data(self) -> PathData:
"""Return the path data."""
Expand Down Expand Up @@ -710,7 +715,6 @@ async def load_data_point_value(

def write_value(self, value: Any) -> tuple[ParameterT, ParameterT]:
"""Update value of the data_point."""

self._reset_temporary_value()

old_value = self._current_value
Expand All @@ -733,6 +737,8 @@ def write_value(self, value: Any) -> tuple[ParameterT, ParameterT]:

def write_temporary_value(self, value: Any) -> None:
"""Update the temporary value of the data_point."""
self._reset_temporary_value()

temp_value = self._convert_value(value)
if self._value == temp_value:
self._set_temporary_refreshed_at()
Expand Down Expand Up @@ -784,7 +790,7 @@ def _convert_value(self, value: Any) -> ParameterT:
def _reset_temporary_value(self) -> None:
"""Reset the temp storage."""
self._temporary_value = None # type: ignore[assignment]
self._set_modified_at(now=INIT_DATETIME)
self._reset_temporary_timestamps()

def get_event_data(self, value: Any = None) -> dict[EventKey, Any]:
"""Get the event_data."""
Expand Down
8 changes: 8 additions & 0 deletions hahomematic/model/hub/data_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,15 @@ async def event(self, value: Any) -> None:
"""Handle event for which this data_point has subscribed."""
self.write_value(value=value)

def _reset_temporary_value(self) -> None:
"""Reset the temp storage."""
self._temporary_value = None
self._reset_temporary_timestamps()

def write_value(self, value: Any) -> None:
"""Set variable value on CCU/Homegear."""
self._reset_temporary_value()

old_value = self._current_value
new_value = self._convert_value(old_value=old_value, new_value=value)
if old_value == new_value:
Expand All @@ -175,6 +182,7 @@ def write_value(self, value: Any) -> None:
def _write_temporary_value(self, value: Any) -> None:
"""Update the temporary value of the data_point."""
temp_value = self._convert_value(old_value=self._current_value, new_value=value)
self._reset_temporary_value()
if self._value == temp_value:
self._set_temporary_refreshed_at()
else:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp>=3.11.7
orjson>=3.10.11
aiohttp>=3.11.8
orjson>=3.10.12
python-slugify>=8.0.4
voluptuous>=0.15.2
6 changes: 3 additions & 3 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
-r requirements.txt
-r requirements_test_pre_commit.txt

coverage==7.6.7
coverage==7.6.8
freezegun==1.5.1
mypy-dev==1.14.0a2
pip==24.3.1
pre-commit==4.0.1
pur==7.3.2
pydantic==2.10.1
pydantic==2.10.2
pydevccu==0.1.8
pylint-per-file-ignores==1.3.2
pylint-strict-informational==0.1
Expand All @@ -20,4 +20,4 @@ pytest-socket==0.7.0
pytest-timeout==2.3.1
pytest==8.3.3
types-python-slugify==8.0.2.20240310
uv==0.5.4
uv==0.5.5
2 changes: 1 addition & 1 deletion requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bandit==1.7.10
bandit==1.8.0
codespell==2.3.0
ruff==0.8.0
yamllint==1.35.1

0 comments on commit 9d44c8c

Please sign in to comment.