glances_api 0.4.3__tar.gz → 0.5.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: glances-api
3
- Version: 0.4.3
2
+ Name: glances_api
3
+ Version: 0.5.0
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
@@ -18,7 +18,7 @@ class Glances:
18
18
  self,
19
19
  host: str = "localhost",
20
20
  port: int = 61208,
21
- version: int = 2,
21
+ version: int = 3,
22
22
  ssl: bool = False,
23
23
  verify_ssl: bool = True,
24
24
  username: str | None = None,
@@ -26,6 +26,11 @@ class Glances:
26
26
  httpx_client: httpx.AsyncClient | None = None,
27
27
  ):
28
28
  """Initialize the connection."""
29
+ if version == 2:
30
+ _LOGGER.warning(
31
+ "Glances api older than v3 will not be supported in the next release."
32
+ )
33
+
29
34
  schema = "https" if ssl else "http"
30
35
  self.url = f"{schema}://{host}:{port}/api/{version}"
31
36
  self.data: dict[str, Any] = {}
@@ -88,7 +93,7 @@ class Glances:
88
93
  else:
89
94
  raise exceptions.GlancesApiError("Element data not available")
90
95
 
91
- async def get_ha_sensor_data(self) -> dict[str, Any] | None:
96
+ async def get_ha_sensor_data(self) -> dict[str, Any]:
92
97
  """Create a dictionary with data for Home Assistant sensors."""
93
98
  await self.get_data("all")
94
99
 
@@ -135,6 +140,12 @@ class Glances:
135
140
  }
136
141
  if data := self.data.get("quicklook"):
137
142
  sensor_data["cpu"] = {"cpu_use_percent": data["cpu"]}
143
+ if data := self.data.get("percpu"):
144
+ sensor_data["percpu"] = {}
145
+ for cpu in data:
146
+ sensor_data["percpu"][str(cpu["cpu_number"])] = {
147
+ "cpu_use_percent": cpu["total"]
148
+ }
138
149
  if networks := self.data.get("network"):
139
150
  sensor_data["network"] = {}
140
151
  for network in networks:
@@ -144,9 +155,12 @@ class Glances:
144
155
  "tx": round(network["tx"] / 1024, 1),
145
156
  "speed": round(network["speed"] / 1024**3, 1),
146
157
  }
147
- if "docker" in self.data and (data := self.data["docker"].get("containers")):
158
+ data = self.data.get("dockers") or self.data.get("containers")
159
+ if data and (containers_data := data.get("containers")):
148
160
  active_containers = [
149
- container for container in data if container["Status"] == "running"
161
+ container
162
+ for container in containers_data
163
+ if container["Status"] == "running"
150
164
  ]
151
165
  sensor_data["docker"] = {"docker_active": len(active_containers)}
152
166
  cpu_use = 0.0
@@ -161,4 +175,14 @@ class Glances:
161
175
  sensor_data["raid"] = data
162
176
  if data := self.data.get("uptime"):
163
177
  sensor_data["uptime"] = data
178
+ if data := self.data.get("gpu"):
179
+ sensor_data["gpu"] = {}
180
+ for sensor in data:
181
+ sensor_data["gpu"][f"GPU_{sensor['gpu_id']}__{sensor['name']}"] = {
182
+ "name": sensor["name"],
183
+ "temperature": sensor["temperature"],
184
+ "mem": sensor["mem"],
185
+ "proc": sensor["proc"],
186
+ "fan_speed": sensor["fan_speed"] if "fan_speed" in sensor else 0,
187
+ }
164
188
  return sensor_data
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "glances_api"
3
- version = "0.4.3"
3
+ version = "0.5.0"
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"
File without changes
File without changes