Project

rubydeako

0.0
No release in over a year
A Ruby implementation of the pydeako library for controlling Deako smart switches via local network discovery and control
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 2.0
~> 1.0
~> 3.0
~> 2.0
 Project Readme

Rubydeako

Gem Version

A Ruby library for interacting with Deako smart switches via local network discovery and control. This is an unofficial port of the Python pydeako library.

📦 RubyGems: https://rubygems.org/gems/rubydeako

Requires Ruby 3.3+.

Features

  • Device discovery via mDNS/Zeroconf
  • Real-time device state updates
  • Control power and dimming for compatible devices
  • Thread-safe socket communication
  • Automatic connection management with heartbeat monitoring

Installation

Add this line to your application's Gemfile:

gem 'rubydeako'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rubydeako

On Linux, mDNS discovery needs Avahi's Bonjour compatibility library, for example:

# Debian/Ubuntu
sudo apt-get install libavahi-compat-libdnssd-dev

# Fedora
sudo dnf install avahi-compat-libdns_sd-devel

Usage

Basic Example

require 'rubydeako'

# Optional: raise log verbosity while debugging
# Rubydeako.logger.level = Logger::DEBUG

discoverer = Rubydeako::Discover::DeakoDiscoverer.new

deako = Rubydeako::Deako.new(
  discoverer.method(:get_address),
  client_name: "MyRubyApp"
)

begin
  deako.connect
  deako.find_devices

  deako.devices.each do |uuid, device|
    puts "Device: #{device['name']} (#{uuid})"
    puts "  Power: #{device['state']['power']}"
    puts "  Dimmable: #{device['dimmable']}"
  end

  if deako.devices.any?
    first_uuid = deako.devices.keys.first

    deako.control_device(first_uuid, true)

    if deako.dimmable?(first_uuid)
      deako.control_device(first_uuid, true, dim: 50)
    end

    deako.control_device(first_uuid, false)
  end
ensure
  deako.disconnect
  discoverer.stop
end

Device State Callbacks

deako.set_state_callback(uuid) do
  puts "Device #{uuid} state changed!"
  state = deako.get_state(uuid)
  puts "Power: #{state['power']}, Dim: #{state['dim']}"
end

API Reference

Main Classes

Rubydeako::Deako

The main client class for controlling Deako devices.

Methods:

  • connect(timeout: 30) - Block until a device connection is established, or raise Rubydeako::ConnectionError
  • disconnect - Close all connections and stop reconnect/heartbeat workers
  • connected? - Whether the client currently has a live socket
  • find_devices(timeout: 10) - Discover devices on the connected bridge
  • control_device(uuid, power, dim: nil) - Control device state
  • get_name(uuid) - Get device name
  • get_state(uuid) - Get device current state
  • dimmable?(uuid) - Check if device supports dimming
  • set_state_callback(uuid, callback = nil, &block) - Set state change callback

Rubydeako::Discover::DeakoDiscoverer

Handles mDNS discovery of Deako devices.

Methods:

  • start - Begin device discovery
  • stop - Stop discovery
  • get_address - Get the most recently advertised device address

If mDNS finds a Deako service but never yields an IP (common when SRV/A records do not resolve), pass a static address instead of the discoverer:

deako = Rubydeako::Deako.new(
  -> { ['192.168.1.50:23', 'deako-bridge'] },
  client_name: 'MyRubyApp'
)

The local API is telnet-style JSON on port 23.

Logging is configured globally:

Rubydeako.logger.level = Logger::INFO
Rubydeako.logger = Logger.new($stderr)

Dependencies

  • dnssd - mDNS/Zeroconf service discovery (loaded when discovery starts)

Development

After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rspec to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the MIT License.

Acknowledgments

This library is a Ruby port of the Python pydeako library.