Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic restart of HABApp when ValueError #469

Open
UrsusS opened this issue Dec 16, 2024 · 2 comments
Open

Automatic restart of HABApp when ValueError #469

UrsusS opened this issue Dec 16, 2024 · 2 comments

Comments

@UrsusS
Copy link

UrsusS commented Dec 16, 2024

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 = "s@gmx.de"
    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': 's@gmx.de', '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': 's@gmx.de', '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': 's@gmx.de', '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': 's@gmx.de', '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

@spacemanspiff2007
Copy link
Owner

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?

@UrsusS
Copy link
Author

UrsusS commented Dec 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants