Saturday, August 31, 2013

Android Async Task with Toast Status

Here's an extension of the CatchableAsyncTaskLoader I wrote about to add progress/status updates via a Toast

Radio Thermostat Auto-Away Script

When I set out to get a wifi-enabled thermostat, here's what I originally wrote about our furnace thermostat before we had cooling installed:

"Looking into wifi enabled HVAC thermostats... nothing strikes me as having the features that I want. They target "easy of programming" and "energy saving" but none of them explicitly aim to monitor more rooms with wireless sensors (though it can be added on) and it is obvious that lowering the temperature setting in winter saves energy, I don't need a green leaf icon for that. Sometimes I want to be able to just circulate the air with the fan with a set timer. And why should I have to program the thermostat at all? If it is on my local network, then it should be able to detect when our phones are here, implying that we are here.

So here's my requirements:
1) A temperature setting when I'm home.
2) A temperature setting when my wife is home (overrides my setting).
3) A temperature setting when we're probably sleeping
4) A temperature setting when nobody is home
5) The ability to set a timer to run the fan for for air circulation
6) Extra wireless thermometers in key 'hotspot' rooms
7) A nice to have would be a count of the number of hours the air filter has been in use."

I ended up finding the Radio Thermostat 3m-50 for $99 at Home Depot, which was a great deal. I don't understand why Nest gets so much press since it doesn't really solve any problem (having a thermostat schedule when our lives don't really have a schedule), it just makes living with the problem and fiddling with a thermostat all the time more fun; but it a very expensive piece of entertainment. Sorry, but distracting the user from the problem doesn't count as an actual solution. The real problem is that a thermostat should be able to sense if nobody is home so it doesn't waste energy, and it should obviously sense when they return.

To actually solve the problem, I use this piece of ruby script that pings our phones and sets away mode when we are not home:

Sunday, August 25, 2013

Variation on AsyncResult for Android AsyncTaskLoader

I found this example of an AsyncResult for an Android AsyncTaskLoader

However, it suggests a pattern of handling exception types with if/else statements in the "if (exception != null)", likely with instanceof.

That responsibility really belongs to the user, and the user can do this instead:

try {
   if (result.getException ()) throw result.getException ();
   // non-exception results
} catch ...

However, this also leaves the responsibility of the user to catch and not ignore the exception. So here's a better alternative that forces the user to catch the (parameterized!) exception to get the value: