HASwitchPlate / openHASP-custom-component

Home Assistant custom component for openHASP
https://www.openhasp.com
MIT License
49 stars 9 forks source link

Error in new HA 2021.8.1 #66

Closed nagyrobi closed 2 years ago

nagyrobi commented 2 years ago

Version of the custom_component

0.6 - current

Configuration

not relevant

Describe the bug

Since release of HA 2021.8.1, log gets filled continuously with the errors below.

Debug log

2021-08-05 12:59:17 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/util/logging.py", line 140, in async_wrapper
    await async_func(*args)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/discovery.py", line 287, in async_integration_message_received
    result = await hass.config_entries.flow.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 153, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 179, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 260, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/openhasp/config_flow.py", line 85, in async_step_mqtt
    _discovered = json.loads(discovery_info.payload)
AttributeError: 'dict' object has no attribute 'payload'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/util/logging.py", line 142, in async_wrapper
    log_exception(format_err, *args)
  File "/usr/src/homeassistant/homeassistant/util/logging.py", line 104, in log_exception
    friendly_msg = format_err(*args)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 373, in <lambda>
    f"Exception in {msg_callback.__name__} when handling msg on "
AttributeError: 'functools.partial' object has no attribute '__name__'
nagyrobi commented 2 years ago

Very funny... Discovery info: {'topic': 'hasp/discovery', 'payload': '{"node":"plate_4","mdl":"Lanbon L8","mf":"openHASP","hwid":"xxxxxxxxxxxxx","pages":12,"sw":"0.6.2","input":{},"power":[],"light":[12,14,27],"dim":[]}', 'qos': 0, 'retain': 0, 'subscribed_topic': 'hasp/discovery', 'timestamp': datetime.datetime(2021, 8, 5, 12, 48, 30, 819614, tzinfo=datetime.timezone.utc)}

nagyrobi commented 2 years ago

https://jsonlint.com/ , https://jsonformatter.org/ say this is not valid json.

fvanroie commented 2 years ago

openHASP sends this discovery payload:

{
    "node": "plate_4",
    "mdl": "Lanbon L8",
    "mf": "openHASP",
    "hwid": "xxxxxxxxxxxxx",
    "pages": 12,
    "sw": "0.6.2",
    "input": {},
    "power": [],
    "light": [12, 14, 27],
    "dim": []
}

That is a valid json object. HA makes it into a larger JSON object, adding topic, payload and timestamp keys that is not valid anymore...

nagyrobi commented 2 years ago

Yes, single quotes around '{}' invalidates it.

nagyrobi commented 2 years ago

Thank you: https://github.com/HASwitchPlate/openHASP-custom-component/commit/eeb2508ee7f4a76eb15442f4c14174591f8da629