alecperkins/py-ninja — pull request #2 by TySkby (2014-03-16 17:40:19+00:00)
Title: Add support for relay devices

The Ninja Blocks REST API has support for relay devices, so I've updated my fork of py-ninja to include support for these.

This adds the ``Relay`` class (subclass of ``Device``) to the ``ninja.devices`` module and also registers the new class in the type map under the ``TYPE_MAP['relay']`` key.

The ``Relay`` class is fairly simple, but here's a break-down:
- Has a "state" attribute which can be set to a logical value.
- Changing the value of ``Relay.state`` sends a PUT request to the API to change the state of the corresponding relay device (eg. bool True for "on" and bool False for "off").
- Also has two "convenience" methods, ``Relay.turn_on()`` and ``Relay.turn_off()``, which set the ``Relay.state`` property to the corresponding bool value.
- The ``Relay.state`` property can be read to retrieve the (last known) state of an initialized relay device instance.

Hopefully everything's up to snuff (I think it is). Happy to change anything you think would make it fit better with the existing code (or anything I may have missed).