home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.35k stars 30.28k forks source link

ViCare One Time Charge Button leads to an error #73064

Closed Friedi1970 closed 2 years ago

Friedi1970 commented 2 years ago

The problem

Since a couple of versions within the ViCare integration there is a entity „button.activate_one_time_charge“ provided which is unfortunately not working. When pressing the button I just receive „TypeError: string indices must be integers“ which is caused by the Home Assistant WebSocket API integration. Anyway, I think the error is caused by ViCare integration.

What version of Home Assistant Core has the issue?

Never worked

What was the last working version of Home Assistant Core?

core-2022.6.2

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Viessmann ViCare

Link to integration documentation on our website

https://www.home-assistant.io/integrations/vicare/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.websocket_api.http.connection
Source: components/vicare/button.py:40 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 08:57:01 (1 occurrences) 
Last logged: 08:57:01

[547868800576] string indices must be integers
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareUtils.py", line 58, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareDevice.py", line 283, in activateOneTimeCharge
    return self.service.setProperty("heating.dhw.oneTimeCharge", "activate", {})
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareCachedService.py", line 29, in setProperty
    response = super().setProperty(property_name, action, data)
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareService.py", line 60, in setProperty
    return self.oauth_manager.post(url, post_data)
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareAbstractOAuthManager.py", line 91, in post
    self.__handle_command_error(response)
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareAbstractOAuthManager.py", line 67, in __handle_command_error
    raise PyViCareCommandError(response)
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareUtils.py", line 124, in __init__
    reason = extended_payload["reason"]
KeyError: 'reason'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 193, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1704, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1741, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 964, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 717, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 114, in _async_press_action
    await self.async_press()
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 129, in async_press
    await self.hass.async_add_executor_job(self.press)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/vicare/button.py", line 86, in press
    self.entity_description.value_getter(self._api)
  File "/usr/src/homeassistant/homeassistant/components/vicare/button.py", line 40, in <lambda>
    value_getter=lambda api: api.activateOneTimeCharge(),
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareUtils.py", line 65, in feature_flag_wrapper
    return wrapper(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareUtils.py", line 60, in wrapper
    raise PyViCareCommandError(func.__name__)
  File "/usr/local/lib/python3.9/site-packages/PyViCare/PyViCareUtils.py", line 121, in __init__
    statusCode = response["statusCode"]
TypeError: string indices must be integers

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

vicare documentation vicare source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @oischinger, mind taking a look at this issue as it has been labeled with an integration (vicare) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

harenber commented 2 years ago

+1

skahlhoefer commented 2 years ago

I did some small investigation on this and proved that the error is reported from the used PyViCare module directly. Reporting that in the appropriate repository resulted in an improved module release 2.16.3 which throws an PyViCare.PyViCareUtils.PyViCareCommandError exception instead of the unhandled TypeError.

This doesn't change a lot as the service call will still not work. The root cause for this seems to be, that specific Viessmann devices just don't support the heating.dhw.oneTimeCharge function.

Friedi1970 commented 2 years ago

@oischinger should the bug be fixed with the last update of core? Unfortunately it is still the same problem.

oischinger commented 2 years ago

@Friedi1970 can this be reproduced? It works for me.

Friedi1970 commented 2 years ago

@oischinger of course. As often as you like. It occurs on every single push 🤷‍♂️

oischinger commented 2 years ago

But it mist be a different exception in the logs now since the original issue got fixed. Can you please post it?

Also: does your device offer one-time-charge in the Vicare app?

By the way: I can only push the button once every few minutes. When a one-timr-charge is already started I get this:

Screenshot_20220903_132614_io homeassistant companion android

Friedi1970 commented 2 years ago

Of course, here is the log:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/vicare/button.py:40 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 13:17:13 (3 occurrences) 
Last logged: 13:55:09

[546940339824] string indices must be integers
[547027257472] string indices must be integers
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareUtils.py", line 58, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareDevice.py", line 283, in activateOneTimeCharge
    return self.service.setProperty("heating.dhw.oneTimeCharge", "activate", {})
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareCachedService.py", line 29, in setProperty
    response = super().setProperty(property_name, action, data)
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareService.py", line 60, in setProperty
    return self.oauth_manager.post(url, post_data)
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareAbstractOAuthManager.py", line 91, in post
    self.__handle_command_error(response)
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareAbstractOAuthManager.py", line 67, in __handle_command_error
    raise PyViCareCommandError(response)
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareUtils.py", line 124, in __init__
    reason = extended_payload["reason"]
KeyError: 'reason'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 199, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 676, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 713, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 114, in _async_press_action
    await self.async_press()
  File "/usr/src/homeassistant/homeassistant/components/button/__init__.py", line 129, in async_press
    await self.hass.async_add_executor_job(self.press)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/vicare/button.py", line 86, in press
    self.entity_description.value_getter(self._api)
  File "/usr/src/homeassistant/homeassistant/components/vicare/button.py", line 40, in <lambda>
    value_getter=lambda api: api.activateOneTimeCharge(),
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareUtils.py", line 65, in feature_flag_wrapper
    return wrapper(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareUtils.py", line 60, in wrapper
    raise PyViCareCommandError(func.__name__)
  File "/usr/local/lib/python3.10/site-packages/PyViCare/PyViCareUtils.py", line 121, in __init__
    statusCode = response["statusCode"]
TypeError: string indices must be integers

Regarding the app, I habe no idea. Where should this feature be found in the app?

lukx commented 2 years ago

@oischinger About pressing repeatedly: One cannot "activate" while the status is active. See https://github.com/oischinger/ha_vicare/pull/108

@Friedi1970 I have tested regularly the oneTimeCharging feature, and have never come across that issue... It looks like:

I am opening an issue in PyViCare, so that the underlying error message becomes visible again. (edit: done).

@Friedi1970 What's your heater model? It looks like the request gets rejected by the API for some reason; Do you have the Activate-one-time-Charge ("Ich möchte Warmwasser") action on your real ViCare app?

Friedi1970 commented 2 years ago

Meanwhile I figured out that the Vitocrossal 300 has not the option for that feature :( Anyway, if so, this feature shouldn‘t be available within the integration for those models which are not supportet ;)

oischinger commented 2 years ago

@Friedi1970 good point. The check for the data point was missing when creating the button entity. I created a PR to fix that.