[DEBUG] correct the interface of ios for python clients

This commit is contained in:
Edouard DUPIN 2023-02-26 21:47:17 +01:00
parent f7398e81af
commit c2f63e9c43
9 changed files with 41 additions and 20 deletions

View File

@ -127,6 +127,14 @@ public class StateHistoryResource {
out.append(data.modify_date.toInstant().toString());
out.append("\"");
}
out.append(", \"state\":");
if (data.state == null) {
out.append("null");
} else {
out.append("\"");
out.append(data.state);
out.append("\"");
}
out.append(", \"data\":" + data.data + "}");
}
out.append("]");

View File

@ -62,7 +62,8 @@ public class StateResource {
),
true);
if (data == null) {
throw new FailException(Response.Status.NOT_FOUND, "Topic has no new data or does not exist: '" + topic + "'");
//throw new FailException(Response.Status.NOT_FOUND, "Topic has no new data or does not exist: '" + topic + "'");
return "";
}
} else {
data = SqlWrapper.getWhere(StateInstant.class,
@ -79,7 +80,6 @@ public class StateResource {
if ("raw".equals(mode)) {
double seconds = data.modify_date.toInstant().toEpochMilli() * 0.001;
out.append(seconds);
return "{ \"time\": " + seconds + ", \"data\":" + data.data + "}";
} else {
out.append("\"");
out.append(data.modify_date.toInstant().toString());

View File

@ -134,7 +134,7 @@ class KaranageConnection(KaranageConnectionInterface):
if token is not None:
self.token = token
def get_url(self, service: str, url_offset: Optional[str]):
def get_url(self, service: str, url_offset: Optional[str] = None):
"""Get the formatted URL for specific service and specific offset
:param service: Name of the service we want to connect on.
@ -163,7 +163,7 @@ class KaranageConnection(KaranageConnectionInterface):
def post(
self,
service: str,
url_offset: Optional[str],
url_offset: Optional[str] = None,
data: Any = None,
headers: Optional[Dict] = None,
params: Optional[Dict] = None,
@ -180,7 +180,7 @@ class KaranageConnection(KaranageConnectionInterface):
def get(
self,
service: str,
url_offset: Optional[str],
url_offset: Optional[str] = None,
headers: Optional[Dict] = None,
params: Optional[Dict] = None,
) -> KaranageResponse:

View File

@ -83,7 +83,7 @@ class KaranageState:
if since is not None:
if type(since) is str:
param["since"] = since
if type(since) is datetime:
elif type(since) is datetime:
param["since"] = since.replace(tzinfo=timezone.utc).isoformat()
else:
raise KaranageException(
@ -93,7 +93,9 @@ class KaranageState:
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)
if ret.data == "":
return None
return convert_to_state_data(json.loads(ret.data), topic)
return None
#raise KaranageException(f"Fail get data: '{ret.url}'", ret.status, ret.data)
@ -108,7 +110,7 @@ class KaranageState:
if since is not None:
if type(since) is str:
param["since"] = since
if type(since) is datetime:
elif type(since) is datetime:
param["since"] = since.replace(tzinfo=timezone.utc).isoformat()
else:
raise KaranageException(
@ -121,7 +123,7 @@ class KaranageState:
out: List[StateData] = []
if ret.data is not None:
for elem in json.loads(ret.data):
out.append(convert_to_state_data(elem, topic))
out.append(convert_to_state_data(elem))
return out
raise KaranageException(f"Fail get data: '{ret.url}'", ret.status, ret.data)
@ -139,16 +141,17 @@ class KaranageState:
:return: A dictionary with the requested data.
"""
param:Dict[str, Any] = {
"mode":"raw" # request raw mode to have the timestant in a float in second
}
if since is not None:
if type(since) is str:
param["since"] = since
if type(since) is datetime:
elif 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)}'")
f"Wrong input parameter type Must be a str or datetime: '{type(since)}' {type(str)}")
if since_id is not None:
param["sinceId"] = since_id
if limit is not None:

View File

@ -1 +1 @@
0.7.1-dev
0.7.2-dev

View File

@ -65,7 +65,7 @@ def filter(data: Dict, filter_list: List[str]) -> Dict:
def need_process(data: Dict[str, Any]) -> Any:
return configuration["cpu"] == "auto" or "include" in configuration["cpu"]
return data == "auto" or "include" in data
def create_cpu_data() -> Dict:

View File

@ -48,11 +48,18 @@ def main():
# transform since in a datetime:
while True:
data = stateInterface.gets(topic=args.topic, since=args.since)
for elem in data:
print(f"{elem.topic} @ {elem.time.astimezone()} => {elem.state}")
print(json.dumps(elem.data, indent=4))
args.since = elem.time
if args.topic is not None:
elem = stateInterface.get(topic=args.topic, since=args.since)
if elem is not None:
print(f"{elem.topic} @ {elem.time.astimezone()} => {elem.state}")
print(json.dumps(elem.data, indent=4))
args.since = elem.time
else:
data = stateInterface.gets(since=args.since)
for elem in data:
print(f"{elem.topic} @ {elem.time.astimezone()} => {elem.state}")
print(json.dumps(elem.data, indent=4))
args.since = elem.time
if not args.watch:
break
else:

View File

@ -52,7 +52,10 @@ def main():
data = stateInterface.get_history(
topic=args.topic, since=args.since, since_id=args.since_id, limit=args.limit
)
print(f"Ret = {json.dumps(data, indent=4)}")
tmp = []
for elem in data:
print(f"{elem.topic} @ {elem.time.astimezone()} => {elem.state}")
print(json.dumps(elem.data, indent=4))
if __name__ == "__main__":
main()

View File

@ -1 +1 @@
0.7.1-dev
0.7.2-dev