I've been working on a home automation plugin for freevo and I need a bit of help. I have the code mostelty done, but I'm having trouble making submenus. What I would like is a menu with a list of rooms, then a sub menu with items in those rooms, then a sub menu with options to control the devices in the room. Here is my code so far, please keep in mind I'm new to python:

#**** local_confg.py ****

plugin.activate('automatedhouse')
HA_ITEMS = [ ("Living Room",(
              ("Corner Light",(
                      ("On","heyu on A1"),
                      ("Off","heyu off A1"),
                      ("Dim","command code goes here")
                      )),
              ("Ceiling Fan",(
                      ("On","command"),
                      ("Off","command")
                      )),
              ("TV",(
                      ("On","command"),
                      ("Off","command")
                      ))
                      )),
           ("Bedroom",(
              ("Ceiling Lights",(
                      ("On","command"),
                      ("Off","command"),
                      ("Dim","command")
                      )),
              ("Table Lamp",(
                      ("On","command"),
                      ("Off","command"),
                      ("Dim","command")
                      ))
                      )) ]

#**** automatedhome.py ****

import os
import sys
import menu
import config

from gui import ConfirmBox
from item import Item
from plugin import MainMenuPlugin

class HomeAutomationItem(Item):
def __init__(self, parent):
Item.__init__(self,parent)
self.name = _( 'Home Automation' )
def config(self):
return [('HA_ITEMS',
[ ("Living Room", "Corner Light","On,Off,Dim"),
("Bedroom", "Ceiling Lights","On,Off,Dim") ],
"Home automation items")]
def actions(self):
items = [(self.createMenu, _('Home Automation'))]
return items
def createMenu(self, arg=None, menuw=None):
ha_menu_items=[]
for room in config.HA_ITEMS:
ha_menu_items+=[menu.MenuItem(room[0])]
for device in room[1]:
ha_menu_items+=[menu.MenuItem(device[0])]
for control in device[1]:
ha_menu_items+=[menu.MenuItem(control[0],lambda arg=None, menuw=None: os.system(control[1]))]
ha_menu=menu.Menu("Home Automation", ha_menu_items)
menuw.pushmenu(ha_menu)
menuw.refresh()
class PluginInterface(MainMenuPlugin):
def items(self, parent):
return [ HomeAutomationItem(parent) ]






-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Freevo-devel mailing list
Freevo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to