Open crhammock opened 3 years ago
Good point. Can you try with the latest commit on master
?
Thanks David, I grabbed the latest files and rebooted.
First I tried the below, the format was defined by the "Fill Example Data" hyperlink via yaml mode
service: home_connect_beta.set_option_active
data:
entity_id: switch.oven_power
key: Cooking.Oven.Option.SetpointTemperature
value: 180
unit: °C
This produced the below error
websocket_api script: Error executing script. Unexpected error for call_service at pos 1: {'key': 'SDK.Error.InvalidOptionValue', 'description': 'Key Cooking.Oven.Option.SetpointTemperature has unexpected type or value 180'}
I also tried the below, based on the format used for the start program service
service: home_connect_beta.set_option_active
data:
entity_id: switch.oven_power
options:
- key: Cooking.Oven.Option.SetpointTemperature
value: 200
unit: °C
This produced the error
websocket_api script: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['options']
Don't know if that helps, I have tried a load of different scenarios and formats but they all seem to provide similar log output and results.
Can you please try with a raw API call or look at the API docs? I wouldn't know why SetPointTemperature should not be allowed to have value 180.
Sorry still getting my head round the logs, didn't realise the log was a response from the API rather than HA.
curl -X PUT "https://api.home-connect.com/api/homeappliances/{MYHAID}/programs/active/options/Cooking.Oven.Option.SetpointTemperature" -H "accept: application/vnd.bsh.sdk.v1+json" -H "Accept-Language: en-GB" -H "authorization: Bearer {AuthKey}" -H "Content-Type: application/vnd.bsh.sdk.v1+json" -d "{ \"data\": { \"key\": \"Cooking.Oven.Option.SetpointTemperature\", \"value\": 180, \"unit\": \"°C\" }}"
I was able to get the RAW API working with the above call.
I wonder if its because the difference is that the optionkey has to be specified in the request URL I don't think this is required when starting a new program. So the key need to be in both the data in the api call (with value and unit) but also in the URL? think this would explain the error from the API previously
Thanks for checking, I think I have found the problem, but I don't have time to try it myself - would be great if you could check again with 008091f.
No problem, happy to be the guinea pig.
I have downloaded the latest files from github but I still get the same SDK error. I can't see anything in the change related to the URL. Are you sure the URL being called to Home Connect is https://api.home-connect.com/api/homeappliances/{MYHAID}/programs/active/options/**{OPTION_KEY}**"
Are you sure the URL being called to Home Connect is https://api.home-connect.com/api/homeappliances/{MYHAID}/programs/active/options/**{OPTION_KEY}**"
I think so, the relevant line is here: https://github.com/DavidMStraub/homeconnect/blob/master/homeconnect/api.py#L343
Sorry if this is a stupid question but what is that api.py you have linked to? I am using the one in
this doesn't have any reference like that on https://github.com/DavidMStraub/homeconnect/blob/master/homeconnect/api.py#L343
@DavidMStraub if this wasn't python and I was going about troubleshooting in a different programming language I would output the API call to a log file or in this instance the HomeAssistant log. Is this possible to do in python in this instance. This should allow me to identify what is wrong with the API call produced from the integration and service call and might help pinpoint where in the code it is failing?
Just thought I would post my findings in case anyone picks this up at some point as I certainly wont remember all this in a couple of weeks. I attempted to adjust the current cooking duration with the script syntax below
service: home_connect_beta.set_option_active data: entity_id: switch.oven_power key: BSH.Common.Option.Duration value: 3600 unit: seconds
this resulted in the following error logs, I have obviscated the haid and bearerid.
2022-02-15 21:51:31 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=home_connect_beta, service=set_option_active, service_data=entity_id=switch.oven_power, key=BSH.Common.Option.Duration, value=3600, unit=seconds> 2022-02-15 21:51:31 DEBUG (SyncWorker_5) [requests_oauthlib.oauth2_session] Invoking 0 protected resource request hooks. 2022-02-15 21:51:31 DEBUG (SyncWorker_5) [requests_oauthlib.oauth2_session] Adding token {'access_token': '2022-02-15 21:51:31 DEBUG (SyncWorker_5) [requests_oauthlib.oauth2_session] Requesting url https://api.home-connect.com//api/homeappliances/haid/programs/active/options/BSH.Common.Option.Duration using method PUT. 2022-02-15 21:51:31 DEBUG (SyncWorker_5) [requests_oauthlib.oauth2_session] Supplying headers {'Content-Type': 'application/vnd.bsh.sdk.v1+json', 'accept': 'application/vnd.bsh.sdk.v1+json', 'Authorization': 'Bearer bearerid'} and data {"data": {"key": "BSH.Common.Option.Duration", "value": "3600", "unit": "seconds"}} 2022-02-15 21:51:31 DEBUG (SyncWorker_5) [requests_oauthlib.oauth2_session] Passing through key word arguments {}. 2022-02-15 21:51:31 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: {'key': 'SDK.Error.InvalidOptionValue', 'description': 'Key BSH.Common.Option.Duration has unexpected type or value 3600'} Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 372, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 575, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1667, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/config/custom_components/home_connect_beta/__init__.py", line 154, in async_service_option_active await _async_service_key_value(call, "set_options_active_program") File "/config/custom_components/home_connect_beta/__init__.py", line 148, in _async_service_key_value await hass.async_add_executor_job( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.9/site-packages/homeconnect/api.py", line 342, in set_options_active_program return self.put( File "/usr/local/lib/python3.9/site-packages/homeconnect/api.py", line 267, in put return self.hc.put( File "/usr/local/lib/python3.9/site-packages/homeconnect/api.py", line 110, in put raise HomeConnectError(res["error"]) homeconnect.api.HomeConnectError: {'key': 'SDK.Error.InvalidOptionValue', 'description': 'Key BSH.Common.Option.Duration has unexpected type or value 3600'} 2022-02-15 21:51:31 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140611611466240] Error handling message: Unknown error Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 534, in handle_execute_script await script_obj.async_run(msg.get("variables"), context=context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1253, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 354, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 372, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 575, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1630, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1667, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/config/custom_components/home_connect_beta/__init__.py", line 154, in async_service_option_active await _async_service_key_value(call, "set_options_active_program") File "/config/custom_components/home_connect_beta/__init__.py", line 148, in _async_service_key_value await hass.async_add_executor_job( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.9/site-packages/homeconnect/api.py", line 342, in set_options_active_program return self.put( File "/usr/local/lib/python3.9/site-packages/homeconnect/api.py", line 267, in put return self.hc.put( File "/usr/local/lib/python3.9/site-packages/homeconnect/api.py", line 110, in put raise HomeConnectError(res["error"]) homeconnect.api.HomeConnectError: {'key': 'SDK.Error.InvalidOptionValue', 'description': 'Key BSH.Common.Option.Duration has unexpected type or value 3600'} 2022-02-15 21:51:31 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140611611466240] Sending {"id": 103, "type": "result", "success": false, "error": {"code": "unknown_error", "message": "Unknown error"}}
I then performed the required request via Curl in linux with
curl -X PUT "https://api.home-connect.com/api/homeappliances/haid/programs/active/options/BSH.Common.Option.Duration" -H "accept: application/vnd.bsh.sdk.v1+json" -H "Accept-Language: en-GB" -H "authorization: Bearer bearerid" -H "Content-Type: application/vnd.bsh.sdk.v1+json" -d "{ \"data\": { \"key\": \"BSH.Common.Option.Duration\", \"value\": 3600, \"unit\": \"seconds\" }}"
Comparing purely the Curl URL and the equivalent URL output from the HomeAssistant debug log they look for the most part the same, clearly the issue is down to specific syntax it is hard to tell with all the escape characters. I might try changing the order of the headers in the curl command to make it clearer but the error tends to suggest the issue is with the data section of the call which I can't see an issue with.
Any help or suggestions from anyone is appreciated otherwise hopefully this information helps someone
I have been starting to use the Home Assistant HomeConnect integration with my oven thanks to the recent feature. However I am unable to get the set_option_active service to work. The below detail from the API tool suggests the feature is only available on ovens yet the example perimeters use a dryer. When trying to perform such tasks as change the temperature or duration of the active program I get the following error
Error handling message: extra keys not allowed @ data['unit']. Got None
https://apiclient.home-connect.com/?url=https%3A//apiclient.home-connect.com/hcsdk-production.yaml&client_id=YOUR_CLIENT_ID#/programs/set_active_program_options
I am using the following YAML