def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) if not self.is_enabled(): return self.data_directory = config_utils.get_config_param(config, PLUGIN_NAME, "data_directory", self.logger) if self.data_directory is None: return user_names = config_utils.get_config_param(config, PLUGIN_NAME, "users", self.logger) if user_names is None: return user_names = user_names.split(",") self.users = {} for user in user_names: if user not in config.sections(): print user + " section is missing" return if "mac" not in config.options(user): print "mac property is missing from the " + user + " section" return self.users[user] = {'mac': config.get(user, "mac"), 'is_home': False, 'last_seen': 0.0} self.users_present = True self.data_logger = presence_logger.PresenceLogger(self.data_directory, "user_data", user_names) self._initialized = True
def __init__(self, config): self._initialized = False if not config_utils.check_config_section(config, CONFIG_SEC_NAME): return enabled = config_utils.get_config_param(config, CONFIG_SEC_NAME, "enabled", logger) if enabled is None: return if enabled.lower() != "true": logger.info("Twilio interface disabled") return sid = config_utils.get_config_param(config, CONFIG_SEC_NAME, "sid", logger) if sid is None: return auth = config_utils.get_config_param(config, CONFIG_SEC_NAME, "auth", logger) if auth is None: return self.number = config_utils.get_config_param(config, CONFIG_SEC_NAME, "number", logger) if self.number is None: return self.client = TwilioRestClient(sid, auth) self._initialized = True
def __init__(self, config): self._initialized = False if not config_utils.check_config_section( config, CONFIG_SEC_NAME ): return enabled = config_utils.get_config_param( config, CONFIG_SEC_NAME, "enabled", logger) if enabled is None: return if enabled.lower() != "true": logger.info("Twilio interface disabled") return sid = config_utils.get_config_param( config, CONFIG_SEC_NAME, "sid", logger) if sid is None: return auth = config_utils.get_config_param( config, CONFIG_SEC_NAME, "auth", logger) if auth is None: return self.number = config_utils.get_config_param( config, CONFIG_SEC_NAME, "number", logger) if self.number is None: return self.client = TwilioRestClient(sid, auth) self._initialized = True
def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) self.mutex = Lock() self.current_temps = {} if not self.is_enabled(): return self.data_directory = config_utils.get_config_param( config, PLUGIN_NAME, "data_directory", self.logger) if self.data_directory is None: return self.device_names = self.og.spark.get_device_names( postfix="_floor_temp") for device in self.device_names: self.current_temps[device] = None self.current_average_temperature = 0.0 # Create the data directory if it does not exist if not os.path.exists(self.data_directory): os.makedirs(self.data_directory) self.data_logger = value_logger.ValueLogger(self.data_directory, "temperatures", self.device_names) self._initialized = True
def __init__(self, object_group, config): Plugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) self.set_point_lock = Lock() if not self.is_enabled(): return self.set_point_filename = config_utils.get_config_param( config, PLUGIN_NAME, "set_point_file", self.logger) if self.set_point_filename is None: return # Create the set point file if it does not yet exist self.set_point_config = ConfigParser.ConfigParser() self.set_point_section = 'set_points' self.user_rule_section = 'rules' self.zones = {} self.rules = {} # Load and verify the set point file. self.load_set_point_file() self._initialized = True
def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) self.mutex = Lock() self.current_temps = {} if not self.is_enabled(): return self.data_directory = config_utils.get_config_param(config, PLUGIN_NAME, "data_directory", self.logger) if self.data_directory is None: return self.device_names = self.og.spark.get_device_names(postfix="_floor_temp") for device in self.device_names: self.current_temps[device] = None self.current_average_temperature = 0.0 # Create the data directory if it does not exist if not os.path.exists(self.data_directory): os.makedirs(self.data_directory) self.data_logger = value_logger.ValueLogger(self.data_directory, "temperatures", self.device_names) self._initialized = True
def verify_common_plugin_config_items(self): if not config_utils.check_config_section(self.config, self.name, self.logger): self._enabled = False else: enabled = config_utils.get_config_param(self.config, self.name, "enabled", self.logger) if enabled is None: self.logger.warning("Section: '" + self.name + "' is missing the 'enabled' property in the config file") self._enabled = False elif enabled.lower() != "true": self._enabled = False
def verify_common_plugin_config_items(self): if not config_utils.check_config_section(self.config, self.name, self.logger): self._enabled = False else: enabled = config_utils.get_config_param(self.config, self.name, "enabled", self.logger) if enabled is None: self.logger.warning( "Section: '" + self.name + "' is missing the 'enabled' property in the config file") self._enabled = False elif enabled.lower() != "true": self._enabled = False
def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) # Get parameters from the config file if not self.is_enabled(): return self.disable_commands = config_utils.get_config_param(config, PLUGIN_NAME, "disable_commands", self.logger) if self.disable_commands is None or self.disable_commands.lower() != "true": self.disable_commands = False else: self.disable_commands = True self.logger.warning("COMMANDS TO FURNACE CONTROLLER DISABLED") data_directory = config_utils.get_config_param(config, PLUGIN_NAME, "data_directory", self.logger) if data_directory is None: return address = config_utils.get_config_param(config, PLUGIN_NAME, "address", self.logger) if address is None: return command_port = config_utils.get_config_param(config, PLUGIN_NAME, "command_port", self.logger) if command_port is None: return response_port = config_utils.get_config_param(config, PLUGIN_NAME, "response_port", self.logger) if response_port is None: return # Get the device pins from the config file self.zones = self.og.thermostat_plugin.get_device_names() self.pins = {} for device in self.zones: pin_str = config_utils.get_config_param(config, PLUGIN_NAME, device, self.logger) if pin_str is None: return self.pins[device] = int(pin_str) # Furnace controller interface self.furnace_controller = udp_interface.UDPSocket(address, response_port, command_port, PLUGIN_NAME + "_inf") if not self.furnace_controller.is_initialized(): self.logger.error( "Failed to initialize furnace_controller" ) return self.furnace_controller.start() # Setup data logger self.data_logger = presence_logger.PresenceLogger(data_directory, "furnace", self.zones) self._initialized = True
def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) self.mutex = Lock() if not self.is_enabled(): return self.data_directory = config_utils.get_config_param(config, PLUGIN_NAME, "data_directory", self.logger) if self.data_directory is None: return if "collect_period" not in config.options(PLUGIN_NAME): self.collect_period = 60 else: self.collect_period = float(config.get(PLUGIN_NAME, "collect_period", True)) self.data_logger = value_logger.ValueLogger(self.data_directory, "memory", "Percent Used") self._initialized = True
def __init__(self, object_group, config): Plugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) self.set_point_lock = Lock() if not self.is_enabled(): return self.set_point_filename = config_utils.get_config_param(config, PLUGIN_NAME, "set_point_file", self.logger) if self.set_point_filename is None: return # Create the set point file if it does not yet exist self.set_point_config = ConfigParser.ConfigParser() self.set_point_section = 'set_points' self.user_rule_section = 'rules' self.zones = {} self.rules = {} # Load and verify the set point file. self.load_set_point_file() self._initialized = True
def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) self.mutex = Lock() if not self.is_enabled(): return self.monitor_device_name = \ config_utils.get_config_param(config, PLUGIN_NAME, "monitor_device_name", self.logger) if self.monitor_device_name is None: return self.breach_number = config_utils.get_config_param(config, PLUGIN_NAME, "breach_number", self.logger) if self.breach_number is None: return self.num_zones = config_utils.get_config_param(config, PLUGIN_NAME, "num_zones", self.logger) if self.num_zones is None: return self.num_zones = int( self.num_zones ) data_directory = config_utils.get_config_param(config, PLUGIN_NAME, "data_directory", self.logger) if data_directory is None: return address = config_utils.get_config_param(config, PLUGIN_NAME, "address", self.logger) if address is None: return port = config_utils.get_config_param(config, PLUGIN_NAME, "port", self.logger) if port is None: return self.zones = [] zone_names = [] for zone in range(self.num_zones): zone_index = "zone_" + str(zone) if zone_index not in config.options(PLUGIN_NAME): print zone_index + " property missing from " + PLUGIN_NAME + " section" return self.zones.append({ 'last': time.localtime(), 'state': CLOSED, 'name': config.get(PLUGIN_NAME, zone_index)}) zone_names.append(config.get(PLUGIN_NAME, zone_index)) if "collect_period" not in config.options(PLUGIN_NAME): self.collect_period = 10 else: self.collect_period = float(config.get(PLUGIN_NAME, "collect_period", True)) # Setup data data_logger self.data_logger = presence_logger.PresenceLogger(data_directory, "security", zone_names) # Setup UDP interface self.udp = udp_interface.UDPSocket(address, port, port, PLUGIN_NAME + "_inf") if not self.udp.is_initialized(): return self.udp.start() self.security_state = SecurityState(object_group=self.og, logger=self.logger, breach_number=self.breach_number) self.sensor_states = "" self._initialized = True
def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) self.mutex = Lock() if not self.is_enabled(): return self.monitor_device_name = \ config_utils.get_config_param(config, PLUGIN_NAME, "monitor_device_name", self.logger) if self.monitor_device_name is None: return self.breach_number = config_utils.get_config_param( config, PLUGIN_NAME, "breach_number", self.logger) if self.breach_number is None: return self.num_zones = config_utils.get_config_param(config, PLUGIN_NAME, "num_zones", self.logger) if self.num_zones is None: return self.num_zones = int(self.num_zones) data_directory = config_utils.get_config_param(config, PLUGIN_NAME, "data_directory", self.logger) if data_directory is None: return address = config_utils.get_config_param(config, PLUGIN_NAME, "address", self.logger) if address is None: return port = config_utils.get_config_param(config, PLUGIN_NAME, "port", self.logger) if port is None: return self.zones = [] zone_names = [] for zone in range(self.num_zones): zone_index = "zone_" + str(zone) if zone_index not in config.options(PLUGIN_NAME): print zone_index + " property missing from " + PLUGIN_NAME + " section" return self.zones.append({ 'last': time.localtime(), 'state': CLOSED, 'name': config.get(PLUGIN_NAME, zone_index) }) zone_names.append(config.get(PLUGIN_NAME, zone_index)) if "collect_period" not in config.options(PLUGIN_NAME): self.collect_period = 10 else: self.collect_period = float( config.get(PLUGIN_NAME, "collect_period", True)) # Setup data data_logger self.data_logger = presence_logger.PresenceLogger( data_directory, "security", zone_names) # Setup UDP interface self.udp = udp_interface.UDPSocket(address, port, port, PLUGIN_NAME + "_inf") if not self.udp.is_initialized(): return self.udp.start() self.security_state = SecurityState(object_group=self.og, logger=self.logger, breach_number=self.breach_number) self.sensor_states = "" self._initialized = True
def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) # Get parameters from the config file if not self.is_enabled(): return self.disable_commands = config_utils.get_config_param( config, PLUGIN_NAME, "disable_commands", self.logger) if self.disable_commands is None or self.disable_commands.lower( ) != "true": self.disable_commands = False else: self.disable_commands = True self.logger.warning("COMMANDS TO FURNACE CONTROLLER DISABLED") data_directory = config_utils.get_config_param(config, PLUGIN_NAME, "data_directory", self.logger) if data_directory is None: return address = config_utils.get_config_param(config, PLUGIN_NAME, "address", self.logger) if address is None: return command_port = config_utils.get_config_param(config, PLUGIN_NAME, "command_port", self.logger) if command_port is None: return response_port = config_utils.get_config_param(config, PLUGIN_NAME, "response_port", self.logger) if response_port is None: return # Get the device pins from the config file self.zones = self.og.thermostat_plugin.get_device_names() self.pins = {} for device in self.zones: pin_str = config_utils.get_config_param(config, PLUGIN_NAME, device, self.logger) if pin_str is None: return self.pins[device] = int(pin_str) # Furnace controller interface self.furnace_controller = udp_interface.UDPSocket( address, response_port, command_port, PLUGIN_NAME + "_inf") if not self.furnace_controller.is_initialized(): self.logger.error("Failed to initialize furnace_controller") return self.furnace_controller.start() # Setup data logger self.data_logger = presence_logger.PresenceLogger( data_directory, "furnace", self.zones) self._initialized = True
def __init__(self, object_group, config): ThreadedPlugin.__init__(self, config=config, object_group=object_group, plugin_name=PLUGIN_NAME) self.mutex = Lock() if not self.is_enabled(): return self.data_directory = config_utils.get_config_param(config, PLUGIN_NAME, "data_directory", self.logger) if self.data_directory is None: return rtl_exe = config_utils.get_config_param(config, PLUGIN_NAME, "rtl_tcp_exe", self.logger) if rtl_exe is None: return if not os.path.isfile(rtl_exe): self.logger.warning("Could not access: " + rtl_exe) return rtl_ppm = config_utils.get_config_param(config, PLUGIN_NAME, "rtl_ppm", self.logger) rtl_ppm_args = "" if rtl_ppm: rtl_ppm_args = " -freqcorrection=" + rtl_ppm amr_exe = config_utils.get_config_param(config, PLUGIN_NAME, "rtl_amr_exe", self.logger) if amr_exe is None: return if not os.path.isfile(amr_exe): self.logger.warning("Could not access: " + rtl_exe) return self.meter_serial_number = \ config_utils.get_config_param(config, PLUGIN_NAME, "meter_serial_number", self.logger) if self.meter_serial_number is None: return self.meter_serial_number = int( self.meter_serial_number ) filter_args = " -filterid=" + str( self.meter_serial_number ) # # start rtl_tcp # self.logger.debug( "RTL_TCP commmand: " + rtl_exe ) self.rtl_handle = subprocess.Popen(shlex.split(rtl_exe), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, close_fds=ON_POSIX) time.sleep(5) # start rtlamr with a thread that fills the queue with each line of output self.logger.debug( "RTL_AMR commmand: " + amr_exe + AMR_ARGS + rtl_ppm_args + filter_args ) self.amr_handle = subprocess.Popen(shlex.split(amr_exe + AMR_ARGS + rtl_ppm_args + filter_args), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, close_fds=ON_POSIX) self.packets = Queue.Queue() self.data_logger = value_logger.ValueLogger(self.data_directory, "energy", "Electricity Used") def enqueue_output(out, queue): f = open("logs/rtlamr.log", 'w') for line in iter(out.readline, b''): queue.put(line.rstrip()) f.write(line) f.close() self.output_thread = Thread( target = enqueue_output, args = (self.amr_handle.stdout, self.packets) ) self.output_thread.daemon = True # thread dies with the program self.output_thread.start() time.sleep(5) if self.rtl_handle.returncode is not None: self.logger.warning( "RTL_TCP exited with code:", str(self.rtl_handle.returncode) ) return if self.amr_handle.returncode is not None: self.logger.warning( "RTL_AMR exited with code:", str(self.amr_handle.returncode) ) return self._initialized = True
if len(sys.argv) == 1: if not os.path.exists(config_filename): write_template_config() if len(sys.argv) == 2: if "-h" == sys.argv[1] or "--help" == sys.argv[1]: print_usage() elif "-e" == sys.argv[1] or "--example-config" == sys.argv[1]: write_template_config() sys.exit() else: config_filename = sys.argv[1] config = parse_config(config_filename) log_filename = config_utils.get_config_param(config, GENERAL_CONFIG_SEC, "log_filename") if log_filename is None: print "log_filename property missing from " + GENERAL_CONFIG_SEC + " section" sys.exit(1) log_level = config_utils.get_config_param(config, GENERAL_CONFIG_SEC, "log_level") if log_level is None: print "log_level property missing from " + GENERAL_CONFIG_SEC + " section" sys.exit(1) html_filename = config_utils.get_config_param(config, GENERAL_CONFIG_SEC, "html_filename") if html_filename is None: print "html_filename property missing from " + GENERAL_CONFIG_SEC + " section" sys.exit(1)
if len(sys.argv) == 1: if not os.path.exists(config_filename): write_template_config() if len(sys.argv) == 2: if "-h" == sys.argv[1] or "--help" == sys.argv[1]: print_usage() elif "-e" == sys.argv[1] or "--example-config" == sys.argv[1]: write_template_config() sys.exit() else: config_filename = sys.argv[1] config = parse_config(config_filename) log_filename = config_utils.get_config_param(config, GENERAL_CONFIG_SEC, "log_filename") if log_filename is None: print "log_filename property missing from " + GENERAL_CONFIG_SEC + " section" sys.exit(1) log_level = config_utils.get_config_param(config, GENERAL_CONFIG_SEC, "log_level") if log_level is None: print "log_level property missing from " + GENERAL_CONFIG_SEC + " section" sys.exit(1) html_filename = config_utils.get_config_param(config, GENERAL_CONFIG_SEC, "html_filename") if html_filename is None: print "html_filename property missing from " + GENERAL_CONFIG_SEC + " section" sys.exit(1) data_directory = config_utils.get_config_param(config, GENERAL_CONFIG_SEC, "data_directory")