[DEBUG] correct the interface of ios for python clients
This commit is contained in:
parent
f7398e81af
commit
c2f63e9c43
@ -127,6 +127,14 @@ public class StateHistoryResource {
|
|||||||
out.append(data.modify_date.toInstant().toString());
|
out.append(data.modify_date.toInstant().toString());
|
||||||
out.append("\"");
|
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(", \"data\":" + data.data + "}");
|
||||||
}
|
}
|
||||||
out.append("]");
|
out.append("]");
|
||||||
|
@ -62,7 +62,8 @@ public class StateResource {
|
|||||||
),
|
),
|
||||||
true);
|
true);
|
||||||
if (data == null) {
|
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 {
|
} else {
|
||||||
data = SqlWrapper.getWhere(StateInstant.class,
|
data = SqlWrapper.getWhere(StateInstant.class,
|
||||||
@ -79,7 +80,6 @@ public class StateResource {
|
|||||||
if ("raw".equals(mode)) {
|
if ("raw".equals(mode)) {
|
||||||
double seconds = data.modify_date.toInstant().toEpochMilli() * 0.001;
|
double seconds = data.modify_date.toInstant().toEpochMilli() * 0.001;
|
||||||
out.append(seconds);
|
out.append(seconds);
|
||||||
return "{ \"time\": " + seconds + ", \"data\":" + data.data + "}";
|
|
||||||
} else {
|
} else {
|
||||||
out.append("\"");
|
out.append("\"");
|
||||||
out.append(data.modify_date.toInstant().toString());
|
out.append(data.modify_date.toInstant().toString());
|
||||||
|
@ -134,7 +134,7 @@ class KaranageConnection(KaranageConnectionInterface):
|
|||||||
if token is not None:
|
if token is not None:
|
||||||
self.token = token
|
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
|
"""Get the formatted URL for specific service and specific offset
|
||||||
|
|
||||||
:param service: Name of the service we want to connect on.
|
:param service: Name of the service we want to connect on.
|
||||||
@ -163,7 +163,7 @@ class KaranageConnection(KaranageConnectionInterface):
|
|||||||
def post(
|
def post(
|
||||||
self,
|
self,
|
||||||
service: str,
|
service: str,
|
||||||
url_offset: Optional[str],
|
url_offset: Optional[str] = None,
|
||||||
data: Any = None,
|
data: Any = None,
|
||||||
headers: Optional[Dict] = None,
|
headers: Optional[Dict] = None,
|
||||||
params: Optional[Dict] = None,
|
params: Optional[Dict] = None,
|
||||||
@ -180,7 +180,7 @@ class KaranageConnection(KaranageConnectionInterface):
|
|||||||
def get(
|
def get(
|
||||||
self,
|
self,
|
||||||
service: str,
|
service: str,
|
||||||
url_offset: Optional[str],
|
url_offset: Optional[str] = None,
|
||||||
headers: Optional[Dict] = None,
|
headers: Optional[Dict] = None,
|
||||||
params: Optional[Dict] = None,
|
params: Optional[Dict] = None,
|
||||||
) -> KaranageResponse:
|
) -> KaranageResponse:
|
||||||
|
@ -83,7 +83,7 @@ class KaranageState:
|
|||||||
if since is not None:
|
if since is not None:
|
||||||
if type(since) is str:
|
if type(since) is str:
|
||||||
param["since"] = since
|
param["since"] = since
|
||||||
if type(since) is datetime:
|
elif type(since) is datetime:
|
||||||
param["since"] = since.replace(tzinfo=timezone.utc).isoformat()
|
param["since"] = since.replace(tzinfo=timezone.utc).isoformat()
|
||||||
else:
|
else:
|
||||||
raise KaranageException(
|
raise KaranageException(
|
||||||
@ -93,7 +93,9 @@ class KaranageState:
|
|||||||
raise KaranageException(
|
raise KaranageException(
|
||||||
f"Fail send message sub-library return None")
|
f"Fail send message sub-library return None")
|
||||||
if ret.status is not None and 200 <= ret.status <= 299:
|
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
|
return None
|
||||||
#raise KaranageException(f"Fail get data: '{ret.url}'", ret.status, ret.data)
|
#raise KaranageException(f"Fail get data: '{ret.url}'", ret.status, ret.data)
|
||||||
|
|
||||||
@ -108,7 +110,7 @@ class KaranageState:
|
|||||||
if since is not None:
|
if since is not None:
|
||||||
if type(since) is str:
|
if type(since) is str:
|
||||||
param["since"] = since
|
param["since"] = since
|
||||||
if type(since) is datetime:
|
elif type(since) is datetime:
|
||||||
param["since"] = since.replace(tzinfo=timezone.utc).isoformat()
|
param["since"] = since.replace(tzinfo=timezone.utc).isoformat()
|
||||||
else:
|
else:
|
||||||
raise KaranageException(
|
raise KaranageException(
|
||||||
@ -121,7 +123,7 @@ class KaranageState:
|
|||||||
out: List[StateData] = []
|
out: List[StateData] = []
|
||||||
if ret.data is not None:
|
if ret.data is not None:
|
||||||
for elem in json.loads(ret.data):
|
for elem in json.loads(ret.data):
|
||||||
out.append(convert_to_state_data(elem, topic))
|
out.append(convert_to_state_data(elem))
|
||||||
return out
|
return out
|
||||||
raise KaranageException(f"Fail get data: '{ret.url}'", ret.status, ret.data)
|
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.
|
:return: A dictionary with the requested data.
|
||||||
"""
|
"""
|
||||||
param:Dict[str, Any] = {
|
param:Dict[str, Any] = {
|
||||||
|
|
||||||
"mode":"raw" # request raw mode to have the timestant in a float in second
|
"mode":"raw" # request raw mode to have the timestant 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:
|
||||||
param["since"] = since
|
param["since"] = since
|
||||||
if type(since) is datetime:
|
elif type(since) is datetime:
|
||||||
param["since"] = since.replace(tzinfo=timezone.utc).isoformat()
|
param["since"] = since.replace(tzinfo=timezone.utc).isoformat()
|
||||||
else:
|
else:
|
||||||
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)}' {type(str)}")
|
||||||
if since_id is not None:
|
if since_id is not None:
|
||||||
param["sinceId"] = since_id
|
param["sinceId"] = since_id
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
|
@ -1 +1 @@
|
|||||||
0.7.1-dev
|
0.7.2-dev
|
@ -65,7 +65,7 @@ def filter(data: Dict, filter_list: List[str]) -> Dict:
|
|||||||
|
|
||||||
|
|
||||||
def need_process(data: Dict[str, Any]) -> Any:
|
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:
|
def create_cpu_data() -> Dict:
|
||||||
|
@ -48,7 +48,14 @@ def main():
|
|||||||
|
|
||||||
# transform since in a datetime:
|
# transform since in a datetime:
|
||||||
while True:
|
while True:
|
||||||
data = stateInterface.gets(topic=args.topic, since=args.since)
|
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:
|
for elem in data:
|
||||||
print(f"{elem.topic} @ {elem.time.astimezone()} => {elem.state}")
|
print(f"{elem.topic} @ {elem.time.astimezone()} => {elem.state}")
|
||||||
print(json.dumps(elem.data, indent=4))
|
print(json.dumps(elem.data, indent=4))
|
||||||
|
@ -52,7 +52,10 @@ def main():
|
|||||||
data = stateInterface.get_history(
|
data = stateInterface.get_history(
|
||||||
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)}")
|
tmp = []
|
||||||
|
for elem in data:
|
||||||
|
print(f"{elem.topic} @ {elem.time.astimezone()} => {elem.state}")
|
||||||
|
print(json.dumps(elem.data, indent=4))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
@ -1 +1 @@
|
|||||||
0.7.1-dev
|
0.7.2-dev
|
Loading…
Reference in New Issue
Block a user