diff --git a/boswatch/config.py b/boswatch/config.py index 3279296..1245eca 100644 --- a/boswatch/config.py +++ b/boswatch/config.py @@ -59,7 +59,37 @@ class Config: logging.debug("configuration sharePoint: %s", sharePoint) return True - def get(self, section, key, sharePoint=""): + def getInt(self, section, key, sharePoint=""): + """!Method to read a single config entry as integer + + @param section: Section to read from + @param key: Value to read + @param sharePoint: Name of the global config share (empty is only local) + @return The value or None""" + value = int(self._get(section, key, sharePoint)) + if value is None: + return 0 + return int(value) + + def getBool(self, section, key, sharePoint=""): + """!Method to read a single config entry as boolean + + @param section: Section to read from + @param key: Value to read + @param sharePoint: Name of the global config share (empty is only local) + @return The value or None""" + return bool(self._get(section, key, sharePoint)) + + def getStr(self, section, key, sharePoint=""): + """!Method to read a single config entry as string + + @param section: Section to read from + @param key: Value to read + @param sharePoint: Name of the global config share (empty is only local) + @return The value or None""" + return str(self._get(section, key, sharePoint)) + + def _get(self, section, key, sharePoint=""): """!Method to read a single config entry @param section: Section to read from diff --git a/boswatch/packet/packet.py b/boswatch/packet/packet.py index d3bfaa3..bf006b8 100644 --- a/boswatch/packet/packet.py +++ b/boswatch/packet/packet.py @@ -71,12 +71,12 @@ class Packet: - frequency""" config = Config() logging.debug("add client data to bwPacket") - self.set("clientName", config.get("Client", "Name", "clientConfig")) + self.set("clientName", config.getStr("Client", "Name", "clientConfig")) self.set("clientVersion", version.client) self.set("clientBuildDate", version.date) self.set("clientBranch", version.branch) - self.set("inputSource", config.get("Server", "InputSource", "clientConfig")) - self.set("frequency", config.get("Stick", "Frequency", "clientConfig")) + self.set("inputSource", config.getStr("Server", "InputSource", "clientConfig")) + self.set("frequency", config.getStr("Stick", "Frequency", "clientConfig")) def addServerData(self): """!Add the server information to the decoded data @@ -88,7 +88,7 @@ class Packet: - serverBranch""" config = Config() logging.debug("add server data to bwPacket") - self.set("serverName", config.get("Server", "Name", "serverConfig")) + self.set("serverName", config.getStr("Server", "Name", "serverConfig")) self.set("serverVersion", version.server) self.set("serverBuildDate", version.date) self.set("serverBranch", version.branch)