I tried this simple test and got an assertion error, the item exists on openhab. I have at the moment a read-only connection to openhab.
Switch ivetaAtHome "Iveta is at Home" (gAnyAtHome)
Any idea what I am doing wrong?
import logging
from HABApp.core.items import Item
log = logging.getLogger('MyRule')
atHome = Item.get_item('ivetaAtHome')
log.info("Iveta at Home: {}".format(atHome))
[2023-07-30 15:03:21,651] [ HABApp.Rules] ERROR | File "/usr/local/lib/python3.10/site-packages/HABApp/core/items/base_item.py", line 32 in get_item
[2023-07-30 15:03:21,651] [ HABApp.Rules] ERROR | --------------------------------------------------------------------------------
[2023-07-30 15:03:21,651] [ HABApp.Rules] ERROR | 24 | @classmethod
[2023-07-30 15:03:21,651] [ HABApp.Rules] ERROR | 25 | def get_item(cls, name: str):
[2023-07-30 15:03:21,652] [ HABApp.Rules] ERROR | 26 | """Returns an already existing item. If it does not exist or has a different item type an exception will occur.
[2023-07-30 15:03:21,652] [ HABApp.Rules] ERROR | 27 |
[2023-07-30 15:03:21,652] [ HABApp.Rules] ERROR | 28 | :param name: Name of the item
[2023-07-30 15:03:21,652] [ HABApp.Rules] ERROR | 29 | """
[2023-07-30 15:03:21,652] [ HABApp.Rules] ERROR | 30 | assert isinstance(name, str), type(name)
[2023-07-30 15:03:21,653] [ HABApp.Rules] ERROR | 31 | item = get_item(name)
[2023-07-30 15:03:21,653] [ HABApp.Rules] ERROR | --> 32 | assert isinstance(item, cls), f'{cls} != {type(item)}'
[2023-07-30 15:03:21,653] [ HABApp.Rules] ERROR | 33 | return item
[2023-07-30 15:03:21,654] [ HABApp.Rules] ERROR | ------------------------------------------------------------
[2023-07-30 15:03:21,654] [ HABApp.Rules] ERROR | cls = <class 'HABApp.core.items.item.Item'>
[2023-07-30 15:03:21,654] [ HABApp.Rules] ERROR | type(item) = <class 'HABApp.openhab.items.switch_item.SwitchItem'>
[2023-07-30 15:03:21,654] [ HABApp.Rules] ERROR | item = <SwitchItem name: ivetaAtHome, value: None, last_change: 2023-07-29T22:35:54.849306, last_update: 2023-07-29T22:35:54.849306>
[2023-07-30 15:03:21,654] [ HABApp.Rules] ERROR | name = 'ivetaAtHome'
[2023-07-30 15:03:21,654] [ HABApp.Rules] ERROR | ------------------------------------------------------------
[2023-07-30 15:03:21,654] [ HABApp.Rules] ERROR |
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | --------------------------------------------------------------------------------
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | Traceback (most recent call last):
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | File "/usr/local/lib/python3.10/site-packages/HABApp/rule_manager/rule_file.py", line 78, in load
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | self.create_rules(created_rules)
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | File "/usr/local/lib/python3.10/site-packages/HABApp/rule_manager/rule_file.py", line 68, in create_rules
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | runpy.run_path(str(self.path), run_name=str(self.path), init_globals=rule_hook.in_dict())
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | File "/usr/local/lib/python3.10/runpy.py", line 289, in run_path
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | return _run_module_code(code, init_globals, run_name,
[2023-07-30 15:03:21,655] [ HABApp.Rules] ERROR | File "/usr/local/lib/python3.10/runpy.py", line 96, in _run_module_code
[2023-07-30 15:03:21,656] [ HABApp.Rules] ERROR | _run_code(code, mod_globals, init_globals,
[2023-07-30 15:03:21,656] [ HABApp.Rules] ERROR | File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
[2023-07-30 15:03:21,656] [ HABApp.Rules] ERROR | exec(code, run_globals)
[2023-07-30 15:03:21,656] [ HABApp.Rules] ERROR | File "/habapp/config/rules/tests/test.py", line 8, in test.py
[2023-07-30 15:03:21,656] [ HABApp.Rules] ERROR | my_item = Item.get_item('ivetaAtHome') # This will raise an exception if the item is not found
[2023-07-30 15:03:21,656] [ HABApp.Rules] ERROR | File "/usr/local/lib/python3.10/site-packages/HABApp/core/items/base_item.py", line 32, in get_item
[2023-07-30 15:03:21,657] [ HABApp.Rules] ERROR | assert isinstance(item, cls), f'{cls} != {type(item)}'
[2023-07-30 15:03:21,658] [ HABApp.Rules] ERROR | AssertionError: <class 'HABApp.core.items.item.Item'> != <class 'HABApp.openhab.items.switch_item.SwitchItem'>
[2023-07-30 15:03:21,660] [ HABApp.Rules] WARNING | Failed to load /habapp/config/rules/tests/test.py!