HABApp Mocking openHAB items not working anymore

Having done a lot of python rules scripting a year ago, I think it’s time to to it a little more serious on openHAB4.
I’d like to implement my rules on a desktop linux machine before integrating them inito a productive openHAB-server. Thus I want to unit-test my rules first. I already did some trials about this a year ago, and it worked so far.

But now, i updated the HABapp package (to 23.09.2) and started from scratch, using the example from the docs:

#!/usr/bin/env python

# -*- coding: ISO-8859-1 -*-

import HABApp
from HABApp.openhab.items import SwitchItem

item = SwitchItem('my_switch', 'ON')

This bit of code taken from the docs throws following event:

Ausnahme: ProxyObjHasNotBeenReplacedError
<ConstProxyObj ItemRegistry> has not been replaced on startup!
  File "/home/<....>/test2.py", line 9, in <module>
HABApp.core.errors.ProxyObjHasNotBeenReplacedError: <ConstProxyObj ItemRegistry> has not been replaced on startup!

So, I have no clue, what to do to fix this

There were some fundamental changes how things work leading to the issue you are observing.

There are some github repositories that implemented a proof of concept how to write unit tests.
If you search you should be able to find them.
However imoh (!) they are still somewhat lacking and I (!) don’t consider them production ready.
Making it possible to easily test rules is still on my backlog but it’ll be at least middle of next year before I’ve got something working.

So either you can make these implementations work or you’ll have to wait.
Currently I don’t write any unit tests and the combination of type hints and an IDE keeps my rules most of the time :wink: error free.

1 Like

No Problem. My hope was to combine the unit tests with some simulation. So I’ll concentrate on simulation so far, which helps me to validate my rules without having to wait for the sensor values :sweat_smile:

Thank you for this great plug-in, I really enjoy it :grinning: :+1: