remuslazar / homeassistant-carwings

Custom HomeAssistant Integration to access Nissan Connect EV Services
MIT License
20 stars 1 forks source link

Climate control not working #13

Closed letrouf closed 1 week ago

letrouf commented 1 month ago

System Health details

System Information

version core-2024.7.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.6.33-haos
arch aarch64
timezone Europe/Paris
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1399 Downloaded Repositories | 37 HACS Data | ok
Home Assistant Cloud logged_in | true -- | -- subscription_expiration | 27 juillet 2024 à 02:00 relayer_connected | true relayer_region | eu-central-1 remote_enabled | true remote_connected | true alexa_enabled | false google_enabled | true remote_server | eu-central-1-14.ui.nabu.casa certificate_status | ready instance_id | 2e63daec2c5345ed83b2d196eabafefd can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.4 -- | -- update_channel | stable supervisor_version | supervisor-2024.06.2 agent_version | 1.6.0 docker_version | 26.1.4 disk_total | 234.5 GB disk_used | 142.1 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | green supervisor_api | ok version_api | ok installed_addons | Mosquitto broker (6.4.1), Samba share (12.3.1), Node-RED (18.0.4), Terminal & SSH (9.14.0), File editor (5.8.0), Silicon Labs Flasher (0.2.3), Apache2 Minimal with MariaDB Client (2.8.3), Home Assistant Google Drive Backup (0.112.1), tiko / Mon Pilotage Elec (1.4.7), Zigbee2MQTT (1.39.0-1), Studio Code Server (5.15.0), openWakeWord (1.10.0), Advanced SSH & Web Terminal (18.0.0)
Dashboards dashboards | 4 -- | -- resources | 18 views | 17 mode | storage
Recorder oldest_recorder_run | 12 juillet 2024 à 20:06 -- | -- current_recorder_run | 20 juillet 2024 à 19:38 estimated_db_size | 260.09 MiB database_engine | sqlite database_version | 3.45.3
Xiaomi Miot Auto component_version | 0.7.19 -- | -- can_reach_server | ok can_reach_spec | ok logged_accounts | 1 total_devices | 2

Checklist

Describe the issue

All the entities work like a charm except for the climate control button. If I click on it, nothing happens in my car and the button becomes unavailable until I reload the integration. It worked with the previous Nissan Leaf integration though. My car is a 2018 leaf. I tried to provide as much info as I can, let me know if you need anything else. And thank you if you take some time to look into my issue.

John

Reproduction steps

  1. activate climate control button
  2. button becomes unavailable
  3. ...

Debug logs

2024-07-22 17:38:26.829 WARNING (MainThread) [homeassistant.helpers.entity] Entity switch.leaf1lejo_climate_control_2 (<class 'custom_components.nissan_carwings.switch.ClimateControlSwitch'>) is using self.async_update_ha_state(), without enabling force_refresh. Instead it should use self.async_write_ha_state(), please create a bug report at https://github.com/remuslazar/homeassistant-carwings/issues
2024-07-22 17:38:29.424 ERROR (MainThread) [pycarwings3.pycarwings3] carwings error -6004: NoRecordInDatabase
2024-07-22 17:38:29.424 ERROR (MainThread) [custom_components.nissan_carwings] Error fetching data - CarwingsError: 
2024-07-22 17:38:29.425 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281471606233776] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/nissan_carwings/api.py", line 234, in async_set_climate
    await response.get_start_climate_control_result(result_key)
  File "/usr/local/lib/python3.12/site-packages/pycarwings3/pycarwings3.py", line 331, in get_start_climate_control_result
    response = await self.session._request_with_retry(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pycarwings3/pycarwings3.py", line 135, in _request_with_retry
    ret = await self._request(endpoint, params)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pycarwings3/pycarwings3.py", line 217, in _request
    raise CarwingsError
pycarwings3.pycarwings3.CarwingsError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/nissan_carwings/switch.py", line 68, in async_turn_on
    await client.async_set_climate(switch_on=True)
  File "/config/custom_components/nissan_carwings/api.py", line 258, in async_set_climate
    raise NissanCarwingsApiClientError(
custom_components.nissan_carwings.api.NissanCarwingsApiClientError: Error fetching data

Diagnostics dump

No response

lootre commented 1 month ago

Hello,

Almost the same problem here, but the climate control is working even though the button turns "Unavailable" each time I press on it. After an integration reload I can see the state of the climate control again, start it or stop it. But then the button is unavailable again.

Here are the logs:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:241
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: July 22, 2024 at 15:52:19 (4 occurrences)
Last logged: 10:23:50

[139861665627968] Unexpected exception
[139862444408352] Unexpected exception
[139861224117952] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/nissan_carwings/api.py", line 234, in async_set_climate
    await response.get_start_climate_control_result(result_key)
  File "/usr/local/lib/python3.12/site-packages/pycarwings3/pycarwings3.py", line 331, in get_start_climate_control_result
    response = await self.session._request_with_retry(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pycarwings3/pycarwings3.py", line 135, in _request_with_retry
    ret = await self._request(endpoint, params)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pycarwings3/pycarwings3.py", line 217, in _request
    raise CarwingsError
pycarwings3.pycarwings3.CarwingsError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/nissan_carwings/switch.py", line 68, in async_turn_on
    await client.async_set_climate(switch_on=True)
  File "/config/custom_components/nissan_carwings/api.py", line 258, in async_set_climate
    raise NissanCarwingsApiClientError(
custom_components.nissan_carwings.api.NissanCarwingsApiClientError: Error fetching data - CarwingsError: 
remuslazar commented 1 month ago

@letrouf this works as intended: the button turns unavailable while the operation is in progress. And, because turning the AC on is a heavily async operation (can take some time, 5-10 minutes), the button will stick unavailable.

Because the operation cannot be cancelled anyway, updating the button "available" state reflects that. The button will be automatically enabled as soon as the car has acknowledged that the operation was successful (which will happen a couple of minutes after the AC has been actually turned on or off).

Could you please test that once again and just wait longer to see if the button state will be updated correctly?

lootre commented 1 month ago

@letrouf this works as intended: the button turns unavailable while the operation is in progress. And, because turning the AC on is a heavily async operation (can take some time, 5-10 minutes), the button will stick unavailable.

Because the operation cannot be cancelled anyway, updating the button "available" state reflects that. The button will be automatically enabled as soon as the car has acknowledged that the operation was successful (which will happen a couple of minutes after the AC has been actually turned on or off).

Could you please test that once again and just wait longer to see if the button state will be updated correctly?

If I may answer even though the question is not for me: the button stayed unavailable for several hours until I manually reloaded the integration, even though the climate control correctly started and stopped when the desired temperature was reached in the car.

The behavior you describe is exactly what happen with the "request update" button.

remuslazar commented 1 month ago

@lootre ok, thanks for the update here. I will take a look into that, it seems to be a bug then..

letrouf commented 1 month ago

Same for me. As this morning the button is still unavailable and the car never turned on AC. Usually when it does I have the notification from the Nissan app within one minute.

Le mar. 23 juil. 2024, 12:00, Remus Lazar @.***> a écrit :

@lootre https://github.com/lootre ok, thanks for the update here. I will take a look into that, it seems to be a bug then..

— Reply to this email directly, view it on GitHub https://github.com/remuslazar/homeassistant-carwings/issues/13#issuecomment-2244778162, or unsubscribe https://github.com/notifications/unsubscribe-auth/BC255AYJITMUHEEYRDBKVKTZNYSTLAVCNFSM6AAAAABLI4U3X6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBUG43TQMJWGI . You are receiving this because you were mentioned.Message ID: @.***>

letrouf commented 1 month ago

Hello there. Would you need me to do more testing ?

7w1z4rd commented 4 weeks ago

For me it turns on AC, but remains unavailable until I reboot HA.

JorenVandenBergh commented 3 weeks ago

I too experience this same issue: After turning on the A/C-switch, it becomes 'unavailable' immediately, it does turn on the A/C in the car however.

For the moment I've made this workaround using an automation, it automatically reloads the Nissan Carwings-integration 20 minutes after switching the A/C on. This 20 minutes ensures the A/C in the car has turned off again, because otherwise reloading the integration will result in the A/C-switch being 'on' instead of 'off'

Trigger: When Nissan Leaf Climate Control changes to Unavailable (Which happens right away after switching A/C on) Then do:

  1. Wait for 20 minutes
  2. Perform action 'Home Assistant Core Integration: Reload config entry' -> Fill in the field 'Config Entry ID' with the Entry ID of the integration. This Entry ID can be found in the file _core.configentries located in _config/.storage/core.configentries and search for 'Carwings'.
remuslazar commented 3 weeks ago

I will definitely take a deeper look at that, it seems that it's a bug in the integration. Currently being busy with other tasks, this could take some time, though.

letrouf commented 3 weeks ago

Thanks, no rush, your work is already amasing. If this can help, i've noticed an error when activating the climate control switch : "error fetching data Carwings error". Screenshot_20240813-134003

remuslazar commented 1 week ago

@letrouf @JorenVandenBergh could you please test if the current release fixes all issues here? I have reworked the whole ac logic to handle errors gracefully. Now also the switch should not become unavailable any more which was kind-of confusing anyway.

letrouf commented 1 week ago

Hi. Thanks for the update. Turns out, the AC works fine now but the switch stays unavailable after. I made an automation to reload integration the switch becomes unavailable to outpass this issue. Thank you again though

Capture d’écran 2024-08-26 110809

remuslazar commented 1 week ago

@letrouf are you sure that you're using the current version? should render 0.1.5 on the integration info page

letrouf commented 1 week ago

Indeed, even after updating yesterday the files it showed 0.1.4. I updated all the files again but after restarting I got a new error :

Enregistreur: homeassistant.util.loop Source: util/loop.py:77 S'est produit pour la première fois: 14:28:01 (1 occurrences) Dernier enregistrement: 14:28:01

Detected blocking call to import_module with args ('custom_components.nissan_carwings',) in /usr/src/homeassistant/homeassistant/loader.py, line 1067: ComponentProtocol, importlib.import_module(self.pkg_path) inside the event loop; This is causing stability issues. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component result = await _async_setup_component(hass, domain, config) File "/usr/src/homeassistant/homeassistant/setup.py", line 334, in _async_setup_component component = await integration.async_get_component() File "/usr/src/homeassistant/homeassistant/loader.py", line 1019, in async_get_component comp = self._get_component() File "/usr/src/homeassistant/homeassistant/loader.py", line 1067, in _get_component ComponentProtocol, importlib.import_module(self.pkg_path)

and :

Enregistreur: homeassistant.setup Source: setup.py:334 S'est produit pour la première fois: 14:28:01 (1 occurrences) Dernier enregistrement: 14:28:01

Setup failed for custom integration 'nissan_carwings': Unable to import component: Exception importing custom_components.nissan_carwings Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/loader.py", line 1067, in _get_component ComponentProtocol, importlib.import_module(self.pkg_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1331, in _find_and_load_unlocked File "", line 935, in _load_unlocked File "", line 995, in exec_module File "", line 488, in _call_with_frames_removed File "/config/custom_components/nissan_carwings/init.py", line 25, in from .coordinator import ( File "/config/custom_components/nissan_carwings/coordinator.py", line 111

homeassistant-carwings/custom_components/nissan_carwings/coordinator.py at master · remuslazar/homeassistant-carwings
                                                                                         ^

SyntaxError: invalid character '·' (U+00B7)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/loader.py", line 1007, in async_get_component comp = await self.hass.async_add_import_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1078, in _get_component raise ImportError(f"Exception importing {self.pkg_path}") from err ImportError: Exception importing custom_components.nissan_carwings

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/loader.py", line 1067, in _get_component ComponentProtocol, importlib.import_module(self.pkg_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1331, in _find_and_load_unlocked File "", line 935, in _load_unlocked File "", line 995, in exec_module File "", line 488, in _call_with_frames_removed File "/config/custom_components/nissan_carwings/init.py", line 25, in from .coordinator import ( File "/config/custom_components/nissan_carwings/coordinator.py", line 111

homeassistant-carwings/custom_components/nissan_carwings/coordinator.py at master · remuslazar/homeassistant-carwings
                                                                                         ^

SyntaxError: invalid character '·' (U+00B7)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/setup.py", line 334, in _async_setup_component component = await integration.async_get_component() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1027, in async_get_component self._component_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1019, in async_get_component comp = self._get_component() ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1078, in _get_component raise ImportError(f"Exception importing {self.pkg_path}") from err ImportError: Exception importing custom_components.nissan_carwings

Probably I did wrong something. I can't even delete the integration.

remuslazar commented 1 week ago

@letrouf I think you have messed up with the files, maybe downloaded the HTML GitHub page instead of the real script or something. You can download a ZIP archive for the current release from here: https://github.com/remuslazar/homeassistant-carwings/releases/tag/v0.1.5

letrouf commented 1 week ago

Ok thank you. I had downloaded an HTML file indeed. I am on 0.1.5 now. AC works fine and button behavior is normal (comes back to off when I got Nissan's app confirmation).

Thank you for your work.

remuslazar commented 1 week ago

Thanks for the update! The button should reflect the current state of the AC but there are some bugs I have already fixed in the master branch. I will test that and create a new release then.

lootre commented 1 week ago

Hey ! I also tested the new version and unfortunately, the remote climate control is not working at all anymore...! The button stays unavailable, even though I reloaded the integration and restarted Home Assistant.

Here are the logs:

This error originated from a custom integration.

Logger: custom_components.nissan_carwings
Source: helpers/update_coordinator.py:386
integration: Nissan Connect (Carwings) (documentation, issues)
First occurred: 15:00:30 (3 occurrences)
Last logged: 15:04:15

Error fetching nissan_carwings data: Error fetching data - AttributeError: 'CarwingsLatestClimateControlStatusResponse' object has no attribute '_operation_date_and_time'

This error originated from a custom integration.

Logger: custom_components.nissan_carwings
Source: custom_components/nissan_carwings/api.py:216
integration: Nissan Connect (Carwings) (documentation, issues)
First occurred: 15:00:30 (9 occurrences)
Last logged: 15:34:23

Error fetching data - AttributeError: 'CarwingsLatestClimateControlStatusResponse' object has no attribute '_operation_date_and_time'
remuslazar commented 1 week ago

@lootre thanks for the error log, I was able to spot the bug. It's already fixed in the new release: https://github.com/remuslazar/homeassistant-carwings/releases/tag/v0.1.6

Could u please test that again if it works now?

JorenVandenBergh commented 1 week ago

I can confirm A/C (both the Switch in HA as the actual logic) works perfect for my 2018 European Leaf in 0.1.6!

Thanks for all your work on this integration!

lootre commented 1 week ago

Yes it's much better now ! Thank you very much for your amazing work !

remuslazar commented 1 week ago

Sounds great! I will close this issue now.. finally! :)