Skip to content

Commit

Permalink
Merge pull request kirichkov#8 from kirichkov/rescue_ble_iface_down
Browse files Browse the repository at this point in the history
Exits gracefully if no BT adapter is available
  • Loading branch information
kamaradclimber authored May 2, 2017
2 parents 5294c80 + eee2f98 commit e4d88d7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bin/home_assistant-ble
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ $stderr.sync = true

def shut_down
@detector.clean_all_devices
$stdout.puts 'Quitting'
$stdout.puts 'Quitting...'
end

Signal.trap('INT') do
$stdout.puts 'Received SIGINT.'
shut_down
exit
end

Signal.trap('TERM') do
$stdout.puts 'Received SIGTERM.'
shut_down
exit
end
Expand All @@ -34,4 +36,10 @@ end

@detector = HomeAssistant::Ble::Detector.new(config)

@detector.run
begin
@detector.run
rescue ScriptError
# If no BLE interface is available clean up and exit
$stdout.puts 'No Bluetooth interfaces available.'
shut_down
end

0 comments on commit e4d88d7

Please sign in to comment.