Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Climate : fixing internal server error when setting hvac mode #58

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

MrXANA91
Copy link
Contributor

@MrXANA91 MrXANA91 commented Nov 24, 2024

This pull request closes #57

Thanks to this comment from @davidsak in OpenWonderLabs/SwitchBotAPI#363 :

setAll with a decimal in the temperature parameter does not seem to work anymore but if called with an integer it does. So for instance, “20.3,5,2,on” does not work but “20,5,2,on” does.

When I force a int cast on target_temperature before sending the request, all hvac_set_mode commands seem to work.

@MrXANA91
Copy link
Contributor Author

MrXANA91 commented Nov 24, 2024

This is a pretty dirty quickfix that will probably require to be improved.
It works for me because I only used round target temperature, but this will have some consequences for people using decimals.

I don't really know how to approach this in that case.

@MrXANA91 MrXANA91 changed the title Climate : cast target temperature as int for request Climate : fixing internal server error when setting hvac mode Nov 24, 2024
@KiraPC
Copy link
Owner

KiraPC commented Nov 25, 2024

Hello @MrXANA91

As I mentioned in the issue OpenWonderLabs/SwitchBotAPI#366 I have the same error sending a setAll command with a integer parameter.

What are the evidence that the problem is the float value?

@MrXANA91
Copy link
Contributor Author

Hello @MrXANA91

As I mentioned in the issue OpenWonderLabs/SwitchBotAPI#366 I have the same error sending a setAll command with a integer parameter.

What are the evidence that the problem is the float value?

Using this branch, several commands I tried to send :

2024-11-24 23:40:45.157 DEBUG (SyncWorker_15) [custom_components.switchbotremote.client.remote] Sending command setAll
2024-11-24 23:40:45.157 DEBUG (SyncWorker_15) [custom_components.switchbotremote.client.remote] Command payload {'commandType': 'command', 'command': 'setAll', 'parameter': '20,5,1,on'}
2024-11-24 23:40:45.157 DEBUG (SyncWorker_15) [custom_components.switchbotremote.client.client] Calling service https://api.switch-bot.com/v1.1/devices/****/commands
2024-11-24 23:40:45.982 DEBUG (SyncWorker_15) [custom_components.switchbotremote.client.client] Call service https://api.switch-bot.com/v1.1/devices/****/commands OK

2024-11-25 09:01:37.317 DEBUG (SyncWorker_7) [custom_components.switchbotremote.client.remote] Sending command setAll
2024-11-25 09:01:37.317 DEBUG (SyncWorker_7) [custom_components.switchbotremote.client.remote] Command payload {'commandType': 'command', 'command': 'setAll', 'parameter': '20,1,1,on'}
2024-11-25 09:01:37.317 DEBUG (SyncWorker_7) [custom_components.switchbotremote.client.client] Calling service https://api.switch-bot.com/v1.1/devices/****/commands
2024-11-25 09:01:38.264 DEBUG (SyncWorker_7) [custom_components.switchbotremote.client.client] Call service https://api.switch-bot.com/v1.1/devices/****/commands OK

2024-11-25 09:16:16.407 DEBUG (SyncWorker_15) [custom_components.switchbotremote.client.remote] Sending command setAll
2024-11-25 09:16:16.408 DEBUG (SyncWorker_15) [custom_components.switchbotremote.client.remote] Command payload {'commandType': 'command', 'command': 'setAll', 'parameter': '20,1,3,on'}
2024-11-25 09:16:16.408 DEBUG (SyncWorker_15) [custom_components.switchbotremote.client.client] Calling service https://api.switch-bot.com/v1.1/devices/****/commands
2024-11-25 09:16:17.383 DEBUG (SyncWorker_15) [custom_components.switchbotremote.client.client] Call service https://api.switch-bot.com/v1.1/devices/****/commands OK

And trying the exact same command you described here : OpenWonderLabs/SwitchBotAPI#366

2024-11-25 09:17:38.973 DEBUG (SyncWorker_19) [custom_components.switchbotremote.client.remote] Sending command setAll
2024-11-25 09:17:38.973 DEBUG (SyncWorker_19) [custom_components.switchbotremote.client.remote] Command payload {'commandType': 'command', 'command': 'setAll', 'parameter': '23,1,3,on'}
2024-11-25 09:17:38.973 DEBUG (SyncWorker_19) [custom_components.switchbotremote.client.client] Calling service https://api.switch-bot.com/v1.1/devices/****/commands
2024-11-25 09:17:40.108 DEBUG (SyncWorker_19) [custom_components.switchbotremote.client.client] Call service https://api.switch-bot.com/v1.1/devices/****/commands OK

During my first debugging attempts here, I tried to reset my developer tokens. Maybe doing this had an impact that went unnoticed until now?

@KiraPC
Copy link
Owner

KiraPC commented Nov 25, 2024

For sure there is something strange with these APIs.

I can't test now because I'm OOH, but I'll investigate during the week.

Anyway, thanks for contributing.

@KiraPC
Copy link
Owner

KiraPC commented Nov 27, 2024

Hello,

As per this comment, it seems, as you say, float number cause the error.

But looking at the climate class, target temperature step is set to 1.

How is it possible that we have float?

@MrXANA91
Copy link
Contributor Author

MrXANA91 commented Nov 28, 2024

Hello,

As per this comment, it seems, as you say, float number cause the error.

But looking at the climate class, target temperature step is set to 1.

How is it possible that we have float?

Best guess is that by default, Home Assistant consider all temperature values as floats, including the _target_temperature. That's probably why any attempt to format this value as a string will display it as a float. The solution to cast that value as an int before sending the web request might not be as dirty as I thought it would be.

The thing is : target temperature step for this Climate component can be configured to be between 0.1 and 2 (with 0.1 minimum precision steps) (see config_flow.py ligne 85). Unfortunately from now on, any value except integers as step values are no longer valid. I don't really know how to handle this.

Anyway, let me know what I can do to help having this fix merged as quickly as possible.

@KiraPC
Copy link
Owner

KiraPC commented Dec 2, 2024

Hello,
As per this comment, it seems, as you say, float number cause the error.
But looking at the climate class, target temperature step is set to 1.
How is it possible that we have float?

Best guess is that by default, Home Assistant consider all temperature values as floats, including the _target_temperature. That's probably why any attempt to format this value as a string will display it as a float. The solution to cast that value as an int before sending the web request might not be as dirty as I thought it would be.

The thing is : target temperature step for this Climate component can be configured to be between 0.1 and 2 (with 0.1 minimum precision steps) (see config_flow.py ligne 85). Unfortunately from now on, any value except integers as step values are no longer valid. I don't really know how to handle this.

Anyway, let me know what I can do to help having this fix merged as quickly as possible.

Ok, great!

So could you also update the file to force in the config flow to set step as integer?

@KiraPC KiraPC merged commit e013350 into KiraPC:main Dec 3, 2024
2 checks passed
@gawertm
Copy link

gawertm commented Dec 3, 2024

@KiraPC if it helps you, also the official Switchbot Cloud Integration has problems setting temperature. It works through the Switchbot App though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal Server Error
3 participants