Skip to content

Instantly share code, notes, and snippets.

@nixterrimus
Last active December 11, 2015 12:48
Show Gist options
  • Save nixterrimus/4602711 to your computer and use it in GitHub Desktop.
Save nixterrimus/4602711 to your computer and use it in GitHub Desktop.
My latest take on what a spirit adapter will look like
class HueAdapter < Spirit::Adapter::Base
name "Philips Hue"
author "Nick Rowe"
implements :colorable_light, :dimmable_light
require_user_setup :true
user_settings do
text :ip_address, required: true, description: "The IP Address of the Hue, use this if your Hue is always available on the same address"
schedule :active_days
boolean :default_to_white_colored_light, "Defaults the lights to a nice white color when they turn on rather than the last set color"
number :fade_rate, "How quickly you'd like the light to dim up, in second"
end
def apply_device_state(device)
# Code goes here!
end
def update_device_state(device)
# Code goes here!
end
end
@nixterrimus
Copy link
Author

I would love feedback or thoughts on how this adapter looks, works, and if you would build one for something in your life.

Adapters will be written as gems. They will have to require spirit-adapter in their Gemfile.

I'm still not clear on how requiring user setup is going to work. For example with the hue you have to have the user push a button on the device. Other devices will require different kinds of setup. I still need to think about it.

This adapter is inspired by the way homebrew formulas are written. Here's an example of the ZSH homebrew formula

I don't love that adapters have to extend from Spirit::Adapter::Base but I don't see how I can support a DSL without having the user do it. I take some comfort in knowing that an adapter for spirit is not going to be code that's being reused from another project so it's not likely the author would want to extend from another class.

I need to write a generator which makes generating the scaffolding for a spirit adapter/device easy.

If the user is implementing adding a custom device (and implementing it) there's going to be more assets in this gem package. The package will also have to include view assets for working with spirit web. A problem for another night, thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment