Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sebastian.boehler/philipshue

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sebastian.boehler/philipshue

Wrapper around the PhilipsHue REST API

  • 1.0.5
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Philips Hue API Wrapper

This is a Typescript package that provides a simple and easy-to-use wrapper around the Philips Hue API. It allows you to control your Philips Hue lights and other devices from your code.

Installation

npm install @sebastianboehler/philipshue@latest --registry=https://npm.pkg.github.com/

Usage

To use the package, import it in your code and create a new instance of the PhilipsHue class:

import PhilipsHue from 'philipsHue'
import express from 'express.js

const port = process.env.PORT || 3000
const redirect_path = `/philipsHue_callback`

const myPhilips = new PhilipsHue({
  redirect_uri: `http://localhost:${port}${redirect_path}`,
  CLIENT_ID: 'YOUR_CLIENT_ID',
  CLIENT_SECRET: 'YOUR_CLIENT_SECRET'
})

const app = express()

app.get('/login', (req, res) => {
  const oAuthUrl = myPhilips.getOAuthUrl()
  res.redirect(oAuthUrl)
});

app.get(redirect_path, async (req, res) => {
  const { code } = req.query
  if (!code) {
    res.json({
      success: false
    })
    return
  }
  const success = await myPhilips.getAccessToken(code.toString())
  if (success) = await myPhilips.createWhitelistUser()
  res.json({
    success
  })
});

app.get('/scenes', async (req, res) => {
  const scenes = await myPhilips.getScenesV2()
  res.json(scenes)
});

app.listen(port, () => {
  console.log(`Sever listening on port ${port}`)
});

Available methods

  • getOAuthurl() returns your oAuth url
  • getAccessToken(code: string, grant_type = 'authorization_code') stores access token, refresh token and expiration Date inside the class
  • refreshToken() renews your access token
  • createWhitelistUser whitelist your user
  • setLightState(id: string | number, state: LightStateV1) lets you change the states of your light, turn them on/off, change color etc.
  • shouldRefreshAccessToken(aboutToExpireInNextSeconds: number = 90) returns true if your access token is about to expire in next x seconds
  • setGroupState(id: string | number, state: LightStateV1 | {scene: string}) let you control whole groups in your home
  • getGroups() returns all groups in your home
  • getLightsV2() returns all lights in your home
  • getGroupsV2() returns all groups in your home
  • getScenesV2() returns all scenes
  • getSceneDetailsV2() get a scene by its id
  • getSmartScenesV2() returns all smart scenes
  • activateSceneV2(id: string) activate a scene
  • activateSmartSceneV2(id: string) activates a smart scene

Please note that not all methods from the V1 and V2 API are supported yet. I'll try to update it as often as possible and extended it by the missing functions.

Keywords

FAQs

Package last updated on 07 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc