Adding a new device type

From ago control wiki
Revision as of 17:47, 22 January 2014 by JoakimL (Talk | contribs)

Jump to: navigation, search

Contents

Tutorial for adding a new device type

This tutorial will take you through all steps and files needed to add a new device type to aGo control. As an example the "Computer" device type used by Wake-on-LAN (WOL) will be used.

Add to schema

File name: conf/schema.yaml

 computer:
   name: General computer (for WOL)
   description: A computer
   commands: ["on"]

Add to main web script

Add your device type to supported_devices
File name: core/rpc/html/js/app.js

var supported_devices = [ "switch", "dimmer", "binarysensor", "dimmerrgb", "multilevelsensor",
"scenario", "drapes", "brightnesssensor", "powermeter", "energysensor", "humiditysensor", "phone",
"pushbutton", "placeholder", "temperaturesensor", "energymeter", "squeezebox", "computer" ];

HTLM template for device

This template is a copy of switch.in.html. The OFF-command is obviously taken away and the icon is changed from icon-lamp to icon-keyboard.
N.B! The file name has to be the same as the device type.
File name: core/rpc/html/templates/devices/computer.in.html

 <div class="four columns grid-item device"  data-bind="attr: {'data-uuid': uuid}"> 
	<div class="row">
		<div class="three columns">
			<div class="pretty large primary btn grid-item-icon handle">
				<i class="icon-keyboard" data-bind="click: showDetails"></i>
			</div>
		</div>
		<div class="nine columns">
			<div class="grid-item-header">
				<h3 data-bind="text: name, if: name"></h3>
				<ko opts="if: room ">
					<p class="room"><i class="icon-location"></i><span data-bind="text: room"></span></p>
				</ko>
                                <p class="info"><i class="icon-info"></i>
                                        <ko opts="if: state() == 0">
                                                <_span data-translateable="true">OFF</_span>
                                        </ko>
                                        <ko opts="if: state() == 255">
                                                <_span data-translateable="true">ON</_span>
                                        </ko>
                                </p>
			</div>
		</div>
	</div>
	<div class="row grid-item-controls">
		<div class="six columns">
		    <ko opts="if: state ">
                <_div data-translateable="true" class="cmd-btn pretty medium default btn btn-full grid-command" data-bind="click: turnOn" data-value="on">ON</_div>
            </ko>
            <ko opts="ifnot: state ">
                <_div data-translateable="true" class="cmd-btn pretty medium primary btn btn-full grid-command" data-bind="click: turnOn" data-value="on">ON</_div>
            </ko>
		</div>
	</div>
 </div>

debian install script

configobj.py and pinger.py are additional programs used by this example, likelly irrelevant for other device types.
File name: debian/agocontrol-wake_on_lan.install

lib/systemd/system/agowake_on_lan.service
opt/agocontrol/bin/agowake_on_lan.py
opt/agocontrol/bin/configobj.py
opt/agocontrol/bin/pinger.py 

debian install

Add section to the main install script

Package: agocontrol-wake_on_lan
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, libagoclient1.0
Description: Wake on LAN support

Update makefile

Add the device directory (wake_on_lan) to the directory list
File name: devices/Makefile

DIRS = enocean3 blinkm chromoflex firmata i2c irtrans_ethernet kwikwai mediaproxy rain8net 
zwave 1wire syslog enigma2 asterisk agoapc agojointspace raspiGPIO raspi1wGPIO raspiMCP3xxxGPIO
gc100 onkyo x10 webcam wake_on_lan

Device driver

Main logic

Finally, a device driver that uses the new device type. This is a plain vanilla task as outlined in Example Device.
File name: devices/wake_on_lan/agowake_on_lan.py

    client.addDevice(deviceId, "computer")

Config file

File name: devices/wake_on_lan/wake_on_lan.conf

[wake_on_lan]
debug=false

[Computers]
	[[DCErouter]]
	name=DCErouter
	mac=01:14:DD:D1:B9:5D
	host=dcerouter

	[[Test]]
	name=test
	mac=00:01:02:03:04:FF
	host=thisshouldfail

New make file

File name: devices/wake_on_lan/Makefile

all:

install:
	$(INSTALL_DIR) $(BINDIR)
	$(INSTALL_PROGRAM) agowake_on_lan.py $(BINDIR)
	$(INSTALL_PROGRAM) pinger.py $(BINDIR)
	$(INSTALL_PROGRAM) configobj.py $(BINDIR)

clean:


Service definition

File name: conf/systemd/agowake_on_lan.service

[Unit]
Description=ago control Wake on LAN handler

[Service]
ExecStart=/opt/agocontrol/bin/agowake_on_lan.py
WorkingDirectory=/opt/agocontrol/bin
StandardOutput=syslog
StandardError=syslog
Restart=always
RestartSec=2
User=root

[Install]
WantedBy=multi-user.target
Personal tools