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

HADotNet stopped working after 0.118 update #13

Closed
SamKr opened this issue Nov 19, 2020 · 16 comments
Closed

HADotNet stopped working after 0.118 update #13

SamKr opened this issue Nov 19, 2020 · 16 comments
Assignees
Labels
bug Something isn't working

Comments

@SamKr
Copy link

SamKr commented Nov 19, 2020

I'm using the latest HDDotNet.Core (1.3.2) to connect to my HomeAssistant server, which I updated today to 0.118.
However, suddenly my code stopped at this point:

// intialise hass client
ClientFactory.Initialize(Variables.HassIp, Variables.HassToken);

// retrieve config
 _configClient = ClientFactory.GetClient<ConfigClient>();

It's giving me this exception:

2020-11-19 12:46:05.253 +01:00 [FTL] Unexpected response code 0 from Home Assistant API endpoint /api/config.
System.Exception: Unexpected response code 0 from Home Assistant API endpoint /api/config.
   at HADotNet.Core.BaseClient.<Get>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at HADotNet.Core.Clients.ConfigClient.<GetConfiguration>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at HomeAssistantGrafanaUpdater.HomeAssistant.HassManager.<Initialise>d__4.MoveNext() in [REDACTED]HassManager.cs:line 31

Visual Studio is on the latest version (16.8.1), and the project uses .NET Framework 4.8.

Any idea what's happening?

@SamKr SamKr added the bug Something isn't working label Nov 19, 2020
@SamKr
Copy link
Author

SamKr commented Nov 19, 2020

Found this in the dev blog: api changes

@SamKr
Copy link
Author

SamKr commented Nov 20, 2020

Actually I don't think the api changes are relevant. When I use curl to fetch the json, using the same uri and bearer, it works and I get a json string. When I deserialize that, using the classes in your project, it works.

When I extend your library to include the restsharp error message, it gives this:

Error: Found invalid data while decoding.

At a loss why it's saying that though. Any idea?

@SamKr
Copy link
Author

SamKr commented Nov 21, 2020

Ended up extending your library to use a curl fallback in case restsharp fails, which works fine for now.

@neodd70
Copy link

neodd70 commented Nov 21, 2020

I'm experiencing the same problem.

@PockyBum522
Copy link

I'm experiencing this as described above. @SamKr can you share your fork that works?

@SamKr
Copy link
Author

SamKr commented Nov 24, 2020

Sure @PockyBum522, will do tomorrow.

@SamKr
Copy link
Author

SamKr commented Nov 25, 2020

Here you go @PockyBum522 : HADotNet fork.

Please read the readme for instructions. Let me know if it doesn't work for you.

@PockyBum522
Copy link

Thank you very much! I'll have a chance to test today.

@qJake
Copy link
Owner

qJake commented Dec 8, 2020

@SamKr What platform/OS are you running on? curl isn't a Windows thing so I'm assuming you're on something else?

RestSharp may have issues on other platforms and that could be the cause. I can try bumping up RestSharp's dependency version to see if that resolves it.

@SamKr
Copy link
Author

SamKr commented Dec 8, 2020

I'm using Windows, curl is available for windows: https://curl.se/windows/

@qJake
Copy link
Owner

qJake commented Dec 8, 2020

Well sure, but not out of the box and not (easily?) as a NuGet dependency... so CliWrap fails if you didn't go out of your way to install curl manually. 😉

In any case, this looks like a bug with 0.118.x, I'll take a look and see if I can find out what changed.

Worst case, I can enhance that error message - response codes of 0 indicate a network issue of some kind, for which there's an error message that should be printed out in those cases.

@SamKr
Copy link
Author

SamKr commented Dec 8, 2020

Curl is a stand alone exe, so as long as I provide it along with the project's executable it's fine. And it's a backup method which is working fine for now.

I tried bumping restsharp and looking what's happening, but didn't get much result. Hopefully you'll do better :)

@KoalaBear84
Copy link

KoalaBear84 commented Dec 25, 2020

Why use Curl when you can use HttpClient? I don't understand. The REST API still works without any issues with HttpClient.

Ahh, nvm, probably because there is an issue in RestSharp.. Which is able to use a fallback.

@Trozmagon
Copy link

The Curl solution doesn't work when performing Posts, any updates on a RestSharp solution?

@Trozmagon
Copy link

Can confirm a basic HttpClient is working just fine:

var client = new HttpClient { BaseAddress = new Uri(""), Timeout = new TimeSpan(0, 0, 0, 0, -1) };
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "
***");

var request = new HttpRequestMessage(HttpMethod.Post, "/api/services/media_player/volume_up");
request.Content = new StringContent("{"entity_id":"media_player.living_room_speaker"}", Encoding.UTF8, "application/json");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

await client.SendAsync(request).ContinueWith(r => {
Console.WriteLine("Response: {0}", r.Result);
});

@qJake
Copy link
Owner

qJake commented Jan 23, 2021

Version 1.4.0 has just been pushed out to NuGet that addresses this. Closing this issue.

@qJake qJake closed this as completed Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants