diff --git a/HABApp/__version__.py b/HABApp/__version__.py index 44c2d02a..bb67aeb6 100644 --- a/HABApp/__version__.py +++ b/HABApp/__version__.py @@ -1 +1 @@ -__version__ = '0.15.0' +__version__ = '0.15.1' diff --git a/HABApp/core/logger.py b/HABApp/core/logger.py index c9b4677b..6cfa3261 100644 --- a/HABApp/core/logger.py +++ b/HABApp/core/logger.py @@ -37,9 +37,12 @@ def add(self, text: str, *args, **kwargs): self.lines.append(text.format(*args, **kwargs)) return self - def add_exception(self, e: Exception): - for line in str(e).splitlines(): - self.lines.append(line) + def add_exception(self, e: Exception, add_traceback: bool = False): + if not add_traceback: + for line in str(e).splitlines(): + self.lines.append(line) + else: + self.lines.extend(HABApp.core.wrapper.format_exception(e)) return self def dump(self) -> bool: diff --git a/HABApp/openhab/connection_handler/func_async.py b/HABApp/openhab/connection_handler/func_async.py index 6f22999f..3ff617d4 100644 --- a/HABApp/openhab/connection_handler/func_async.py +++ b/HABApp/openhab/connection_handler/func_async.py @@ -192,6 +192,8 @@ async def async_set_thing_cfg(uid: str, cfg: typing.Dict[str, typing.Any]): elif ret.status >= 300: raise ValueError('Something went wrong') + return ret.status + # --------------------------------------------------------------------------------------------------------------------- # Link handling is experimental diff --git a/HABApp/parameters/parameter.py b/HABApp/parameters/parameter.py index 0007295f..53ecebd5 100644 --- a/HABApp/parameters/parameter.py +++ b/HABApp/parameters/parameter.py @@ -1,4 +1,5 @@ import typing +from math import ceil, floor from .parameters import add_parameter as _add_parameter from .parameters import get_value as _get_value @@ -29,6 +30,9 @@ def value(self) -> typing.Any: """ return _get_value(self.filename, *self.keys) + def __repr__(self): + return f'= other def __gt__(self, other): - if not isinstance(other, (int, float)): - return NotImplemented - return self.value > other - def __repr__(self): - return f'`). .. execute_code:: :header_output: Output @@ -166,10 +168,12 @@ It is possible to watch items for changes or updates. # the function has 1 argument which is the event def item_changed(self, event: ValueChangeEvent): - print(f'{event.name} changed from {event.old_value} to {event.value}') + print(f'{event.name} changed from "{event.old_value}" to "{event.value}"') + print(f'Last change of {self.my_item.name}: {self.my_item.last_change}') def item_updated(self, event: ValueUpdateEvent): - print(f'{event.name} updated value: {event.value}') + print(f'{event.name} updated value: "{event.value}"') + print(f'Last update of {self.my_item.name}: {self.my_item.last_update}') MyFirstRule() # hide diff --git a/_doc/interface_openhab.rst b/_doc/interface_openhab.rst index c0621d38..79d05819 100644 --- a/_doc/interface_openhab.rst +++ b/_doc/interface_openhab.rst @@ -18,6 +18,7 @@ Function parameters :imported-members: +.. _OPENHAB_ITEM_TYPES: Openhab item types ------------------------------ @@ -37,6 +38,7 @@ Example: HABApp.core.Items.set_item(ContactItem('MyContact', initial_value='OPEN')) HABApp.core.Items.set_item(SwitchItem('MySwitch', initial_value='OFF')) # hide + from HABApp.openhab.items import ContactItem, SwitchItem my_contact = ContactItem.get_item('MyContact') if my_contact.is_open(): @@ -225,6 +227,8 @@ and how to automatically link items to it. .. tip:: Integer values can be specified either as integer (``20``) or hex (``0x14``) +The entries ``thing config``, ``create items`` and ``channels`` are optional and can be combined as desired. + .. code-block:: yaml @@ -236,7 +240,8 @@ and how to automatically link items to it. filter: thing_type: zwave:philio_pst02a_00_000 - # Set this configuration for all things. + # Set this configuration every matching thing. HABApp will automatically only + # change the values which are not already correct. # Here it is the z-wave parameters which are responsible for the device behaviour thing config: 4: 99 # Light Threshold diff --git a/readme.md b/readme.md index fd6d638b..d92f6e96 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,13 @@ [![Build Status](https://travis-ci.org/spacemanspiff2007/HABApp.svg?branch=master)](https://travis-ci.org/spacemanspiff2007/HABApp) [![Documentation Status](https://readthedocs.org/projects/habapp/badge/?version=latest)](https://habapp.readthedocs.io/en/latest/?badge=latest) [![Updates](https://pyup.io/repos/github/spacemanspiff2007/HABApp/shield.svg)](https://pyup.io/repos/github/spacemanspiff2007/HABApp/) +![PyPI - Python Version](https://img.shields.io/pypi/pyversions/habapp) + +![PyPI](https://img.shields.io/pypi/v/HABapp) +[![Downloads](https://pepy.tech/badge/habapp/month)](https://pepy.tech/project/habapp/month) +![Docker Image Version (latest by date)](https://img.shields.io/docker/v/spacemanspiff2007/habapp?label=docker) +![Docker Pulls](https://img.shields.io/docker/pulls/spacemanspiff2007/habapp) + _Easy automation with MQTT and/or openHAB_ @@ -92,4 +99,4 @@ class MyOpenhabRule(HABApp.Rule): self.oh.post_update('TestItemUpdate', 123) MyOpenhabRule() -``` \ No newline at end of file +``` diff --git a/tests/test_core/test_logger.py b/tests/test_core/test_logger.py index bcdec5b5..ad9d0bcd 100644 --- a/tests/test_core/test_logger.py +++ b/tests/test_core/test_logger.py @@ -12,6 +12,11 @@ def test_exception_multiline(): assert HABAppLogger(None).add_exception(e).lines == ['Line1', 'Line2', 'Line3'] +def test_exception_traceback(): + e = Exception('Line1\nLine2\nLine3') + assert HABAppLogger(None).add_exception(e, add_traceback=True).lines == ['Exception: Line1', 'Line2', 'Line3'] + + def test_bool(): for cls in (HABAppError, HABAppInfo, HABAppWarning): i = cls(getLogger('test')).add('') diff --git a/tests/test_rule/test_rule_params.py b/tests/test_rule/test_rule_params.py index 7a15383a..997fbedd 100644 --- a/tests/test_rule/test_rule_params.py +++ b/tests/test_rule/test_rule_params.py @@ -66,6 +66,22 @@ def test_float_operators(params): assert p > 4 +def test_arithmetic(params): + Parameters.set_parameter_file('file', {'key': 1}) + p = Parameter('file', 'key') + + assert int(p) == 1 + assert p + 1 == 2 + assert p - 1 == 0 + assert p * 3 == 3 + assert p / 2 == 0.5 + assert p // 2 == 0 + assert p << 1 == 2 + assert p >> 1 == 0 + assert p | 2 == 3 + assert p & 2 == 0 + + def test_simple_key_creation(params): Parameter('file', 'key')