Git Product home page Git Product logo

swiftyhue's Introduction

Carthage compatible CocoaPods compatible Platform

SwiftyHue

Philips Hue SDK written in swift

Work in progress...

Installation

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

To integrate SwiftyHue into your Xcode project using Carthage, specify it in your Cartfile:

github "Spriter/SwiftyHue"

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate SwiftyHue into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

pod 'SwiftyHue', '0.4.1'

Then, run the following command:

$ pod install

Example with submodules

SwiftyHue/Base: The core functionality of SwiftyHue.

SwiftyHue/BridgeServices: Provides classes to find bridges in a network and authenticate with them.

target 'MyApp' do
  use_frameworks!

  pod ’SwiftyHue’, '0.3.3'

end

target 'MyApp tvOS' do
    use_frameworks!
    
    pod ’SwiftyHue’, '0.3.3'
end

target 'MyApp watchOS Extension' do
    use_frameworks!
    
    pod ’SwiftyHue/Base’, '0.3.3'
    
end

Note: You can use SwiftyHue/Base submodule to use SwiftyHue also on watchOS.

Usage

Find Bridge

The first step is to find a bridge in the network.

let bridgeFinder = BridgeFinder()
bridgeFinder.delegate = self;
bridgeFinder.start()

Implement the BridgeFinderDelegate protocol to get the search results.

extension BridgeSelectionTableViewController: BridgeFinderDelegate {
    
    func bridgeFinder(finder: BridgeFinder, didFinishWithResult bridges: [HueBridge]) {
     
        let bridges = bridges;
    }
}

Bridge Authenticator

Before you can connect to a bridge you need to create user.

var bridgeAuthenticator: BridgeAuthenticator! = BridgeAuthenticator(bridge: bridge, uniqueIdentifier: "swiftyhue#\(UIDevice.currentDevice().name)")

Implement the BridgeAuthenticatorDelegate protocol to get the authentication events.

extension BridgePushLinkViewController: BridgeAuthenticatorDelegate {
    
    func bridgeAuthenticator(authenticator: BridgeAuthenticator, didFinishAuthentication username: String) {
        
    }
    
    func bridgeAuthenticator(authenticator: BridgeAuthenticator, didFailWithError error: NSError) {
     
    }
    
    // you should now ask the user to press the link button
    func bridgeAuthenticatorRequiresLinkButtonPress(authenticator: BridgeAuthenticator) {

    }
    
    // user did not press the link button in time, you restart the process and try again
    func bridgeAuthenticatorDidTimeout(authenticator: BridgeAuthenticator) {
        
    }
}

Heartbeat

Setup Heartbeat for resource updates.

    
let bridgeAccessConfig= BridgeAccessConfig(bridgeId: "YOUR_BRIDGE_ID", ipAddress: "YOUR_BRIDGE_IP", username: "YOUR_BRIDGE_USERNAME")
let swiftyHue: SwiftyHue = SwiftyHue();

swiftyHue.setBridgeAccessConfig(bridgeAccessConfig)
swiftyHue.setLocalHeartbeatInterval(10, forResourceType: .Lights)
swiftyHue.setLocalHeartbeatInterval(10, forResourceType: .Groups)
swiftyHue.setLocalHeartbeatInterval(10, forResourceType: .Rules)
swiftyHue.setLocalHeartbeatInterval(10, forResourceType: .Scenes)
swiftyHue.setLocalHeartbeatInterval(10, forResourceType: .Schedules)
swiftyHue.setLocalHeartbeatInterval(10, forResourceType: .Sensors)
swiftyHue.setLocalHeartbeatInterval(10, forResourceType: .Config)

swiftyHue.startHeartbeat()

Register for Update Events.

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.lightChanged), name: ResourceCacheUpdateNotification.LightsUpdated.rawValue, object: nil)

Use the resource cache.

if let cache = swiftyHue.resourceCache {
    
    // Dict of lights [String: Light]. Keys are the light identifiers.
    let lights = cache.lights
}

Send API

You can use the SendAPI to send requests to the bridge. For example recall a Scene or create a group.

let sendAPI = swiftyHue.brideSendAPI

More coming soon...

Resource API

You can use the resourceAPI to request resources from the bridge. For example all groups.

let resourceAPI = swiftyHue.resourceAPI

resourceAPI.fetchGroups { (result) in

    guard let groups = result.value else {
        //...
        return
    }
    
    //...
}

Generate documentation

Install jazzy:

$ [sudo] gem install jazzy

Run generate script:

$ ./generate_doc.sh

Log

We use 'Log' for Logging. Log` is a powerful logging framework that provides built-in themes and formatters, and a nice API to define your owns.

Get the most out of Log by installing XcodeColors and KZLinkedConsole

Contributing

We'd love to see your ideas for improving this repo! The best way to contribute is by submitting a pull request. We'll do our best to respond to your patch as soon as possible. You can also submit a issue if you find bugs. :octocat:

Please make sure to follow our general coding style and add test coverage for new features!

Needs

You need Carthage to work on the SwiftyHue Project. If you have Carthage installed just run

$ carthage bootstrap

in the root directory of the project. Remember to build the SwiftyHue framework targets to run the example application targets.

Made with SwiftyHue

swiftyhue's People

Contributors

choas avatar cliffspencer avatar j3y-s avatar nilslattek avatar samuelclay avatar spriter avatar zorro2b avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.