Skip to content

Commit

Permalink
23.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Nov 23, 2023
1 parent c53ff89 commit 61d2032
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 3 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ select = [

ignore = [
"RET501", # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
"TRY400" # https://docs.astral.sh/ruff/rules/error-instead-of-exception/
"TRY400", # https://docs.astral.sh/ruff/rules/error-instead-of-exception/

"A003", # https://docs.astral.sh/ruff/rules/builtin-attribute-shadowing/
]


Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ MyOpenhabRule()
```

# Changelog
#### 23.XX.X (2023-XX-XX)
#### 23.11.1 (2023-11-23)
- Fix for very small float values (#425)
- Fix for writing to persistence (#424)
- Updated dependencies

#### 23.09.2 (2023-09-24)
- Made channel type on a ``Thing`` optional (#416)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Packages for source formatting
# -----------------------------------------------------------------------------
pre-commit >= 3.5, < 3.6
ruff >= 0.1.5, < 0.2
ruff >= 0.1.6, < 0.2

# -----------------------------------------------------------------------------
# Packages for other developement tasks
Expand Down
6 changes: 3 additions & 3 deletions requirements_setup.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiohttp == 3.8.6
pydantic == 2.5.0
aiohttp == 3.9.0
pydantic == 2.5.2
msgspec == 0.18.4
pendulum == 2.1.2
bidict == 0.22.1
Expand All @@ -13,7 +13,7 @@ easyconfig == 0.3.1
stack_data == 0.6.3
colorama == 0.4.6

voluptuous == 0.14.0
voluptuous == 0.14.1

typing-extensions == 4.8.0

Expand Down
9 changes: 5 additions & 4 deletions src/HABApp/__check_dependency_packages__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import importlib
import sys
from typing import List, Dict

from HABApp.__debug_info__ import print_debug_info


def get_dependencies() -> List[str]:
def get_dependencies() -> list[str]:
return [
'aiohttp-sse-client',
'aiohttp',
Expand All @@ -31,7 +32,7 @@ def get_dependencies() -> List[str]:
def check_dependency_packages():
"""Imports all dependencies and reports failures"""

missing: Dict[str, ModuleNotFoundError] = {}
missing: dict[str, ModuleNotFoundError] = {}

# Package aliases (if the import name differs from the package name)
alias = {
Expand All @@ -43,7 +44,7 @@ def check_dependency_packages():
for name in get_dependencies():
try:
importlib.import_module(alias.get(name, name))
except ModuleNotFoundError as e:
except ModuleNotFoundError as e: # noqa: PERF203
missing[name] = e

if not missing:
Expand Down
6 changes: 3 additions & 3 deletions src/HABApp/__debug_info__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import platform
import sys

from HABApp.__version__ import __version__


def get_debug_info() -> str:

info = {
'HABApp': __version__,
'Platform': platform.platform(),
'Machine': platform.machine(),
'Python': sys.version,
}

indent = max(map(lambda x: len(x), info))
indent = max(len(x) for x in info)
ret = '\n'.join('{:{indent}s}: {:s}'.format(k, str(v).replace('\n', ''), indent=indent) for k, v in info.items())

try:
Expand All @@ -26,7 +26,7 @@ def get_debug_info() -> str:
ret += f'\n\nInstalled Packages\n{"-" * 80}\n{table}'

except Exception as e:
ret += f'\n\nCould not get installed Packages!\nError: {str(e)}'
ret += f'\n\nCould not get installed Packages!\nError: {e!s}'

return ret

Expand Down
2 changes: 1 addition & 1 deletion src/HABApp/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# Development versions contain the DEV-COUNTER postfix:
# - 23.09.0.DEV-1

__version__ = '23.09.2'
__version__ = '23.11.0'
7 changes: 4 additions & 3 deletions src/HABApp/core/events/filter/event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from inspect import isclass
from typing import Final, Optional
from typing import get_type_hints as _get_type_hints
from typing import get_type_hints as typing_get_type_hints

from HABApp.core.const import MISSING
from HABApp.core.const.hints import TYPE_ANY_CLASS_TYPE
Expand All @@ -22,7 +22,7 @@ def __init__(self, event_class: TYPE_ANY_CLASS_TYPE, **kwargs):
self.attr_name2: Optional[str] = None
self.attr_value2 = None

type_hints = _get_type_hints(event_class)
type_hints = typing_get_type_hints(event_class)

for arg, value in kwargs.items():
if value is MISSING:
Expand All @@ -39,7 +39,8 @@ def __init__(self, event_class: TYPE_ANY_CLASS_TYPE, **kwargs):
self.attr_name2 = arg
self.attr_value2 = value
else:
raise ValueError('Not implemented for more than 2 values!')
msg = 'Not implemented for more than 2 values!'
raise ValueError(msg)

def trigger(self, event) -> bool:
if not isinstance(event, self.event_class):
Expand Down
1 change: 1 addition & 0 deletions src/HABApp/openhab/item_to_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def add_to_registry(item: 'HABApp.openhab.items.OpenhabItem', set_value=False):
# Replace existing item with the updated definition
Items.pop_item(name)
Items.add_item(item)
return None


def remove_from_registry(name: str):
Expand Down
3 changes: 2 additions & 1 deletion src/HABApp/openhab/map_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ def get_event(_in_dict: dict) -> OpenhabEvent:
try:
return _events[event_type].from_dict(topic, payload)
except KeyError:
raise ValueError(f'Unknown Event: {event_type:s} for {_in_dict}')
msg = f'Unknown Event: {event_type:s} for {_in_dict}'
raise ValueError(msg) from None
32 changes: 23 additions & 9 deletions src/HABApp/openhab/process_events.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
import logging
from asyncio import create_task
from typing import Union

import HABApp
import HABApp.core
import HABApp.openhab.events
from HABApp.core.asyncio import create_task
from HABApp.core.errors import ItemNotFoundException
from HABApp.core.events import ValueUpdateEvent, ValueChangeEvent
from HABApp.core.internals import uses_post_event, uses_get_item
from HABApp.core.events import ValueChangeEvent, ValueUpdateEvent
from HABApp.core.internals import uses_get_item, uses_post_event
from HABApp.core.logger import log_warning
from HABApp.core.wrapper import process_exception
from HABApp.openhab.definitions.topics import TOPIC_THINGS, TOPIC_ITEMS
from HABApp.openhab.events import GroupStateChangedEvent, GroupStateUpdatedEvent, \
ItemAddedEvent, ItemRemovedEvent, ItemUpdatedEvent, \
ThingStatusInfoEvent, ThingAddedEvent, ThingRemovedEvent, ThingUpdatedEvent, ThingConfigStatusInfoEvent
from HABApp.openhab.item_to_reg import add_to_registry, remove_from_registry, remove_thing_from_registry, \
add_thing_to_registry
from HABApp.openhab.definitions.topics import TOPIC_ITEMS, TOPIC_THINGS
from HABApp.openhab.events import (
GroupStateChangedEvent,
GroupStateUpdatedEvent,
ItemAddedEvent,
ItemRemovedEvent,
ItemUpdatedEvent,
ThingAddedEvent,
ThingConfigStatusInfoEvent,
ThingRemovedEvent,
ThingStatusInfoEvent,
ThingUpdatedEvent,
)
from HABApp.openhab.item_to_reg import (
add_thing_to_registry,
add_to_registry,
remove_from_registry,
remove_thing_from_registry,
)
from HABApp.openhab.map_events import get_event


log = logging.getLogger('HABApp.openhab.items')

post_event = uses_post_event()
Expand Down
22 changes: 13 additions & 9 deletions src/HABApp/rule/interfaces/rule_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import logging
import os
from pathlib import Path
from typing import Optional, Union, Iterable, Any, Tuple, Dict, List, Callable
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union

from typing_extensions import TypeAlias

import HABApp
from HABApp.core.logger import HABAppError, HABAppWarning
from HABApp.core.wrapper import process_exception


log = logging.getLogger('HABApp.execute')

HINT_EXEC_ARGS: TypeAlias = Union[str, Path]
Expand All @@ -28,10 +29,12 @@ def _ensure_str_objs(objs: Iterable[HINT_EXEC_ARGS], key: str, enforce_abs=False
path_val = Path(val)
str_val = val
else:
raise ValueError(f'{key:s}[{i:d}] is not of type str! "{val}" ({type(val).__name__:s})')
msg = f'{key:s}[{i:d}] is not of type str! "{val}" ({type(val).__name__:s})'
raise TypeError(msg)

if enforce_abs and not path_val.is_absolute():
raise ValueError(f'{key:s}[{i:d}] is not an absolute path: "{val}"')
msg = f'{key:s}[{i:d}] is not an absolute path: "{val}"'
raise ValueError(msg)

new_args.append(str_val)

Expand All @@ -42,20 +45,22 @@ def build_exec_params(*args: HINT_EXEC_ARGS,
_capture_output=True,
_additional_python_path: HINT_PYTHON_PATH = None,
**kwargs: Any) -> Tuple[Iterable[str], Dict[str, Any]]:

# convenience for easy capturing
if _capture_output:
if 'stdout' in kwargs:
raise ValueError('Parameter "capture_output" can not be used with "stdout" in kwargs!')
msg = 'Parameter "capture_output" can not be used with "stdout" in kwargs!'
raise ValueError(msg)
kwargs['stdout'] = asyncio.subprocess.PIPE
if 'stderr' in kwargs:
raise ValueError('Parameter "capture_output" can not be used with "stderr" in kwargs!')
msg = 'Parameter "capture_output" can not be used with "stderr" in kwargs!'
raise ValueError(msg)
kwargs['stderr'] = asyncio.subprocess.PIPE

# convenience for additional libraries
if _additional_python_path is not None:
if 'env' in kwargs:
raise ValueError('Parameter "additional_python_path" can not be used with "env" in kwargs!')
msg = 'Parameter "additional_python_path" can not be used with "env" in kwargs!'
raise ValueError(msg)

ppath = _ensure_str_objs(_additional_python_path, 'additional_python_path', enforce_abs=True)

Expand Down Expand Up @@ -104,7 +109,6 @@ def __eq__(self, other):


async def async_subprocess_exec(callback, *args, calling_func, raw_info: bool, **kwargs):

call_str = ''

try:
Expand All @@ -113,7 +117,7 @@ async def async_subprocess_exec(callback, *args, calling_func, raw_info: bool, *
stdout = None
stderr = None

call_str = ' '.join(map(lambda x: f'"{x}"', args))
call_str = ' '.join(f'"{x}"' for x in args)

try:
proc = await asyncio.create_subprocess_exec(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ envlist =
py39
py310
py311
py312
docs



[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310, flake, docs
3.11: py311

3.11: py312


[testenv]
Expand Down

0 comments on commit 61d2032

Please sign in to comment.