npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

alexa-simple-smart-home-controller

v0.0.67

Published

**This library is deprecated.**

Downloads

6

Readme

Imporant Notice:

This library is deprecated.

This library currently maintenance on below repository.

https://github.com/secual/alexa-smart-home-controller

alexa-simple-smart-home-controller (beta)

This package make your smart home skill code simpler.

** Important: This package is now Work in progress.

Concept

  • Be Readable
  • Can be more focus to implement a logic of device cloud
  • Implement simplify

install

npm install alexa-simple-smart-home-controller

or

yarn add alexa-simple-smart-home-controller

example

import SmartHomeController from 'alexa-simple-smart-home-controller'

// Yous have to implement a logic of your device cloud
import * as DeviceCloud from './deviceCloud'

// @ts-ignore
export const handler = async (event, context) => {
  console.log(event, context)
  console.log(JSON.stringify(event))

  const controller = new SmartHomeController(
    event,
    DeviceCloud.discoverFunc,
    DeviceCloud.searchFunc
  )

  const response = await controller.run()
  return response
};

How to implement your Smart Home Skill with alexa-simple-smart-home-controller

Step1: implement device discovery function

Smart home skill has to discover user devices from device cloud. You can implement discovery logic as DeviceSearchFunction object. This object needs for creating SmartHomeController instance.

 export type DeviceSearchFunction = (
  event: Device.ControllerRequestEvent
) => Promise<Device.IUserDevice>;

Step2: implement device object

In this package, Requesting to the device cloud is used through the UserDevice object. For example, when your skill request to the light device, You will implement a device object for the light device.

class LightDevice extends Device.UserDevice {
  public async sendSignal(): Promise<Device.Response | {}> {
    const header = this.event.directive.header

    switch (header.name) {
      case 'SetBrightness':
          // Requesting for your light device to the device cloud here.
          break;
      case 'AdjustBrightness':
          // Requesting for your light device to the device cloud here.
        break;
      default:
        break;
    }
    const r: Device.Response = {
      event: {
        header: {
          namespace: 'Alexa',
          name: 'Response',
          messageId: this.event.directive.header.messageId + '-R',
          payloadVersion: '3',
          correlationToken: 'token1'
        },
        endpoint: this.event.directive.endpoint,
        payload: 'hoge' 
      },
      context: {
        properties: [
          {
            namespace: header.namespace,
            name: header.name,
            value: 'ON',
            timeOfSample: 'test',
            uncertaintyInMilliseconds: 50
          }
        ]
      }
    }
    return r
  }
}

Step3: implement search device function

This package is made for skill can respond utterances for several types of devices. So You have to find target device from user utterance. DeviceSearchFunction object is to do so.

Easiest way is check device category. (below)

export const searchFunc: Device.DeviceSearchFunction = async (event) => {
  // @ts-ignore
  return DeviceMap[event.directive.header.namespace](event)
}

export const DeviceMap = {
  'Alexa.BrightnessController': (event: Device.ControllerRequestEvent) => {
    return new LightDevice(event)
  },
  'Alexa.ChannelController': (event: Device.ControllerRequestEvent) => {
    return new TvDevice(event)
  }
}