Skip to content

Commit

Permalink
Merge pull request #55 from soffes/standard
Browse files Browse the repository at this point in the history
Add linter
  • Loading branch information
soffes committed Jan 3, 2024
2 parents 7cc4ae2 + 33a9df1 commit f7d26f0
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 221 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ name: Tests
on: [push]
jobs:
test:
name: Test Swift Package
name: Test
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v1
- uses: actions/setup-ruby@v1
- name: 'Install Dependencies'
run: sudo apt-get install libcurl4-openssl-dev && gem install bundler && bundle install
- name: 'Test'
- name: Checkout
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Test
run: bundle exec rake test
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Test
run: bundle exec rake standard
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem 'rake'
gem "rake", "~> 13.0"
gem "minitest", "~> 5.0"
gem "standard", "~> 1.3"
gem "webmock", "~> 3.19"
14 changes: 8 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end

task :default => :test
require "standard/rake"

task default: :test
38 changes: 17 additions & 21 deletions hue.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'hue/version'
require "hue/version"

Gem::Specification.new do |spec|
spec.name = 'hue'
spec.version = Hue::VERSION
spec.authors = ['Sam Soffes']
spec.email = ['[email protected]']
spec.description = 'Work with Philips Hue light bulbs.'
spec.summary = 'Work with Philips Hue light bulbs from Ruby.'
spec.homepage = 'https://github.com/soffes/hue'
spec.license = 'MIT'
spec.name = "hue"
spec.version = Hue::VERSION
spec.authors = ["Sam Soffes"]
spec.email = ["[email protected]"]
spec.description = "Work with Philips Hue light bulbs."
spec.summary = "Work with Philips Hue light bulbs from Ruby."
spec.homepage = "https://github.com/soffes/hue"
spec.license = "MIT"

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.required_ruby_version = '>= 2.1.0'
spec.add_dependency 'thor'
spec.add_dependency 'json'
spec.add_dependency 'color_conversion'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'webmock'
spec.required_ruby_version = ">= 2.1.0"
spec.add_dependency "thor"
spec.add_dependency "json"
spec.add_dependency "color_conversion"
end
18 changes: 9 additions & 9 deletions lib/hue.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'hue/version'
require 'hue/errors'
require 'hue/client'
require 'hue/bridge'
require 'hue/editable_state'
require 'hue/translate_keys'
require 'hue/light'
require 'hue/group'
require 'hue/scene'
require "hue/version"
require "hue/errors"
require "hue/client"
require "hue/bridge"
require "hue/editable_state"
require "hue/translate_keys"
require "hue/light"
require "hue/group"
require "hue/scene"

module Hue
USERNAME_RANGE = 10..40
Expand Down
36 changes: 18 additions & 18 deletions lib/hue/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ def initialize(client, hash)
# Current time stored on the bridge.
def utc
json = get_configuration
DateTime.parse(json['utc'])
DateTime.parse(json["utc"])
end

# Indicates whether the link button has been pressed within the last 30
# seconds.
def link_button_pressed?
json = get_configuration
json['linkbutton']
json["linkbutton"]
end

# This indicates whether the bridge is registered to synchronize data with a
# portal account.
def has_portal_services?
json = get_configuration
json['portalservices']
json["portalservices"]
end

def refresh
Expand All @@ -74,7 +74,7 @@ def refresh
def lights
@lights ||= begin
json = JSON(Net::HTTP.get(URI.parse(base_url)))
json['lights'].map do |key, value|
json["lights"].map do |key, value|
Light.new(@client, self, key, value)
end
end
Expand All @@ -84,7 +84,7 @@ def add_lights
uri = URI.parse("#{base_url}/lights")
http = Net::HTTP.new(uri.host)
response = http.request_post(uri.path, nil)
(response.body).first
response.body.first
end

def groups
Expand All @@ -105,27 +105,27 @@ def scenes
end
end

private
private

KEYS_MAP = {
:id => :id,
:ip => :internalipaddress,
:name => :name,
:proxy_port => :proxyport,
:software_update => :swupdate,
:ip_whitelist => :whitelist,
:software_version => :swversion,
:proxy_address => :proxyaddress,
:mac_address => :macaddress,
:network_mask => :netmask,
:portal_services => :portalservices,
id: :id,
ip: :internalipaddress,
name: :name,
proxy_port: :proxyport,
software_update: :swupdate,
ip_whitelist: :whitelist,
software_version: :swversion,
proxy_address: :proxyaddress,
mac_address: :macaddress,
network_mask: :netmask,
portal_services: :portalservices
}

def unpack(hash)
KEYS_MAP.each do |local_key, remote_key|
value = hash[remote_key.to_s]
next unless value
instance_variable_set("@#{local_key}", value)
instance_variable_set(:"@#{local_key}", value)
end
end

Expand Down
52 changes: 26 additions & 26 deletions lib/hue/cli.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
require 'thor'
require "thor"

module Hue
class Cli < Thor
desc 'lights', 'Find all of the lights on your network'
desc "lights", "Find all of the lights on your network"
def lights
client.lights.each do |light|
puts light.id.to_s.ljust(6) + light.name
end
end

desc 'add LIGHTS', 'Search for new lights'
desc "add LIGHTS", "Search for new lights"
def add(thing)
case thing
when 'lights'
when "lights"
client.add_lights
end
end

desc 'light ID STATE [COLOR]', 'Access a light'
desc "light ID STATE [COLOR]", "Access a light"
long_desc <<-LONGDESC
Examples: \n
hue all on \n
Expand All @@ -27,41 +27,41 @@ def add(thing)
hue all --hue 50000 --brightness 200 --saturation 240 \n
hue all --alert lselect \n
LONGDESC
option :hue, :type => :numeric
option :sat, :type => :numeric, :aliases => '--saturation'
option :bri, :type => :numeric, :aliases => '--brightness'
option :alert, :type => :string
desc 'all STATE', 'Send commands to all lights'
def all(state = 'on')
option :hue, type: :numeric
option :sat, type: :numeric, aliases: "--saturation"
option :bri, type: :numeric, aliases: "--brightness"
option :alert, type: :string
desc "all STATE", "Send commands to all lights"
def all(state = "on")
body = options.dup
body[:on] = state == 'on'
body[:on] = state == "on"
client.lights.each do |light|
puts light.set_state body
end
end

desc 'light ID STATE [COLOR]', 'Access a light'
desc "light ID STATE [COLOR]", "Access a light"
long_desc <<-LONGDESC
Examples: \n
hue light 1 on --hue 12345 \n
hue light 1 --brightness 25 \n
hue light 1 --alert lselect \n
hue light 1 off
LONGDESC
option :hue, :type => :numeric
option :sat, :type => :numeric, :aliases => '--saturation'
option :bri, :type => :numeric, :aliases => '--brightness'
option :alert, :type => :string
option :hue, type: :numeric
option :sat, type: :numeric, aliases: "--saturation"
option :bri, type: :numeric, aliases: "--brightness"
option :alert, type: :string
def light(id, state = nil)
light = client.light(id)
puts light.name

body = options.dup
body[:on] = (state == 'on' || !(state == 'off'))
body[:on] = (state == "on" || !(state == "off"))
puts light.set_state(body) if body.length > 0
end

desc 'groups', 'Find all light groups on your network'
desc "groups", "Find all light groups on your network"
def groups
client.groups.each do |group|
puts group.id.to_s.ljust(6) + group.name
Expand All @@ -71,28 +71,28 @@ def groups
end
end

desc 'group ID STATE [COLOR]', 'Update a group of lights'
desc "group ID STATE [COLOR]", "Update a group of lights"
long_desc <<-LONGDESC
Examples: \n
hue groups 1 on --hue 12345
hue groups 1 --brightness 25
hue groups 1 --alert lselect
hue groups 1 off
LONGDESC
option :hue, :type => :numeric
option :sat, :type => :numeric, :aliases => '--saturation'
option :bri, :type => :numeric, :aliases => '--brightness'
option :alert, :type => :string
option :hue, type: :numeric
option :sat, type: :numeric, aliases: "--saturation"
option :bri, type: :numeric, aliases: "--brightness"
option :alert, type: :string
def group(id, state = nil)
group = client.group(id)
puts group.name

body = options.dup
body[:on] = (state == 'on' || !(state == 'off'))
body[:on] = (state == "on" || !(state == "off"))
puts group.set_state(body) if body.length > 0
end

private
private

def client
@client ||= Hue::Client.new
Expand Down
Loading

0 comments on commit f7d26f0

Please sign in to comment.