/keiko

keiko is Python and Web API clients for 警子ちゃん.

Primary LanguagePythonOtherNOASSERTION

keiko

https://badge.fury.io/py/keiko.png https://travis-ci.org/lanius/keiko.png https://coveralls.io/repos/lanius/keiko/badge.png

keiko is Python and Web API clients for Keiko-chan.

Installation

keiko can be installed via pip or easy_install:

$ pip install keiko

Or:

$ easy_install keiko

Usage

Firstly, setup Keiko-chan and assign IP address.

Python

Specify the address of Keiko-chan and instantiate the client:

>>> import keiko
>>> address = '192.168.1.2'  # example address of Keiko-chan
>>> client = keiko.Client(address)

Control the lamps:

>>> client.lamps.green.on()  # turns on the lamp
>>> client.lamps.green.status
'on'
>>> client.lamps.green.off()  # turns off the lamp
>>> client.lamps.green.status
'off'
>>> client.lamps.yellow.blink()  # blinks the lamp
>>> client.lamps.yellow.status
'blink'
>>> client.lamps.red.quickblink()  # blinks the lamp quickly
>>> client.lamps.red.status
'quickblink'
>>> client.lamps.off()  # turns off the all lamps

With delay and duration time:

>>> client.lamps.red.on(wait=2, time=4)  # wait 2 second, light 4 seconds

Control the buzzer:

>>> client.buzzer.on()  # turns on the buzzer
>>> client.buzzer.status
'continuous'
>>> client.buzzer.off()  # turns off the buzzer
>>> client.buzzer.status
'off'

Control the direct inputs and outputs:

>>> client.di.status
{1: 'off', 2: 'off', 3: 'off', 4: 'off'}
>>> client.do.status
{1: 'off', 2: 'off', 3: 'off', 4: 'off'}
>>> client.do(2).on()
>>> client.do(2).status
'on'
>>> client.do.status
{1: 'off', 2: 'on', 3: 'off', 4: 'off'}

Control the voices:

>>> client.voices.status
'stop'
>>> client.voices(1).play()  # plays #1 voice
>>> client.voices.stop()  # stops the voice
>>> client.voices(5).play(3)  # plays #5 voice 3 times
>>> client.voices.stop()
>>> client.voices(10).repeat()  # plays #10 voice repeatedly
>>> client.voices.stop()

Web API

Specify the address of Keiko-chan and run Web API server:

$ keiko 192.168.1.2
 * Running on http://127.0.0.1:8080/

Pass optional parameters to the server:

$ keiko 192.168.1.2 --server myhost:5000
 * Running on http://myhost:5000/

Control the lamps:

$ curl http://127.0.0.1:8080/lamps
{
  "lamps": {
    "green": "off",
    "red": "off",
    "yellow": "off"
  }
}

$ curl http://127.0.0.1:8080/lamps/green/on
{
  "result": "success"
}

$ curl http://127.0.0.1:8080/lamps/green
{
  "lamps": {
    "green": "on"
  }
}

With delay and duration time:

$ curl http://127.0.0.1:8080/lamps/yellow/on?wait=2&time=4
{
  "result": "success"
}

Control the buzzer:

$ curl http://127.0.0.1:8080/buzzer
{
  "buzzer": "off"
}

$ curl http://127.0.0.1:8080/buzzer/on
{
  "result": "success"
}

Control the direct inputs and outputs:

$ curl http://127.0.0.1:8080/di
{
  "di": {
    "1": "off",
    "2": "off",
    "3": "off",
    "4": "off"
  }
}

$ curl http://127.0.0.1:8080/do
{
  "do": {
    "1": "off",
    "2": "off",
    "3": "off",
    "4": "off"
  }
}

$ curl http://127.0.0.1:8080/do/2/on
{
  "result": "success"
}

Control the voices:

$ curl http://127.0.0.1:8080/voices
{
  "voices": "stop"
}

$ curl http://127.0.0.1:8080/voices/10/play
{
  "result": "success"
}

Caveats

This module is unofficial and tested with only Keiko-chan 4G+ (DN-1510GL) yet. For more details, see the official documentation.