Skip to content

Commit

Permalink
Fix unignore search (#1409)
Browse files Browse the repository at this point in the history
* Fix unignore search

* Update visibility.py

* Add more tests

* Update visibility.py

* Update visibility.py

* Update changelog.md
  • Loading branch information
SukramJ authored Jan 31, 2024
1 parent 7ccc6de commit 5ab904a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 19 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 2024.X.XX (2024-01-28)
# Version 2024.1.11 (2024-01-31)

- Remove deprecation warnings for py3.12
- Fix/improve unignore search

# Version 2024.1.10 (2024-01-28)

Expand Down
47 changes: 31 additions & 16 deletions hahomematic/caches/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def __init__(

# unignore from custom unignore files
# parameter
self._custom_un_ignore_parameters: Final[set[str]] = set()
self._custom_un_ignore_values_parameters: Final[set[str]] = set()

# device_type, channel_no, paramset_key, parameter
self._custom_un_ignore_complex: Final[
Expand Down Expand Up @@ -394,23 +394,33 @@ def _parameter_is_un_ignored(
device_type_l = device_type.lower()

# check if parameter is in custom_un_ignore
if paramset_key == ParamsetKey.VALUES and parameter in self._custom_un_ignore_parameters:
if (
paramset_key == ParamsetKey.VALUES
and parameter in self._custom_un_ignore_values_parameters
):
return True

# check if parameter is in custom_un_ignore with paramset_key
if (
(custom_un_ignore := self._custom_un_ignore_complex)
and (
channel_values := custom_un_ignore.get(device_type_l)
or custom_un_ignore.get(_UN_IGNORE_WILDCARD)
)
and (
paramset_key_values := channel_values.get(channel_no)
or channel_values.get(_UN_IGNORE_WILDCARD)

search_matrix = (
(
(device_type_l, channel_no),
(device_type_l, _UN_IGNORE_WILDCARD),
(_UN_IGNORE_WILDCARD, channel_no),
(_UN_IGNORE_WILDCARD, _UN_IGNORE_WILDCARD),
)
and parameter in paramset_key_values.get(paramset_key, set())
):
return True # pragma: no cover
if paramset_key == ParamsetKey.VALUES
else ((device_type_l, channel_no),)
)

for dtl, cno in search_matrix:
if (
(custom_un_ignore := self._custom_un_ignore_complex)
and (channel_values := custom_un_ignore.get(dtl))
and (paramset_key_values := channel_values.get(cno))
and parameter in paramset_key_values.get(paramset_key, set())
):
return True # pragma: no cover

# check if parameter is in _UN_IGNORE_PARAMETERS_BY_DEVICE
if not custom_only:
Expand Down Expand Up @@ -466,7 +476,7 @@ def _add_line_to_cache(self, line: str) -> None:

if line_details := self._get_unignore_line_details(line=line):
if isinstance(line_details, str):
self._custom_un_ignore_parameters.add(line)
self._custom_un_ignore_values_parameters.add(line_details)
return

self._add_complex_unignore_entry(
Expand Down Expand Up @@ -556,7 +566,12 @@ def _get_unignore_line_details(
line,
)
return None

if (
device_type == _UN_IGNORE_WILDCARD
and channel_no == _UN_IGNORE_WILDCARD
and paramset_key == ParamsetKey.VALUES
):
return parameter
if device_type is not None and parameter is not None and paramset_key is not None:
return device_type, channel_no, parameter, paramset_key
return line
Expand Down
2 changes: 1 addition & 1 deletion hahomematic/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create_entities_and_append_to_device(device: hmd.HmDevice) -> None:
)
# required to fix hm master paramset operation values
if parameter_data[Description.OPERATIONS] == 0 and parameter_is_un_ignored:
parameter_data[Description.OPERATIONS] = 6
parameter_data[Description.OPERATIONS] = 3

if parameter_data[Description.OPERATIONS] & Operations.EVENT and (
parameter in CLICK_EVENTS
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "hahomematic"
version = "2024.1.10"
version = "2024.1.11"
license = {text = "MIT License"}
description = "Homematic interface for Home Assistant running on Python 3."
readme = "README.md"
Expand Down
85 changes: 85 additions & 0 deletions tests/test_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,91 @@ async def test_device_unignore_hm(
assert generic_entity.usage == EntityUsage.ENTITY


@pytest.mark.parametrize(
("lines", "parameter", "channel_no", "paramset_key", "expected_result"),
[
(["DECISION_VALUE:VALUES@all:all"], "DECISION_VALUE", 3, "VALUES", True),
(["INHIBIT:VALUES@HM-ES-PMSw1-Pl:1"], "INHIBIT", 1, "VALUES", True),
(["WORKING:VALUES@all:all"], "WORKING", 1, "VALUES", True),
(["AVERAGING:MASTER@HM-ES-PMSw1-Pl:2"], "AVERAGING", 2, "MASTER", True),
(
["DECISION_VALUE:VALUES@all:all", "AVERAGING:MASTER@HM-ES-PMSw1-Pl:2"],
"DECISION_VALUE",
3,
"VALUES",
True,
),
(
[
"DECISION_VALUE:VALUES@HM-ES-PMSw1-Pl:3",
"INHIBIT:VALUES@HM-ES-PMSw1-Pl:1",
"WORKING:VALUES@HM-ES-PMSw1-Pl:1",
"AVERAGING:MASTER@HM-ES-PMSw1-Pl:2",
],
"DECISION_VALUE",
3,
"VALUES",
True,
),
(
[
"DECISION_VALUE:VALUES@HM-ES-PMSw1-Pl:3",
"INHIBIT:VALUES@HM-ES-PMSw1-Pl:1",
"WORKING:VALUES@HM-ES-PMSw1-Pl:1",
"AVERAGING:MASTER@HM-ES-PMSw1-Pl:2",
],
"AVERAGING",
2,
"MASTER",
True,
),
(
["DECISION_VALUE", "INHIBIT:VALUES", "WORKING", "AVERAGING:MASTER@HM-ES-PMSw1-Pl:2"],
"AVERAGING",
2,
"MASTER",
True,
),
(
["DECISION_VALUE", "INHIBIT:VALUES", "WORKING", "AVERAGING:MASTER@HM-ES-PMSw1-Pl:2"],
"DECISION_VALUE",
3,
"VALUES",
True,
),
],
)
@pytest.mark.asyncio
async def test_device_unignore_hm2(
factory: helper.Factory,
lines: list[str],
parameter: str,
channel_no: int | None,
paramset_key: str,
expected_result: bool,
) -> None:
"""Test device un ignore."""
central, _ = await factory.get_default_central(
{"VCU0000137": "HM-ES-PMSw1-Pl.json"}, un_ignore_list=lines
)

assert (
central.parameter_visibility.parameter_is_un_ignored(
device_type="HM-ES-PMSw1-Pl",
channel_no=channel_no,
paramset_key=paramset_key,
parameter=parameter,
)
is expected_result
)
generic_entity = central.get_generic_entity(
f"VCU0000137:{channel_no}" if channel_no else "VCU0000137", parameter
)
if expected_result:
assert generic_entity
assert generic_entity.usage == EntityUsage.ENTITY


@pytest.mark.asyncio
async def test_all_parameters(factory: helper.Factory) -> None:
"""Test all_parameters."""
Expand Down

0 comments on commit 5ab904a

Please sign in to comment.