Code Monkey home page Code Monkey logo

ecobee's People

Contributors

i8beef avatar perecli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ecobee's Issues

Nullable fields declared as `int` values default to 0, causing validation errors when doing a POST to update the thermostat's HvacMode

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.

another small change request

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.

"Object reference not set to an instance of an object" on PostAsync with a ThermostatUpdateRequest containing a SetHoldFunction.

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?

more examples

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:

  • get temperature of all sensors
  • set a hold with a designated comfort zone
  • set a sensor to participate in a comfort zone
  • set system mode: heat, AC, auto, off
  • set a hold with desired heat and cold temps

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.

small change request

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.

FileLoadException: Could not load file or assembly 'Newtonsoft.Json'

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.