glances_api 0.5.0__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {glances_api-0.5.0 → glances_api-0.5.1}/LICENSE +1 -1
- {glances_api-0.5.0 → glances_api-0.5.1}/PKG-INFO +3 -4
- {glances_api-0.5.0 → glances_api-0.5.1}/glances_api/__init__.py +12 -8
- {glances_api-0.5.0 → glances_api-0.5.1}/glances_api/exceptions.py +0 -8
- {glances_api-0.5.0 → glances_api-0.5.1}/pyproject.toml +2 -2
- {glances_api-0.5.0 → glances_api-0.5.1}/README.rst +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017-
|
|
3
|
+
Copyright (c) 2017-2024 Fabian Affolter <fabian@affolter-engineering.ch>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: glances_api
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Python API for interacting with Glances
|
|
5
5
|
Home-page: https://github.com/home-assistant-ecosystem/python-glances-api
|
|
6
6
|
License: MIT
|
|
7
7
|
Author: Fabian Affolter
|
|
8
8
|
Author-email: fabian@affolter-engineering.ch
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.11,<4.0
|
|
10
10
|
Classifier: Development Status :: 3 - Alpha
|
|
11
11
|
Classifier: Environment :: Console
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
@@ -15,9 +15,8 @@ Classifier: Operating System :: MacOS :: MacOS X
|
|
|
15
15
|
Classifier: Operating System :: Microsoft :: Windows
|
|
16
16
|
Classifier: Operating System :: POSIX
|
|
17
17
|
Classifier: Programming Language :: Python :: 3
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
20
|
Classifier: Topic :: Utilities
|
|
22
21
|
Requires-Dist: httpx (>=0.23,<1)
|
|
23
22
|
Project-URL: Repository, https://github.com/home-assistant-ecosystem/python-glances-api/releases
|
|
@@ -35,7 +35,7 @@ class Glances:
|
|
|
35
35
|
self.url = f"{schema}://{host}:{port}/api/{version}"
|
|
36
36
|
self.data: dict[str, Any] = {}
|
|
37
37
|
self.plugins: list[str] = []
|
|
38
|
-
self.values: Any | None = None
|
|
38
|
+
self.values: dict[str, Any] | None = None
|
|
39
39
|
self.username = username
|
|
40
40
|
self.password = password
|
|
41
41
|
self.verify_ssl = verify_ssl
|
|
@@ -45,7 +45,7 @@ class Glances:
|
|
|
45
45
|
"""Retrieve the data."""
|
|
46
46
|
url = f"{self.url}/{endpoint}"
|
|
47
47
|
|
|
48
|
-
httpx_client
|
|
48
|
+
httpx_client = (
|
|
49
49
|
self.httpx_client
|
|
50
50
|
if self.httpx_client
|
|
51
51
|
else httpx.AsyncClient(verify=self.verify_ssl)
|
|
@@ -55,12 +55,16 @@ class Glances:
|
|
|
55
55
|
async with httpx_client as client:
|
|
56
56
|
if self.password is None:
|
|
57
57
|
response = await client.get(url)
|
|
58
|
-
|
|
58
|
+
elif self.username is not None:
|
|
59
59
|
response = await client.get(
|
|
60
60
|
url, auth=(self.username, self.password)
|
|
61
61
|
)
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
else:
|
|
63
|
+
raise ValueError("username and password must be provided.")
|
|
64
|
+
except (httpx.ConnectError, httpx.TimeoutException) as err:
|
|
65
|
+
raise exceptions.GlancesApiConnectionError(
|
|
66
|
+
f"Connection to {url} failed"
|
|
67
|
+
) from err
|
|
64
68
|
|
|
65
69
|
if response.status_code == httpx.codes.UNAUTHORIZED:
|
|
66
70
|
raise exceptions.GlancesApiAuthorizationError(
|
|
@@ -77,11 +81,11 @@ class Glances:
|
|
|
77
81
|
self.data = response.json()
|
|
78
82
|
elif endpoint == "pluginslist":
|
|
79
83
|
self.plugins = response.json()
|
|
80
|
-
except TypeError:
|
|
84
|
+
except TypeError as err:
|
|
81
85
|
_LOGGER.error("Can not load data from Glances")
|
|
82
86
|
raise exceptions.GlancesApiConnectionError(
|
|
83
87
|
"Unable to get the data from Glances"
|
|
84
|
-
)
|
|
88
|
+
) from err
|
|
85
89
|
|
|
86
90
|
async def get_metrics(self, element: str) -> None:
|
|
87
91
|
"""Get all the metrics for a monitored element."""
|
|
@@ -150,7 +154,7 @@ class Glances:
|
|
|
150
154
|
sensor_data["network"] = {}
|
|
151
155
|
for network in networks:
|
|
152
156
|
sensor_data["network"][network["interface_name"]] = {
|
|
153
|
-
"is_up": network
|
|
157
|
+
"is_up": network.get("is_up"),
|
|
154
158
|
"rx": round(network["rx"] / 1024, 1),
|
|
155
159
|
"tx": round(network["tx"] / 1024, 1),
|
|
156
160
|
"speed": round(network["speed"] / 1024**3, 1),
|
|
@@ -4,22 +4,14 @@
|
|
|
4
4
|
class GlancesApiError(Exception):
|
|
5
5
|
"""General GlancesApiError exception occurred."""
|
|
6
6
|
|
|
7
|
-
pass
|
|
8
|
-
|
|
9
7
|
|
|
10
8
|
class GlancesApiConnectionError(GlancesApiError):
|
|
11
9
|
"""When a connection error is encountered."""
|
|
12
10
|
|
|
13
|
-
pass
|
|
14
|
-
|
|
15
11
|
|
|
16
12
|
class GlancesApiAuthorizationError(GlancesApiError):
|
|
17
13
|
"""When a connection error is encountered."""
|
|
18
14
|
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
15
|
|
|
22
16
|
class GlancesApiNoDataAvailable(GlancesApiError):
|
|
23
17
|
"""When no data is available."""
|
|
24
|
-
|
|
25
|
-
pass
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "glances_api"
|
|
3
|
-
version = "0.5.
|
|
3
|
+
version = "0.5.1"
|
|
4
4
|
description = "Python API for interacting with Glances"
|
|
5
5
|
authors = ["Fabian Affolter <fabian@affolter-engineering.ch>"]
|
|
6
6
|
homepage = "https://github.com/home-assistant-ecosystem/python-glances-api"
|
|
@@ -18,7 +18,7 @@ classifiers = [
|
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
[tool.poetry.dependencies]
|
|
21
|
-
python = "^3.
|
|
21
|
+
python = "^3.11"
|
|
22
22
|
httpx = ">=0.23,<1"
|
|
23
23
|
|
|
24
24
|
[tool.poetry.dev-dependencies]
|
|
File without changes
|