HABApp 0.20

Good news everyone!

I just released HABApp 0.20.0!

This release contains new features and some bug fixes and documentation improvements.


EventFilter

It is now possible to filter on any event value when listening to an event.
For the most common events I have created convenience filters that provide type hints.
E.g.

  • ValueUpdateEventFilter and ValueChangeEventFilter
  • MqttValueUpdateEventFilter and MqttValueChangeEventFilter
  • ItemStateEventFilter and ItemStateChangedEventFilter

Example:

from HABApp import Rule
from HABApp.core.events import EventFilter, ValueUpdateEventFilter, ValueUpdateEvent
from HABApp.core.items import Item

class MyRule(Rule):
    def __init__(self):
        super().__init__()
        my_item = Item.get_item('MyItem')

        # This will only call the callback for ValueUpdateEvents where the value==my_value
        my_item.listen_event(self.on_val_my_value, ValueUpdateEventFilter(value='my_value'))

        # This is the same as above but with the generic filter
        my_item.listen_event(self.on_val_my_value, EventFilter(ValueUpdateEvent, value='my_value'))

    def on_val_my_value(self, event: ValueUpdateEvent):
        assert isinstance(event, ValueUpdateEvent), type(event)

MyRule()

Benchmark

Since I have been trying to get a fix for the rest api performance issue it was necessary to run some benchmarks. Thus I added ‘-b’ or ‘–benchmark’ as a cmd argument which can be used to bench the current configuration.

+------------------------------------------------------------------------------+
|                                    HABApp                                    |
+------------------------------------------------------------------------------+

Bench events .. done!

               |  dur   | per sec | median |  min   |  max   |  mean 
      rtt idle | 5.922s |   6.22k |  0.0us |  0.0us | 2.00ms | 0.16ms
async rtt idle | 5.998s | 922.088 | 1.00ms | 1.00ms | 5.00ms | 1.08ms

+------------------------------------------------------------------------------+
|                                     MQTT                                     |
+------------------------------------------------------------------------------+

Bench events .. done!

               |  dur   | per sec | median |  min   |  max   |  mean 
      rtt idle | 5.949s |   2.22k |  0.0us |  0.0us | 2.00ms | 0.45ms
async rtt idle | 6.005s | 736.178 | 1.00ms | 1.00ms | 11.0ms | 1.36ms

+------------------------------------------------------------------------------+
|                                   openHAB                                    |
+------------------------------------------------------------------------------+

Bench item operations ... done!

            |  dur   | per sec | median |  min   |  max   |  mean 
create item | 2.386s | 125.726 | 7.00ms | 6.00ms | 42.0ms | 7.95ms
update item | 2.338s | 128.307 | 7.00ms | 6.00ms | 29.0ms | 7.79ms
delete item | 1.699s | 176.564 | 5.00ms | 5.00ms | 17.0ms | 5.66ms

Bench item state update .... done!

                      |  dur   | per sec | median |  min   |  max   |  mean 
             rtt idle | 4.996s | 149.111 | 7.00ms | 6.00ms | 13.0ms | 6.71ms
       async rtt idle | 4.999s | 129.418 | 8.00ms | 7.00ms | 15.0ms | 7.73ms
      rtt load (+10x) | 5.048s |  18.422 | 54.0ms | 43.0ms | 72.0ms | 54.3ms
async rtt load (+10x) | 5.074s |  12.613 | 79.0ms | 68.0ms | 90.0ms | 79.3ms

Cleanup ... complete

Changelog

  • added Eventfilter
  • added ‘-b’ or ‘–benchmark’ as a cmd argument to run some benchmarks
  • *.items file for textual thing config gets properly appended (fixes #199)
  • Updated docs (closes #197 )
  • Reworked cmd args
  • Reworked shutdown
  • Duplicate items no longer show full traceback for textual thing config
  • Added logger for file events which can be enabled with HABApp.file_events
2 Likes

Good news everyone!

I just released HABApp 0.20.1!

This is a small release which brings a fix for the failing config reload and fronttail support on openhabian.

Changelog

  • Optimized AggregationItem
  • HABApp logs are now included by default in Frontail on openhabian
  • Fixed a bug where HABApp and logging config was not reloaded

Good news everyone!

I just released HABApp 0.20.2!

This is a small release which brings mostly better documentation and small fixes and dependency updates

Changelog

  • Added HABApp.util.functions with min/max
  • Reworked small parts of the file watcher
  • Doc improvements
  • Dependency updates
2 Likes

Just updated to latest version and getting the following in the log.

[2021-04-07 11:12:55,078] [    HABApp.openhab.plugin]    ERROR | Error "" in setup_plugins:

[2021-04-07 11:12:55,078] [    HABApp.openhab.plugin]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_logic/_plugin.py", line 72, in setup_plugins

[2021-04-07 11:12:55,079] [    HABApp.openhab.plugin]    ERROR |     69   def setup_plugins():

[2021-04-07 11:12:55,079] [    HABApp.openhab.plugin]    ERROR |     70       for p in PLUGINS:

[2021-04-07 11:12:55,079] [    HABApp.openhab.plugin]    ERROR |     71           with ExceptionToHABApp(log, ignore_exception=True):

[2021-04-07 11:12:55,079] [    HABApp.openhab.plugin]    ERROR | --> 72               p.setup()

[2021-04-07 11:12:55,080] [    HABApp.openhab.plugin]    ERROR |     73               log.debug(f'Setup {p.__class__.__name__} complete')

[2021-04-07 11:12:55,080] [    HABApp.openhab.plugin]    ERROR |     ..................................................

[2021-04-07 11:12:55,080] [    HABApp.openhab.plugin]    ERROR |      p = <HABApp.openhab.connection_logic.plugin_things.plugin_things.ManualThingConfig object at 0x7f990ba5ec70>

[2021-04-07 11:12:55,081] [    HABApp.openhab.plugin]    ERROR |      PLUGINS = [<HABApp.openhab.connection_logic.plugin_load_items.LoadAllOpenhabItems object at 0x7f990ba53310>, <HABApp.openhab.connection_logic.plugin_ping.PingOpenhab object at 0x7f990ba5e070>, <HABApp.openhab.connection_logic.plugin_thing_overview.ThingOverview object at 0x7f990ba5e490>, <HABApp.openhab.connection_logic.plugin_things.plugin_things.ManualThingConfig object at 0x7f990ba5ec70>, ]

[2021-04-07 11:12:55,081] [    HABApp.openhab.plugin]    ERROR |      ExceptionToHABApp = <class 'HABApp.core.wrapper.ExceptionToHABApp'>

[2021-04-07 11:12:55,081] [    HABApp.openhab.plugin]    ERROR |      log = <Logger HABApp.openhab.plugin (INFO)>

[2021-04-07 11:12:55,082] [    HABApp.openhab.plugin]    ERROR |      p.setup = <method 'ManualThingConfig.setup' of <HABApp.openhab.connection_logic.plugin_things.plugin_things.ManualThingConfig object at 0x7f990ba5ec70> plugin_things.py:30>

[2021-04-07 11:12:55,082] [    HABApp.openhab.plugin]    ERROR |      log.debug = <method 'Logger.debug' of <Logger HABApp.openhab.plugin (INFO)> __init__.py:1420>

[2021-04-07 11:12:55,082] [    HABApp.openhab.plugin]    ERROR |     ..................................................

[2021-04-07 11:12:55,082] [    HABApp.openhab.plugin]    ERROR | 

[2021-04-07 11:12:55,083] [    HABApp.openhab.plugin]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_logic/plugin_things/plugin_things.py", line 45, in setup

[2021-04-07 11:12:55,083] [    HABApp.openhab.plugin]    ERROR |     30   def setup(self):

[2021-04-07 11:12:55,083] [    HABApp.openhab.plugin]    ERROR |  (...)

[2021-04-07 11:12:55,084] [    HABApp.openhab.plugin]    ERROR |     41           )

[2021-04-07 11:12:55,084] [    HABApp.openhab.plugin]    ERROR |     42       )

[2021-04-07 11:12:55,084] [    HABApp.openhab.plugin]    ERROR |     43   

[2021-04-07 11:12:55,084] [    HABApp.openhab.plugin]    ERROR |     44       # watch folder

[2021-04-07 11:12:55,085] [    HABApp.openhab.plugin]    ERROR | --> 45       HABApp.core.files.watch_folder(HABApp.CONFIG.directories.config, '.yml', True)

[2021-04-07 11:12:55,085] [    HABApp.openhab.plugin]    ERROR |     ..................................................

[2021-04-07 11:12:55,085] [    HABApp.openhab.plugin]    ERROR |      self = <HABApp.openhab.connection_logic.plugin_things.plugin_things.ManualThingConfig object at 0x7f990ba5ec70>

[2021-04-07 11:12:55,086] [    HABApp.openhab.plugin]    ERROR |      HABApp.core.files.watch_folder = <function 'watch_folder' all.py:116>

[2021-04-07 11:12:55,086] [    HABApp.openhab.plugin]    ERROR |      HABApp.CONFIG.directories.config = PosixPath('/etc/openhab/habapp/conf')

[2021-04-07 11:12:55,086] [    HABApp.openhab.plugin]    ERROR |     ..................................................

[2021-04-07 11:12:55,086] [    HABApp.openhab.plugin]    ERROR | 

[2021-04-07 11:12:55,087] [    HABApp.openhab.plugin]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/core/files/all.py", line 118, in watch_folder

[2021-04-07 11:12:55,087] [    HABApp.openhab.plugin]    ERROR |     116  def watch_folder(folder: Path, file_ending: str, watch_subfolders: bool = False) -> AggregatingAsyncEventHandler:

[2021-04-07 11:12:55,087] [    HABApp.openhab.plugin]    ERROR |     117      handler = AggregatingAsyncEventHandler(folder, process, file_ending, watch_subfolders)

[2021-04-07 11:12:55,088] [    HABApp.openhab.plugin]    ERROR | --> 118      HABApp.core.files.watcher.add_folder_watch(handler)

[2021-04-07 11:12:55,088] [    HABApp.openhab.plugin]    ERROR |     119      return handler

[2021-04-07 11:12:55,088] [    HABApp.openhab.plugin]    ERROR |     ..................................................

[2021-04-07 11:12:55,089] [    HABApp.openhab.plugin]    ERROR |      folder = PosixPath('/etc/openhab/habapp/conf')

[2021-04-07 11:12:55,089] [    HABApp.openhab.plugin]    ERROR |      Path = <class 'pathlib.Path'>

[2021-04-07 11:12:55,089] [    HABApp.openhab.plugin]    ERROR |      file_ending = '.yml'

[2021-04-07 11:12:55,089] [    HABApp.openhab.plugin]    ERROR |      watch_subfolders = True

[2021-04-07 11:12:55,090] [    HABApp.openhab.plugin]    ERROR |      AggregatingAsyncEventHandler = <class 'HABApp.core.files.watcher.file_watcher.AggregatingAsyncEventHandler'>

[2021-04-07 11:12:55,090] [    HABApp.openhab.plugin]    ERROR |      handler = <HABApp.core.files.watcher.file_watcher.AggregatingAsyncEventHandler object at 0x7f990b9faac0>

[2021-04-07 11:12:55,090] [    HABApp.openhab.plugin]    ERROR |      HABApp.core.files.watcher.add_folder_watch = <function 'add_folder_watch' folder_watcher.py:32>

[2021-04-07 11:12:55,090] [    HABApp.openhab.plugin]    ERROR |     ..................................................

[2021-04-07 11:12:55,091] [    HABApp.openhab.plugin]    ERROR | 

[2021-04-07 11:12:55,091] [    HABApp.openhab.plugin]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/core/files/watcher/folder_watcher.py", line 39, in add_folder_watch

[2021-04-07 11:12:55,091] [    HABApp.openhab.plugin]    ERROR |     32   def add_folder_watch(handler: BaseWatcher):

[2021-04-07 11:12:55,092] [    HABApp.openhab.plugin]    ERROR |  (...)

[2021-04-07 11:12:55,092] [    HABApp.openhab.plugin]    ERROR |     35       assert isinstance(handler.folder, Path) and handler.folder.is_dir()

[2021-04-07 11:12:55,092] [    HABApp.openhab.plugin]    ERROR |     36   

[2021-04-07 11:12:55,092] [    HABApp.openhab.plugin]    ERROR |     37       with LOCK:

[2021-04-07 11:12:55,093] [    HABApp.openhab.plugin]    ERROR |     38           _folder = str(handler.folder)

[2021-04-07 11:12:55,093] [    HABApp.openhab.plugin]    ERROR | --> 39           assert _folder not in WATCHES

[2021-04-07 11:12:55,093] [    HABApp.openhab.plugin]    ERROR |     40   

[2021-04-07 11:12:55,093] [    HABApp.openhab.plugin]    ERROR |     ..................................................

[2021-04-07 11:12:55,094] [    HABApp.openhab.plugin]    ERROR |      handler = <HABApp.core.files.watcher.file_watcher.AggregatingAsyncEventHandler object at 0x7f990b9faac0>

[2021-04-07 11:12:55,094] [    HABApp.openhab.plugin]    ERROR |      BaseWatcher = <class 'HABApp.core.files.watcher.base_watcher.BaseWatcher'>

[2021-04-07 11:12:55,094] [    HABApp.openhab.plugin]    ERROR |      handler.folder = PosixPath('/etc/openhab/habapp/conf')

[2021-04-07 11:12:55,095] [    HABApp.openhab.plugin]    ERROR |      Path = <class 'pathlib.Path'>

[2021-04-07 11:12:55,095] [    HABApp.openhab.plugin]    ERROR |      handler.folder.is_dir = <method 'Path.is_dir' of /etc/openhab/habapp/conf pathlib.py:1417>

[2021-04-07 11:12:55,095] [    HABApp.openhab.plugin]    ERROR |      LOCK = <unlocked _thread.lock object at 0x7f990c22c570>

[2021-04-07 11:12:55,095] [    HABApp.openhab.plugin]    ERROR |      _folder = '/etc/openhab/habapp/conf'

[2021-04-07 11:12:55,096] [    HABApp.openhab.plugin]    ERROR |      WATCHES = {'/etc/openhab/habapp/conf': <ObservedWatch: path=/etc/openhab/habapp/conf, is_recursive=False>}

[2021-04-07 11:12:55,096] [    HABApp.openhab.plugin]    ERROR |     ..................................................

[2021-04-07 11:12:55,096] [    HABApp.openhab.plugin]    ERROR | 

[2021-04-07 11:12:55,097] [    HABApp.openhab.plugin]    ERROR | ---- (full traceback above) ----

[2021-04-07 11:12:55,097] [    HABApp.openhab.plugin]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_logic/_plugin.py", line 72, in setup_plugins

[2021-04-07 11:12:55,097] [    HABApp.openhab.plugin]    ERROR |     p.setup()

[2021-04-07 11:12:55,098] [    HABApp.openhab.plugin]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/openhab/connection_logic/plugin_things/plugin_things.py", line 45, in setup

[2021-04-07 11:12:55,098] [    HABApp.openhab.plugin]    ERROR |     HABApp.core.files.watch_folder(HABApp.CONFIG.directories.config, '.yml', True)

[2021-04-07 11:12:55,098] [    HABApp.openhab.plugin]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/core/files/all.py", line 118, in watch_folder

[2021-04-07 11:12:55,098] [    HABApp.openhab.plugin]    ERROR |     HABApp.core.files.watcher.add_folder_watch(handler)

[2021-04-07 11:12:55,099] [    HABApp.openhab.plugin]    ERROR | File "/opt/habapp/lib/python3.9/site-packages/HABApp/core/files/watcher/folder_watcher.py", line 39, in add_folder_watch

[2021-04-07 11:12:55,099] [    HABApp.openhab.plugin]    ERROR |     assert _folder not in WATCHES

[2021-04-07 11:12:55,099] [    HABApp.openhab.plugin]    ERROR | 

[2021-04-07 11:12:55,100] [    HABApp.openhab.plugin]    ERROR | AssertionError

Hmm, do you have the same folder configured twice in the HABApp config?

Hmm, No. Got the error first after updating to 0.20.2

directories:
  logging: /var/log/habapp  # Folder where the logs will be written to
  rules: /etc/openhab/habapp # Folder from which the rule files will be loaded
  param: /etc/openhab/habapp/param # Folder from which the parameter files will be loaded
  config: /etc/openhab/habapp/conf # Folder from which configuration files will be loaded
  lib: lib # Folder where additional libraries can be placed

Hmm, strange. Config looks good so far. I’ve created an issue - would you mind if we continue the discussion there? If you don’t have a github account we can continue here.
Is this issue reproducible (e.g. persists after restarts)?

We should continue at github.