HABApp - failing at the tutorial

Hi,

I have somehow managed to fail the basic example in the HABApp docs. When I create the test.py file I get the following error in the logs:

[2021-05-05 09:39:52,000] [             HABApp.Rules]    ERROR | Error "'MyFirstRule' object has no attribute 'run'" in load:
[2021-05-05 09:39:52,000] [             HABApp.Rules]    ERROR | Could not load /etc/openhab2/habapp/rules/test.py!
[2021-05-05 09:39:52,001] [             HABApp.Rules]    ERROR | File "/home/dan/.local/lib/python3.6/site-packages/HABApp/rule_manager/rule_file.py", line 79, in load
[2021-05-05 09:39:52,001] [             HABApp.Rules]    ERROR |     self.create_rules(created_rules)
[2021-05-05 09:39:52,001] [             HABApp.Rules]    ERROR | File "/home/dan/.local/lib/python3.6/site-packages/HABApp/rule_manager/rule_file.py", line 68, in create_rules
[2021-05-05 09:39:52,001] [             HABApp.Rules]    ERROR |     '__HABAPP__RULES': created_rules,
[2021-05-05 09:39:52,001] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.6/runpy.py", line 263, in run_path
[2021-05-05 09:39:52,001] [             HABApp.Rules]    ERROR |     pkg_name=pkg_name, script_name=fname)
[2021-05-05 09:39:52,002] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
[2021-05-05 09:39:52,002] [             HABApp.Rules]    ERROR |     mod_name, mod_spec, pkg_name, script_name)
[2021-05-05 09:39:52,002] [             HABApp.Rules]    ERROR | File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
[2021-05-05 09:39:52,002] [             HABApp.Rules]    ERROR |     exec(code, run_globals)
[2021-05-05 09:39:52,002] [             HABApp.Rules]    ERROR | File "/etc/openhab2/habapp/rules/test.py", line 16, in test.py
[2021-05-05 09:39:52,003] [             HABApp.Rules]    ERROR |     12       def say_something(self):
[2021-05-05 09:39:52,003] [             HABApp.Rules]    ERROR |     13           print('That was easy!')
[2021-05-05 09:39:52,003] [             HABApp.Rules]    ERROR |     14   
[2021-05-05 09:39:52,003] [             HABApp.Rules]    ERROR |     15   # Rules
[2021-05-05 09:39:52,003] [             HABApp.Rules]    ERROR | --> 16   MyFirstRule() 
[2021-05-05 09:39:52,003] [             HABApp.Rules]    ERROR |     ..................................................
[2021-05-05 09:39:52,003] [             HABApp.Rules]    ERROR |      MyFirstRule = <class '/etc/openhab2/habapp/rules/test.py.MyFirstRule'>
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR |     ..................................................
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR | 
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR | File "/etc/openhab2/habapp/rules/test.py", line 10, in __init__
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR |     5    def __init__(self):
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR |     6        super().__init__()
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR |     7    
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR |     8        # Use run.at to schedule things directly after instantiation,
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR |     9        # don't do blocking things in __init__
[2021-05-05 09:39:52,004] [             HABApp.Rules]    ERROR | --> 10       self.run.soon(self.say_something)
[2021-05-05 09:39:52,005] [             HABApp.Rules]    ERROR |     ..................................................
[2021-05-05 09:39:52,005] [             HABApp.Rules]    ERROR |      self = </etc/openhab2/habapp/rules/test.py.MyFirstRule object at 0x7f0c14044a90>
[2021-05-05 09:39:52,005] [             HABApp.Rules]    ERROR |      self.run.soon = # AttributeError
[2021-05-05 09:39:52,005] [             HABApp.Rules]    ERROR |           self = </etc/openhab2/habapp/rules/test.py.MyFirstRule object at 0x7f0c14044a90>
[2021-05-05 09:39:52,005] [             HABApp.Rules]    ERROR |      self.say_something = <method 'MyFirstRule.say_something' of </etc/openhab2/habapp/rules/test.py.MyFirstRule object at 0x7f0c14044a90> test.py:12>
[2021-05-05 09:39:52,005] [             HABApp.Rules]    ERROR |     ..................................................
[2021-05-05 09:39:52,005] [             HABApp.Rules]    ERROR | 
[2021-05-05 09:39:52,005] [             HABApp.Rules]    ERROR | AttributeError: 'MyFirstRule' object has no attribute 'run'
[2021-05-05 09:39:52,005] [             HABApp.Rules]  WARNING | Failed to load /etc/openhab2/habapp/rules/test.py!

Would be fantastic if anyone can see what I’m doing wrong…

You are using an older version (probably 0.20.X) but are trying the new examples for >= 0.30.
The newest version requires python 3.7, that’s why you probably got an old(er) one.
You can switch the version of the docs in the lower left if you don’t feel like upgrading your python version.
grafik

1 Like

brilliant, thank you - have updated python and will continue playing!

2 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.