i8beef / ecobee Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
The return type for Sensors and Outputs should be array or IList instead of Sensor and Output. Thank you!
I'm using your API is a progressive web app. It has a web component and an automation component on the back end. This means that for every set of ecobee auth tokens there are at least two clients operating concurrently on them from separate processes. The way the API works right now is that once you initiate the client it assumes that it has sole control of the auth tokens but in my case there are several parties that constantly refresh the tokens and must be aware of each others changes otherwise the ecobee servers will complain of expired auth token submission. For this reason I maintain the auth tokens in a database that is accessed by all the parties. But for this to work the Client class has to allow mid stream token updates not just on instantiation of the class through the constructor. Of course I could create a new Client class every request but that would not be proper considering all the setup that goes on inside.
As .NET Standard 2.0 is fleshed out, reimplement the library as a .NET Standard 2.0 library.
When attempting the following request to change the hvacMode of a thermostat:
public async Task<Response> SetHvacMode(string thermostatId, string newMode)
{
// TODO: this doesn't work for some reason
try {
var request = new ThermostatUpdateRequest
{
Selection = new Selection
{
SelectionType = "registered",
SelectionMatch = thermostatId
},
Thermostat = new Thermostat
{
Settings = new Settings
{
HvacMode = newMode
}
}
};
var response = await this.ecobeeClient.PostAsync<ThermostatUpdateRequest, Response>(request);
return response;
} catch (ApiAuthException ex) {
this.clearTokenSync();
throw ex;
}
}
I get this error response back from the Ecobee API:
7: Validation error. [Rule int(5,60) failed on: 0 /thermostat/ventilatorMinOnTime][Rule int(5,30) failed on: 0 /thermostat/setting/stage1HeatingDifferentialTemp][Rule int(5,30) failed on: 0 /thermostat/setting/stage1CoolingDifferentialTemp]
In particular, it's complaining that 0 is an invalid value for the following fields on the Settings object:
ventilatorMinOnTime
stage1HeatingDifferentialTemp
stage1CoolingDifferentialTemp
At a glance, this error seems like it comes from nowhere: after all, the Ecobee API docs list those fields as not-required, and I'm not providing them (just like in their example), so it should work.
Glancing at the source of this lib, it looks like in the current version the Settings
object declares these fields as int
, which is a value type in C#, so it can't ever have the value null
-- instead, it seems like it's defaulting to 0
, which is what's causing the validation errors to occur.
Glancing around, it looks like there are quite a few fields that are declared as int
when they probably should be int?
, to avoid defaulting to 0 when the user does not intend to.
Having this problem again where my app complains about 'Newtonsoft.Json'.
FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Remember I had fixed it before by changing my app from .Net Framework to .Net Standard but as I started pulling in libraries that I needed, .Net Standard was really breaking them so had to move my project back to .NET framework.
I tried adding this in the app.config but it instead it now gives me two errors one for v11.0.0.0 and one for v11.0.1.0:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.1.0" newVersion="11.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I also added a nuget package reference to Newtonsoft.Json v11.0.1.0 in my project and still.
Any ideas?
Are there any plans to update this API to the new authentication scheme that Ecobee just put in place?
Is it possible for you to provide a few more API requests examples like you have with this:
var request = new ThermostatSummaryRequest {
Selection = new Protocol.Objects.Selection {
SelectionType = "registered"
}
};
var response = client.Get<ThermostatSummaryRequest, ThermostatSummaryResponse>(request).Result;
I need the following:
With just one single request as an example its really hard to map out the API docs to your code. You have no examples doing a POST with a JSON payload.
Looking at the Client class I noticed this:
private TimeSpan _timeout = TimeSpan.FromSeconds(30);
But this is not used anywhere so my assumption is that you intended to implement a timeout at some point and never did.
Well I was going to externally implement my own time out with this function:
Public Async Function WithTimeout(Of TResult)(
sctTimeout As TimeSpan,
objAsyncFunc As Func(Of CancellationToken, Task(Of TResult)),
Optional strErrorMsg As String = Nothing
) As Task(Of TResult)
Dim objCts = New CancellationTokenSource(sctTimeout.TotalMilliseconds)
Try
Return Await objAsyncFunc.Invoke(objCts.Token)
Catch ex As TaskCanceledException
If strErrorMsg = Nothing Then
Throw ex
Else
Throw New ApplicationException(strErrorMsg)
End If
End Try
End Function
But then I would have to call each API function like this:
Dim strResult = Await WithTimeout(TimeSpan.FromMilliseconds(30000), Async Function(ct) Await TestAsync(2000, ct), "Ecobee servers did not respond in time.")
This works but it would be so much nicer if it was included in the Client class of the API. You're welcome to use this global function which adds the timeout feature to any async function that takes a cancelation token. All yours do.
I have this code:
public async function SetHoldTemp(intnewTemp)
{
var request = new ThermostatUpdateRequest
{
Selection = new I8Beef.Ecobee.Protocol.Objects.Selection
{
SelectionType = "registered",
SelectionMatch = ""
}
};
request.Functions.Add(
new I8Beef.Ecobee.Protocol.Functions.SetHoldFunction
{
Type = "setHold",
Params = new I8Beef.Ecobee.Protocol.Functions.SetHoldParams
{
CoolHoldTemp = newTemp,
HeatHoldTemp = newTemp,
HoldType = "nextTransition"
}
}
);
var response = await this.ecobeeClient.PostAsync<ThermostatUpdateRequest, Response>(request);
return response;
}
I've tried a variety of "shapes" for my ThermostatUpdateRequest
object, but the same result comes back every time: "Object reference not set to an instance of an object." I've tried even directly copy-pasting both from your "EcobeeClientTest" and your MQTT-to-Ecobee bridge project (both of which have any code paths with a "set hold" commented out, which I suspect may be because this codepath is just broken), and that fails with the same cause too.
Have you been able to successfully set a temperature hold using this lib?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.