Closed TheGroundZero closed 5 months ago
Hi @TheGroundZero,
interesting... The button calls the service function in my code. Does this happen everytime? Could you enable the debug log, this would help to check if the connection is closed already. (you can send it to mb.dev.issue156@nulsch.de )
So far I only saw it occur once, with both buttons.
So I pressed "start" -> error. Then pressed "stop" -> error. Then I fiddled around a little and tried again, and I don't think I got an error that time round.
I propose that we monitor this. I got this multiple times in my dev environments in the context of short network interruptions. Therefore the component has some fallback code to recreate the websocket connection already.
Looks like I have found the problem. A solution will be part of the release v0.10... in the next few days/weeks...
Got the same error today again.
I noticed car_charging_active and max_state_of_charge (and probably all the rest as well) didn't update. I wanted to force a refresh by changing the max_state_of_charge via the battery_max_soc_configure service.
I have an input_number with a range 50-100 and moving it, triggers and automation that calls the service. After doing so, I got the following error in the logs:
Logger: homeassistant.components.automation.car_battery_target
Source: components/automation/__init__.py:666
Integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 15:05:47 (1 occurrences)
Last logged: 15:05:47
While executing automation automation.car_battery_target
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 666, in async_trigger
return await self.action_script.async_run(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1600, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 435, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 487, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 512, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 943, in _async_choose_step
await self._async_run_script(script)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1100, in _async_run_script
result = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1600, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 435, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 487, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 512, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 723, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mbapi2020/services.py", line 146, in battery_max_soc_configure
await domain[_get_config_entryid(call.data.get(CONF_VIN))].client.battery_max_soc_configure(
File "/config/custom_components/mbapi2020/client.py", line 716, in battery_max_soc_configure
await self.websocket.call(message.SerializeToString())
File "/config/custom_components/mbapi2020/websocket.py", line 223, in call
await self._connection.send_bytes(message)
File "/usr/local/lib/python3.12/site-packages/aiohttp/client_ws.py", line 170, in send_bytes
await self._writer.send(data, binary=True, compress=compress)
File "/usr/local/lib/python3.12/site-packages/aiohttp/http_websocket.py", line 727, in send
await self._send_frame(message, WSMsgType.BINARY, compress)
File "/usr/local/lib/python3.12/site-packages/aiohttp/http_websocket.py", line 675, in _send_frame
self._write(header + mask + message)
File "/usr/local/lib/python3.12/site-packages/aiohttp/http_websocket.py", line 702, in _write
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
My logs also shows a few of these:
Logger: homeassistant
Source: custom_components/mbapi2020/client.py:374
Integration: MercedesME 2020 ([documentation](https://github.com/ReneNulschDE/mbapi2020), [issues](https://github.com/ReneNulschDE/mbapi2020/issues))
First occurred: 4 March 2024 at 14:04:14 (3 occurrences)
Last logged: 14:25:12
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/mbapi2020/websocket.py", line 212, in _recv
ack_message = self._on_data_received(message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mbapi2020/client.py", line 128, in on_data
self._process_vep_updates(data)
File "/config/custom_components/mbapi2020/client.py", line 436, in _process_vep_updates
self._build_car(current_car, update_mode=True)
File "/config/custom_components/mbapi2020/client.py", line 272, in _build_car
car.electric = self._get_car_values(
^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mbapi2020/client.py", line 374, in _get_car_values
display_value=curr_display_value,
^^^^^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'curr_display_value' where it is not associated with a value
cannot access local variable 'curr_display_value' --> this one I had this morning too and it is fixed in the master branch.
Let me check the other one again. On what system (HW, SW) is your HA running? And what is your current version of the MBAPI component?
On what system (HW, SW) is your HA running? And what is your current version of the MBAPI component?
Fedora CoreOS with HA Container managed via Podman. Core 2024.2.5 v0.11.1 of MBAPI
Is this a fast machine? I'm currently analyzing a different topic but the result could be the same. Looks like that sometimes the MB servers sending so many messages and my code is not fast enough to handle all this incoming traffic... Just setting up a slow PI3 to test this...
It's a Beelink Mini S (Intel N5095) I do sporadically have some network issues, but afaik it only interferes with my WiFi.
I have reworked the connection logic to the MB servers. The data receiver and data processor are decoupled now and this should prevent "shadow"/"phantom" connections. Is part of v0.11.2-beta.4
Also part of v0.12.0 - Please recheck. I'll close it for now. feel free to reopen it again.
Pressing the Preclimate start/stop buttons, I get an error popping up
Cannot write to closing transport
. The service call does seem to work (at least the 2nd time I tried it).HA logs show:
PS: any plans on turning this into a switch instead of 2 buttons? Would help me get rid of these templates :)