HABApp icon indicating copy to clipboard operation
HABApp copied to clipboard

Automatic restart of HABApp when ValueError

Open UrsusS opened this issue 11 months ago • 2 comments

This small piece of code causes HABApp to restart when the casting str() is missing in line HideItem.oh_send_command(Message)

def HideMessage(self) -> None:

    Subject: str = "Fenster xy ist noch geöffnet"
    Messagebody: str = "Wer schließt es?"
    Receiver: str = "[email protected]"
    ReferenceID: str = "10"

    Message: BufferMessageType = {
        "Receiver": Receiver,
        "Subject": "",
        "Messagebody": "",
        "ReferenceID": ReferenceID,
        "Timestamp": "",
    }

    HideItem: StringItem = StringItem.get_item("str_Notification_HideMessage")
    # HideItem.oh_send_command(str(Message))
    HideItem.oh_send_command(Message)

    return
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] - Error  in Outgoing queue worker:
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/openhab/connection/plugins/out.py", line 87 in queue_worker
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] - --------------------------------------------------------------------------------
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -      71 | async def queue_worker(self) -> None:
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -       (...)
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -      83 |                 if not isinstance(item, str):
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -      84 |                     item = item._name
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -      86 |                 if not isinstance(state, str):
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] - -->  87 |                     state = to_str(state, scientific_floats=scientific_floats)
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -      89 |                 if is_cmd:
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -    ------------------------------------------------------------
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -      self = <HABApp.openhab.connection.plugins.out.OutgoingCommandsPlugin object at 0x7f3eb09edb50>
2024-12-16 19:48:25.205 [ERROR] [HABApp                     ] -      self.plugin_connection = <HABApp.openhab.connection.connection.OpenhabConnection object at 0x7f3eb0965450>
2024-12-16 19:48:25.206 [ERROR] [HABApp                     ] -      self.plugin_connection.context = OpenhabContext(version=(4, 2, 3), is_oh3=False, is_oh41=True, waited_for_openhab=False, created_items={'num_Mower_Mowing_Duration': (<NumberItem name: 
.....
:07.660374901+01:00), last_update: InstantView(2024-12-16T19:42:07.660374901+01:00)>, InstantView(2024-12-16T19:42:07.660374901+01:00)), 'network:pingdevice:LaptopLAN': (<Thing name: network:pingdevice:LaptopLAN, last_change: InstantView(2024-12-16T19:42:07.660385577+01:00), last_update: InstantView(2024-12-16T19:42:07.660385577+01:00)>, InstantView(2024-12-16T19:42:07.660385577+01:00))}, session=<aiohttp.client.ClientSession object at 0x7f3eaf5ed1d0>, session_options={})
2024-12-16 19:48:25.206 [ERROR] [HABApp                     ] -      self.plugin_connection.context.is_oh41 = True
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      self.queue = <Queue at 0x7f3eb09edb90 maxsize=0 tasks=555>
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      e = ValueError()
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      is_cmd = True
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      item = 'str_Notification_HideMessage'
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      item, state, is_cmd = ('str_Notification_HideMessage', {'Receiver': '[email protected]', 'Subject': '', 'Messagebody': '', 'ReferenceID': '10', 'Timestamp': ''}, True)
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      queue = <Queue at 0x7f3eb09edb90 maxsize=0 tasks=555>
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      scientific_floats = True
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      state = {'Receiver': '[email protected]', 'Subject': '', 'Messagebody': '', 'ReferenceID': '10', 'Timestamp': ''}
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      to_str = <function convert_to_oh_type at 0x7f3eb09914e0>
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -    ------------------------------------------------------------
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] - 
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/openhab/connection/handler/helper.py", line 52 in convert_to_oh_type
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] - --------------------------------------------------------------------------------
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      12 | def convert_to_oh_type(obj: Any, scientific_floats: bool = False) -> str:
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -       (...)
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      47 |         return ','.join(convert_to_oh_type(x, scientific_floats=scientific_floats) for x in obj)
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      49 |     if isinstance(obj, BaseModel):
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      50 |         return obj.model_dump_json()
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] - -->  52 |     raise ValueError()
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -    ------------------------------------------------------------
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      BaseModel = <class 'pydantic.main.BaseModel'>
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      obj = {'Receiver': '[email protected]', 'Subject': '', 'Messagebody': '', 'ReferenceID': '10', 'Timestamp': ''}
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      scientific_floats = True
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -      str(obj) = "{'Receiver': '[email protected]', 'Subject': '', 'Messagebody': '', 'ReferenceID': '10', 'Timestamp': ''}"
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -    ------------------------------------------------------------
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] - 
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] - --------------------------------------------------------------------------------
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] - Traceback (most recent call last):
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -   File "/opt/habapp/lib/python3.11/site-packages/HABApp/openhab/connection/plugins/out.py", line 87, in queue_worker
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -     state = to_str(state, scientific_floats=scientific_floats)
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-12-16 19:48:25.207 [ERROR] [HABApp                     ] -   File "/opt/habapp/lib/python3.11/site-packages/HABApp/openhab/connection/handler/helper.py", line 52, in convert_to_oh_type
2024-12-16 19:48:25.208 [ERROR] [HABApp                     ] -     raise ValueError()
2024-12-16 19:48:25.208 [ERROR] [HABApp                     ] - ValueError
2024-12-16 19:48:26.222 [INFO ] [HABApp.connection.openhab  ] - Connected to OpenHAB version 4.2.3 (Release Build)
2024-12-16 19:48:26.306 [INFO ] [HABApp.openhab.items       ] - Updated 979 Items
2024-12-16 19:48:26.327 [INFO ] [HABApp.openhab.items       ] - Updated 110 Things
2024-12-16 19:48:26.508 [INFO ] [HABApp.openhab.transform   ] - Transformations:
2024-12-16 19:48:26.508 [INFO ] [HABApp.openhab.transform   ] -   Map: Z2M_MAP.map, de.map, en.map, heating_loopmode.map, ups.map, weather_codes.map, weather_precipitation.map

UrsusS avatar Dec 16 '24 20:12 UrsusS

Hm - it fails in the outgoing queue and that's why there is a reconnect. A dictionary is something that can not mapped to a native openhab type. What would you expect?

spacemanspiff2007 avatar Dec 17 '24 13:12 spacemanspiff2007

Well, I have expected a ValueError or something similar.

What happened looked for me like a restart of HABApp, with newly opened log files. This something I haven't expected.

UrsusS avatar Dec 18 '24 17:12 UrsusS

The current version of HABApp fails fast, there should be an error in the rule and no more reconnect. Thanks for inspiring this behavior and feel free to reopen if it happens again with the new version.

spacemanspiff2007 avatar May 27 '25 10:05 spacemanspiff2007