From 8a67f49bf0b79f566d4e38edde461688579532b2 Mon Sep 17 00:00:00 2001 From: spacemanspiff2007 <10754716+spacemanspiff2007@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:15:41 +0100 Subject: [PATCH] ci --- run/conf_testing/rules/openhab/test_interface.py | 8 +++++--- .../rules/openhab/test_item_events.py | 1 - .../rules/openhab/test_item_funcs.py | 10 ++++++---- src/HABApp/core/errors.py | 1 + src/HABApp/core/items/item_color.py | 1 - .../openhab/connection/plugins/load_items.py | 2 +- src/HABApp/openhab/items/color_item.py | 2 +- src/HABApp/openhab/items/commands.py | 1 + tests/test_openhab/test_items/conftest.py | 6 +++--- tests/test_openhab/test_items/test__converter.py | 2 +- tests/test_openhab/test_items/test_commands.py | 6 ++---- tests/test_openhab/test_items/test_dimmer.py | 2 +- tests/test_openhab/test_items/test_switch.py | 2 +- .../test_openhab/test_items/test_tuple_items.py | 4 ++-- tests/test_openhab/test_types.py | 16 +++++++++------- tests/test_openhab/test_values.py | 2 +- 16 files changed, 35 insertions(+), 31 deletions(-) diff --git a/run/conf_testing/rules/openhab/test_interface.py b/run/conf_testing/rules/openhab/test_interface.py index 2129ce57..8794358c 100644 --- a/run/conf_testing/rules/openhab/test_interface.py +++ b/run/conf_testing/rules/openhab/test_interface.py @@ -11,17 +11,19 @@ # ---------------------------------------------------------------------------------------------------------------------- import time -from HABApp.openhab.events import ItemCommandEvent, ItemCommandEventFilter from HABAppTests import ( + EventWaiter, ItemWaiter, OpenhabTmpItem, TestBaseRule, - get_openhab_test_states, get_openhab_item_names, - get_random_name, get_openhab_test_commands, EventWaiter, + get_openhab_test_commands, + get_openhab_test_states, + get_random_name, ) import HABApp +from HABApp.openhab.events import ItemCommandEventFilter class TestOpenhabInterface(TestBaseRule): diff --git a/run/conf_testing/rules/openhab/test_item_events.py b/run/conf_testing/rules/openhab/test_item_events.py index 6bd4774b..07c79dc5 100644 --- a/run/conf_testing/rules/openhab/test_item_events.py +++ b/run/conf_testing/rules/openhab/test_item_events.py @@ -1,4 +1,3 @@ -import time from HABAppTests import ( EventWaiter, diff --git a/run/conf_testing/rules/openhab/test_item_funcs.py b/run/conf_testing/rules/openhab/test_item_funcs.py index d2aa2beb..f363369f 100644 --- a/run/conf_testing/rules/openhab/test_item_funcs.py +++ b/run/conf_testing/rules/openhab/test_item_funcs.py @@ -1,15 +1,17 @@ import dataclasses import logging -from HABApp.core.types import HSB -from HABAppTests import ItemWaiter, OpenhabTmpItem, TestBaseRule, get_openhab_test_states, get_openhab_item_names, get_openhab_test_commands +from HABAppTests import ( + ItemWaiter, + OpenhabTmpItem, + TestBaseRule, +) +from HABApp.core.types import HSB from HABApp.openhab.items import ( ColorItem, ContactItem, DimmerItem, - ImageItem, - LocationItem, NumberItem, OpenhabItem, RollershutterItem, diff --git a/src/HABApp/core/errors.py b/src/HABApp/core/errors.py index a2c5b786..fbb814f2 100644 --- a/src/HABApp/core/errors.py +++ b/src/HABApp/core/errors.py @@ -1,4 +1,5 @@ from typing import Any as _Any + from typing_extensions import Self as _Self from HABApp.core.const.hints import HasNameAttr as _HasNameAttr diff --git a/src/HABApp/core/items/item_color.py b/src/HABApp/core/items/item_color.py index f245a599..97c7f92f 100644 --- a/src/HABApp/core/items/item_color.py +++ b/src/HABApp/core/items/item_color.py @@ -118,4 +118,3 @@ def get_create_item(cls, name: str, if not isinstance(item, cls): raise WrongItemTypeError.from_item(item, cls) return item - diff --git a/src/HABApp/openhab/connection/plugins/load_items.py b/src/HABApp/openhab/connection/plugins/load_items.py index 68d55a84..23a7aea5 100644 --- a/src/HABApp/openhab/connection/plugins/load_items.py +++ b/src/HABApp/openhab/connection/plugins/load_items.py @@ -12,7 +12,7 @@ from HABApp.openhab.connection.connection import OpenhabConnection, OpenhabContext from HABApp.openhab.connection.handler import map_null_str from HABApp.openhab.connection.handler.func_async import async_get_all_items_state, async_get_items, async_get_things -from HABApp.openhab.definitions import QuantityValue, QuantityType +from HABApp.openhab.definitions import QuantityType from HABApp.openhab.item_to_reg import ( add_thing_to_registry, add_to_registry, diff --git a/src/HABApp/openhab/items/color_item.py b/src/HABApp/openhab/items/color_item.py index a44c5946..21f8ef9b 100644 --- a/src/HABApp/openhab/items/color_item.py +++ b/src/HABApp/openhab/items/color_item.py @@ -1,5 +1,5 @@ from collections.abc import Mapping -from typing import TYPE_CHECKING, Final, overload, override +from typing import TYPE_CHECKING, Final, override from HABApp.core.errors import InvalidItemValueError, ItemValueIsNoneError from HABApp.core.types import HSB, RGB diff --git a/src/HABApp/openhab/items/commands.py b/src/HABApp/openhab/items/commands.py index 80f665b8..e3c0d52c 100644 --- a/src/HABApp/openhab/items/commands.py +++ b/src/HABApp/openhab/items/commands.py @@ -4,6 +4,7 @@ from HABApp.openhab.definitions import OnOffType, UpDownType from HABApp.openhab.interface_sync import send_command + ON: Final = OnOffType.ON OFF: Final = OnOffType.OFF UP: Final = UpDownType.UP diff --git a/tests/test_openhab/test_items/conftest.py b/tests/test_openhab/test_items/conftest.py index c8222bd5..97840341 100644 --- a/tests/test_openhab/test_items/conftest.py +++ b/tests/test_openhab/test_items/conftest.py @@ -4,13 +4,13 @@ class ValueCollector: - def __init__(self): + def __init__(self) -> None: self.values = [] - def __call__(self, name, value): + def __call__(self, name, value) -> None: self.values.append(value) - def assert_called_with(self, *values, clear=True): + def assert_called_with(self, *values, clear=True) -> None: if len(values) == 1 and len(self.values) == 1: assert self.values[0] == values[0] diff --git a/tests/test_openhab/test_items/test__converter.py b/tests/test_openhab/test_items/test__converter.py index 8754c846..3706600e 100644 --- a/tests/test_openhab/test_items/test__converter.py +++ b/tests/test_openhab/test_items/test__converter.py @@ -4,7 +4,7 @@ from HABApp.openhab.items._converter import ValueToOh -def test_converter(): +def test_converter() -> None: a = ValueToOh('Asdf', UnDefType) b = a.add_type('Sdfg', DecimalType) diff --git a/tests/test_openhab/test_items/test_commands.py b/tests/test_openhab/test_items/test_commands.py index 9f25bc7a..c7bae3d0 100644 --- a/tests/test_openhab/test_items/test_commands.py +++ b/tests/test_openhab/test_items/test_commands.py @@ -1,11 +1,9 @@ -import typing import pytest -from HABApp import __version__ from HABApp.core.types import HSB -from HABApp.openhab.definitions import OnOffValue, OpenClosedValue, UpDownValue, OpenClosedType, UpDownType -from HABApp.openhab.items import ContactItem, ColorItem +from HABApp.openhab.definitions import OnOffValue, OpenClosedType, UpDownType, UpDownValue +from HABApp.openhab.items import ColorItem, ContactItem from HABApp.openhab.items.commands import OnOffCommand, UpDownCommand from HABApp.openhab.map_items import _items as item_dict diff --git a/tests/test_openhab/test_items/test_dimmer.py b/tests/test_openhab/test_items/test_dimmer.py index 360ae267..d514beec 100644 --- a/tests/test_openhab/test_items/test_dimmer.py +++ b/tests/test_openhab/test_items/test_dimmer.py @@ -22,7 +22,7 @@ def test_dimmer_set_value() -> None: DimmerItem('item_name').set_value('asdf') -def test_switch_post_update(posted_updates): +def test_switch_post_update(posted_updates) -> None: sw = DimmerItem('') sw.oh_post_update('ON') diff --git a/tests/test_openhab/test_items/test_switch.py b/tests/test_openhab/test_items/test_switch.py index 833aa7e1..27ed328ab3 100644 --- a/tests/test_openhab/test_items/test_switch.py +++ b/tests/test_openhab/test_items/test_switch.py @@ -21,7 +21,7 @@ def test_switch_set_value() -> None: SwitchItem('item_name').set_value('asdf') -def test_switch_post_update(posted_updates): +def test_switch_post_update(posted_updates) -> None: sw = SwitchItem('') sw.oh_post_update('ON') diff --git a/tests/test_openhab/test_items/test_tuple_items.py b/tests/test_openhab/test_items/test_tuple_items.py index 2278270b..b45e8a63 100644 --- a/tests/test_openhab/test_items/test_tuple_items.py +++ b/tests/test_openhab/test_items/test_tuple_items.py @@ -14,7 +14,7 @@ def test_call_set_value() -> None: assert call.value == ('a', 'b') -def test_call_post_update(posted_updates): +def test_call_post_update(posted_updates) -> None: call = CallItem('my_call_item') call.oh_post_update('asdf') @@ -59,7 +59,7 @@ def test_location_set_value() -> None: assert call.value == (1, 2, 3.3) -def test_location_post_update(posted_updates): +def test_location_post_update(posted_updates) -> None: call = LocationItem('my_call_item') call.oh_post_update((132, 456)) diff --git a/tests/test_openhab/test_types.py b/tests/test_openhab/test_types.py index d4db0d7c..2e8658ea 100644 --- a/tests/test_openhab/test_types.py +++ b/tests/test_openhab/test_types.py @@ -1,14 +1,14 @@ import itertools from datetime import datetime from inspect import signature -from typing import Final, Literal +from typing import Final import pytest from sphinx.util.inspect import isclass from whenever import SystemDateTime from HABApp.core.types import HSB, RGB -from HABApp.openhab.definitions import OpenHABDataType, RefreshType, UnDefType +from HABApp.openhab.definitions import OpenHABDataType, UnDefType from HABApp.openhab.definitions import types as types_module from HABApp.openhab.definitions.types import ( DateTimeType, @@ -17,12 +17,14 @@ PercentType, PointType, QuantityType, + RawType, RestrictedOpenHABDataType, StringListType, - StringType, RawType, + StringType, ) from tests.helpers.inspect import get_module_classes + ALL_TYPES: Final = tuple( cls for n in dir(types_module) if isclass(cls := getattr(types_module, n)) and issubclass(cls, OpenHABDataType) and cls is not OpenHABDataType @@ -35,7 +37,7 @@ @pytest.mark.parametrize('cls', (c for c in RESTRICTED_TYPES if c is not UnDefType)) -def test_restricted_types(cls: type[RestrictedOpenHABDataType]): +def test_restricted_types(cls: type[RestrictedOpenHABDataType]) -> None: for value in cls.get_allowed_values(): assert cls.from_oh_str(value) == value assert cls.to_oh_str(value) == value @@ -50,14 +52,14 @@ def test_restricted_types(cls: type[RestrictedOpenHABDataType]): assert return_annotation in annotations -def test_undef_type(): +def test_undef_type() -> None: for value in UnDefType.get_allowed_values(): assert UnDefType.from_oh_str(value) is None assert UnDefType.to_oh_str(None) == UnDefType.NULL @pytest.mark.parametrize('cls', RESTRICTED_TYPES) -def test_restricted_types_invalid(cls: type[RestrictedOpenHABDataType]): +def test_restricted_types_invalid(cls: type[RestrictedOpenHABDataType]) -> None: # Error if we get the wrong value with pytest.raises(ValueError) as e: cls.from_oh_str('asdf') @@ -343,7 +345,7 @@ def test_str_type_invalid() -> None: # Module constants # ---------------------------------------------------------------------------------------------------------------------- -def test_all_types(): +def test_all_types() -> None: classes = get_module_classes( types_module, subclass=(OpenHABDataType, RestrictedOpenHABDataType), include_subclass=False) diff --git a/tests/test_openhab/test_values.py b/tests/test_openhab/test_values.py index e32b72b8..65f9bfcd 100644 --- a/tests/test_openhab/test_values.py +++ b/tests/test_openhab/test_values.py @@ -8,7 +8,7 @@ from tests.helpers.inspect import get_module_classes -def test_all_values(): +def test_all_values() -> None: classes = get_module_classes( values_module, subclass=ComplexOhValue, include_subclass=False)