diff --git a/client/python/karanage/karanage/state.py b/client/python/karanage/karanage/state.py index f94fad5..77ebab6 100644 --- a/client/python/karanage/karanage/state.py +++ b/client/python/karanage/karanage/state.py @@ -72,13 +72,13 @@ class KaranageState: f"Fail send message: '{ret.url}'", ret.status, ret.data ) - def gets(self, topic: Optional[str] = None, since: Union[None, str, datetime] = None) -> List[StateData]: + def get(self, topic: str, since: Union[None, str, datetime] = None) -> Optional[StateData]: """Get all the topic fom the server. :param since: ISO1866 time value. :return: A dictionary with the requested data. """ param = { - "mode":"raw" # request raw mode to have the timestant in a float in second + "mode":"raw" # request raw mode to have the timestamp in a float in second } if since is not None: if type(since) is str: @@ -89,6 +89,31 @@ class KaranageState: raise KaranageException( f"Wrong input parameter type Must be a str or datetime: '{type(since)}'") ret = self.connection.get("state", topic, params=param) + if ret is None: + raise KaranageException( + f"Fail send message sub-library return None") + if ret.status is not None and 200 <= ret.status <= 299: + return convert_to_state_data(ret.data, topic) + return None + #raise KaranageException(f"Fail get data: '{ret.url}'", ret.status, ret.data) + + def gets(self, since: Union[None, str, datetime] = None) -> List[StateData]: + """Get all the topic fom the server. + :param since: ISO1866 time value. + :return: A dictionary with the requested data. + """ + param = { + "mode":"raw" # request raw mode to have the timestamp in a float in second + } + if since is not None: + if type(since) is str: + param["since"] = since + if type(since) is datetime: + param["since"] = since.replace(tzinfo=timezone.utc).isoformat() + else: + raise KaranageException( + f"Wrong input parameter type Must be a str or datetime: '{type(since)}'") + ret = self.connection.get("state", params=param) if ret is None: raise KaranageException( f"Fail send message sub-library return None") diff --git a/client/python/karanage_tools/bin/karanage-system b/client/python/karanage_tools/bin/karanage-system index 48a69b0..ccde738 100755 --- a/client/python/karanage_tools/bin/karanage-system +++ b/client/python/karanage_tools/bin/karanage-system @@ -1,2 +1,3 @@ #!/bin/python3 from karanage_tools import karanage_system +karanage_system.main() \ No newline at end of file diff --git a/client/python/karanage_tools/bin/karanage-tools-state-get b/client/python/karanage_tools/bin/karanage-tools-state-get index 89f05e0..d9f39a4 100755 --- a/client/python/karanage_tools/bin/karanage-tools-state-get +++ b/client/python/karanage_tools/bin/karanage-tools-state-get @@ -1,2 +1,3 @@ #!/bin/python3 from karanage_tools import karanage_tools_state_get +karanage_tools_state_get.main() \ No newline at end of file diff --git a/client/python/karanage_tools/bin/karanage-tools-state-history-get b/client/python/karanage_tools/bin/karanage-tools-state-history-get index 41ff1c0..cd3d733 100755 --- a/client/python/karanage_tools/bin/karanage-tools-state-history-get +++ b/client/python/karanage_tools/bin/karanage-tools-state-history-get @@ -1,2 +1,3 @@ #!/bin/python3 from karanage_tools import karanage_tools_state_history_get +karanage_tools_state_history_get.main() \ No newline at end of file diff --git a/client/python/karanage_tools/karanage_tools/karanage_system.py b/client/python/karanage_tools/karanage_tools/karanage_system.py index 8e8bdf3..36817c0 100755 --- a/client/python/karanage_tools/karanage_tools/karanage_system.py +++ b/client/python/karanage_tools/karanage_tools/karanage_system.py @@ -141,8 +141,7 @@ def agglutinate(configuration, name, data): return filter(data, configuration[name]["include"]) return none - -if __name__ == "__main__": +def main(): # Load arguments: parser = argparse.ArgumentParser() parser.add_argument( @@ -233,3 +232,6 @@ if __name__ == "__main__": except KaranageException as ex: print(f"Can not send to the server: {ex}") time.sleep(configuration["config"]["sleep"]) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/client/python/karanage_tools/karanage_tools/karanage_tools_state_get.py b/client/python/karanage_tools/karanage_tools/karanage_tools_state_get.py index 9ebe4d2..6e170ea 100755 --- a/client/python/karanage_tools/karanage_tools/karanage_tools_state_get.py +++ b/client/python/karanage_tools/karanage_tools/karanage_tools_state_get.py @@ -22,7 +22,7 @@ from karanage import ( ) -if __name__ == "__main__": +def main(): # Load arguments: parser = argparse.ArgumentParser() parser.add_argument("-C", "--connection", type=str, help="json configuration file") @@ -57,3 +57,6 @@ if __name__ == "__main__": break else: time.sleep(1) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/client/python/karanage_tools/karanage_tools/karanage_tools_state_history_get.py b/client/python/karanage_tools/karanage_tools/karanage_tools_state_history_get.py index d50202b..76ab6d7 100755 --- a/client/python/karanage_tools/karanage_tools/karanage_tools_state_history_get.py +++ b/client/python/karanage_tools/karanage_tools/karanage_tools_state_history_get.py @@ -17,7 +17,7 @@ from typing import Dict, List from karanage import KaranageConnection, KaranageState -if __name__ == "__main__": +def main(): # Load arguments: parser = argparse.ArgumentParser() parser.add_argument("-C", "--connection", type=str, help="json configuration file") @@ -53,3 +53,6 @@ if __name__ == "__main__": topic=args.topic, since=args.since, since_id=args.since_id, limit=args.limit ) print(f"Ret = {json.dumps(data, indent=4)}") + +if __name__ == "__main__": + main() \ No newline at end of file