def __init__(self): ''' Load initial RFXtrx configuration from rfxtrx.conf ''' config_file = config_to_location('rfxtrx.conf') config = ConfigParser.RawConfigParser() config.read(os.path.join(config_file)) self.port = config.get("serial", "port") # Get broker information (ZeroMQ) self.coordinator_host = config.get("coordinator", "host") self.coordinator_port = config.getint("coordinator", "port") self.loglevel = config.get('general', 'loglevel') self.id = config.get('general', 'id') callbacks = {'custom': self.cb_custom} self.pluginapi = pluginapi.PluginAPI(self.id, 'RFXtrx', broker_host=self.coordinator_host, broker_port=self.coordinator_port, **callbacks) log = Logging("RFXtrx", console=True) log.set_level(self.loglevel) self.protocol = RFXtrxProtocol(self, log) myserial = SerialPort (self.protocol, self.port, reactor) myserial.setBaudRate(38400) reactor.run(installSignalHandlers=0) return True
class MainWrapper: """ This is the main wrapper for HouseAgent, this class takes care of starting all important core components for HouseAgent such as the event engine, network coordinator etc. """ def __init__(self): from houseagent.utils.generic import get_configurationpath self.config_path = get_configurationpath() if os.path.exists(os.path.join(self.config_path, "HouseAgent.conf")): config = ConfigParser.RawConfigParser() config.read(os.path.join(self.config_path, "HouseAgent.conf")) self.port = config.getint("webserver", "port") self.loglevel = config.get("general", "loglevel") # Get broker information (RabbitMQ) self.broker_host = config.get("broker", "host") self.broker_port = config.getint("broker", "port") self.broker_user = config.get("broker", "username") self.broker_pass = config.get("broker", "password") self.broker_vhost = config.get("broker", "vhost") else: print "Configuration file not found! Make sure the configuration file is placed in the proper directory. For *nix: /etc/HouseAgent/, for Windows C:\Programdata\HouseAgent" sys.exit() def start(self): self.log = Logging("Main") self.log.set_level(self.loglevel) self.log.debug("Starting HouseAgent database layer...") database = Database(self.log) self.log.debug("Starting HouseAgent coordinator...") coordinator = Coordinator( "houseagent", self.broker_host, self.broker_port, self.broker_user, self.broker_pass, self.broker_vhost, database=database, ) self.log.debug("Starting HouseAgent event handler...") event_handler = EventHandler(coordinator, database) self.log.debug("Starting HouseAgent web server...") Web(self.port, coordinator, event_handler, database) if os.name == "nt": reactor.run(installSignalHandlers=0) else: reactor.run() return True
def start(self): self.log = Logging("Main") self.log.set_level(self.loglevel) self.log.debug("Starting HouseAgent database layer...") database = Database(self.log) self.log.debug("Starting HouseAgent coordinator...") coordinator = Coordinator( "houseagent", self.broker_host, self.broker_port, self.broker_user, self.broker_pass, self.broker_vhost, database=database, ) self.log.debug("Starting HouseAgent event handler...") event_handler = EventHandler(coordinator, database) self.log.debug("Starting HouseAgent web server...") Web(self.port, coordinator, event_handler, database) if os.name == "nt": reactor.run(installSignalHandlers=0) else: reactor.run() return True
def __init__(self): ''' Load initial Astral configuration from Astral.conf ''' config_file = config_to_location('Astral.conf') self.config = ConfigParser.RawConfigParser() self.config.read(os.path.join(config_file)) # Get broker information (ZeroMQ) self.coordinator_host = self.config.get("coordinator", "host") self.coordinator_port = self.config.getint("coordinator", "port") self.loglevel = self.config.get('general', 'loglevel') self.log = Logging("Astral", console=True) self.log.set_level(self.loglevel) self.id = self.config.get('general', 'id') callbacks = {} self.pluginapi = pluginapi.PluginAPI(self.id, 'Astral', broker_host=self.coordinator_host, broker_port=self.coordinator_port, **callbacks) self.pluginapi.ready() c = CronSchedule("* * * * *") s = ScheduledCall(f=self.fire_minute) s.start(c) reactor.run() return True
def __init__(self): ''' Load initial Youless configuration from youless.conf ''' from houseagent.utils.generic import get_configurationpath config_path = "/etc/houseagent" config = ConfigParser.RawConfigParser() config.read(os.path.join(config_path, 'youless.conf')) self.addr = config.get("net", "addr") # Get broker information (RabbitMQ) self.broker_host = config.get("broker", "host") self.broker_port = config.getint("broker", "port") self.broker_user = config.get("broker", "username") self.broker_pass = config.get("broker", "password") self.broker_vhost = config.get("broker", "vhost") self.logging = config.getboolean('general', 'logging') self.log = Logging('Youless') self.id = config.get('general', 'id')
class AstralWrapper(object): def __init__(self): ''' Load initial Astral configuration from Astral.conf ''' config_file = config_to_location('Astral.conf') self.config = ConfigParser.RawConfigParser() self.config.read(os.path.join(config_file)) # Get broker information (ZeroMQ) self.coordinator_host = self.config.get("coordinator", "host") self.coordinator_port = self.config.getint("coordinator", "port") self.loglevel = self.config.get('general', 'loglevel') self.log = Logging("Astral", console=True) self.log.set_level(self.loglevel) self.id = self.config.get('general', 'id') callbacks = {} self.pluginapi = pluginapi.PluginAPI(self.id, 'Astral', broker_host=self.coordinator_host, broker_port=self.coordinator_port, **callbacks) self.pluginapi.ready() c = CronSchedule("* * * * *") s = ScheduledCall(f=self.fire_minute) s.start(c) reactor.run() return True def fire_minute(self): city = Astral()[self.config.get("astral", "city")] sun = city.sun() self.log.debug(sun) delta = int(time.time()) - int(time.mktime(sun["sunrise"].timetuple())) + 30 if delta > 0: self.log.info("Sunrise was {0} minutes ago".format(delta // 60)) else: self.log.info("Sunrise in {0} minutes".format(-(delta // 60))) self.pluginapi.value_update("1", {"Sunrise delta": delta // 60}) delta = int(time.time()) - int(time.mktime(sun["sunset"].timetuple())) + 30 if delta > 0: self.log.info("Sunset was {0} minutes ago".format(delta // 60)) else: self.log.info("Sunset in {0} minutes".format(-(delta // 60))) self.pluginapi.value_update("1", {"Sunset delta": delta // 60}) delta = int(time.time()) - int(time.mktime(sun["dawn"].timetuple())) + 30 if delta > 0: self.log.info("Dawn was {0} minutes ago".format(delta // 60)) else: self.log.info("Dawn in {0} minutes".format(-(delta // 60))) self.pluginapi.value_update("1", {"Dawn delta": delta // 60}) delta = int(time.time()) - int(time.mktime(sun["dusk"].timetuple())) + 30 if delta > 0: self.log.info("Dusk was {0} minutes ago".format(delta // 60)) else: self.log.info("Dusk in {0} minutes".format(-(delta // 60))) self.pluginapi.value_update("1", {"Dusk delta": delta // 60}) delta = int(time.time()) - int(time.mktime(sun["noon"].timetuple())) + 30 if delta > 0: self.log.info("Solar noon was {0} minutes ago".format(delta // 60)) else: self.log.info("Solar noon in {0} minutes".format(-(delta // 60))) self.pluginapi.value_update("1", {"Solar noon delta": delta // 60})
class YoulessWrapper(): def __init__(self): ''' Load initial Youless configuration from youless.conf ''' from houseagent.utils.generic import get_configurationpath config_path = "/etc/houseagent" config = ConfigParser.RawConfigParser() config.read(os.path.join(config_path, 'youless.conf')) self.addr = config.get("net", "addr") # Get broker information (RabbitMQ) self.broker_host = config.get("broker", "host") self.broker_port = config.getint("broker", "port") self.broker_user = config.get("broker", "username") self.broker_pass = config.get("broker", "password") self.broker_vhost = config.get("broker", "vhost") self.logging = config.getboolean('general', 'logging') self.log = Logging('Youless') self.id = config.get('general', 'id') def start(self): ''' Function that starts the Youless plug-in. It handles the creation of the plugin connection. ''' callbacks = {'custom': self.cb_custom} self.pluginapi = pluginapi.PluginAPI(self.id, 'Youless', broker_host=self.broker_host, broker_port=self.broker_port, **callbacks) self.protocol = YoulessProtocol(self, self.log) self.pluginapi.ready() # log.startLogging(open('/var/log/houseagent/youless.log','w')) self.log.debug("Youless plugin ready") lc = LoopingCall(self.protocol.read_device) lc.start(60) reactor.run(installSignalHandlers=0) return True def cb_custom(self, action, parameters): ''' This function is a callback handler for custom commands received from the coordinator. @param action: the custom action to handle @param parameters: the parameters passed with the custom action ''' if action == 'get_devices': print 'get_devices' devices = {} for dev in self.protocol._devices: devices[dev.id] = [dev.type, dev.subtype] d = defer.Deferred() d.callback(devices) return d