[HOTFIX] missing correct API

This commit is contained in:
Edouard DUPIN 2023-02-24 21:12:21 +01:00
parent c9965986c0
commit f7398e81af
7 changed files with 42 additions and 6 deletions

View File

@ -72,13 +72,13 @@ class KaranageState:
f"Fail send message: '{ret.url}'", ret.status, ret.data 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. """Get all the topic fom the server.
:param since: ISO1866 time value. :param since: ISO1866 time value.
:return: A dictionary with the requested data. :return: A dictionary with the requested data.
""" """
param = { 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 since is not None:
if type(since) is str: if type(since) is str:
@ -89,6 +89,31 @@ class KaranageState:
raise KaranageException( raise KaranageException(
f"Wrong input parameter type Must be a str or datetime: '{type(since)}'") f"Wrong input parameter type Must be a str or datetime: '{type(since)}'")
ret = self.connection.get("state", topic, params=param) 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: if ret is None:
raise KaranageException( raise KaranageException(
f"Fail send message sub-library return None") f"Fail send message sub-library return None")

View File

@ -1,2 +1,3 @@
#!/bin/python3 #!/bin/python3
from karanage_tools import karanage_system from karanage_tools import karanage_system
karanage_system.main()

View File

@ -1,2 +1,3 @@
#!/bin/python3 #!/bin/python3
from karanage_tools import karanage_tools_state_get from karanage_tools import karanage_tools_state_get
karanage_tools_state_get.main()

View File

@ -1,2 +1,3 @@
#!/bin/python3 #!/bin/python3
from karanage_tools import karanage_tools_state_history_get from karanage_tools import karanage_tools_state_history_get
karanage_tools_state_history_get.main()

View File

@ -141,8 +141,7 @@ def agglutinate(configuration, name, data):
return filter(data, configuration[name]["include"]) return filter(data, configuration[name]["include"])
return none return none
def main():
if __name__ == "__main__":
# Load arguments: # Load arguments:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
@ -233,3 +232,6 @@ if __name__ == "__main__":
except KaranageException as ex: except KaranageException as ex:
print(f"Can not send to the server: {ex}") print(f"Can not send to the server: {ex}")
time.sleep(configuration["config"]["sleep"]) time.sleep(configuration["config"]["sleep"])
if __name__ == "__main__":
main()

View File

@ -22,7 +22,7 @@ from karanage import (
) )
if __name__ == "__main__": def main():
# Load arguments: # Load arguments:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-C", "--connection", type=str, help="json configuration file") parser.add_argument("-C", "--connection", type=str, help="json configuration file")
@ -57,3 +57,6 @@ if __name__ == "__main__":
break break
else: else:
time.sleep(1) time.sleep(1)
if __name__ == "__main__":
main()

View File

@ -17,7 +17,7 @@ from typing import Dict, List
from karanage import KaranageConnection, KaranageState from karanage import KaranageConnection, KaranageState
if __name__ == "__main__": def main():
# Load arguments: # Load arguments:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-C", "--connection", type=str, help="json configuration file") 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 topic=args.topic, since=args.since, since_id=args.since_id, limit=args.limit
) )
print(f"Ret = {json.dumps(data, indent=4)}") print(f"Ret = {json.dumps(data, indent=4)}")
if __name__ == "__main__":
main()