glances_api 0.4.2__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.2
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,9 +140,27 @@ class Glances:
135
140
  }
136
141
  if data := self.data.get("quicklook"):
137
142
  sensor_data["cpu"] = {"cpu_use_percent": data["cpu"]}
138
- if "docker" in self.data and (data := self.data["docker"].get("containers")):
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
+ }
149
+ if networks := self.data.get("network"):
150
+ sensor_data["network"] = {}
151
+ for network in networks:
152
+ sensor_data["network"][network["interface_name"]] = {
153
+ "is_up": network["is_up"],
154
+ "rx": round(network["rx"] / 1024, 1),
155
+ "tx": round(network["tx"] / 1024, 1),
156
+ "speed": round(network["speed"] / 1024**3, 1),
157
+ }
158
+ data = self.data.get("dockers") or self.data.get("containers")
159
+ if data and (containers_data := data.get("containers")):
139
160
  active_containers = [
140
- container for container in data if container["Status"] == "running"
161
+ container
162
+ for container in containers_data
163
+ if container["Status"] == "running"
141
164
  ]
142
165
  sensor_data["docker"] = {"docker_active": len(active_containers)}
143
166
  cpu_use = 0.0
@@ -150,4 +173,16 @@ class Glances:
150
173
  sensor_data["docker"]["docker_memory_use"] = round(mem_use / 1024**2, 1)
151
174
  if data := self.data.get("raid"):
152
175
  sensor_data["raid"] = data
176
+ if data := self.data.get("uptime"):
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
+ }
153
188
  return sensor_data
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "glances_api"
3
- version = "0.4.2"
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"
@@ -23,7 +23,7 @@ httpx = ">=0.23,<1"
23
23
 
24
24
  [tool.poetry.dev-dependencies]
25
25
  black = "^23.3"
26
- pytest = "^7.1.2"
26
+ pytest = "^7.3.0"
27
27
  pytest-httpx = ">0.15,<1"
28
28
  pytest-asyncio = "^0.16.0"
29
29
  isort = "^5.10.0"
File without changes
File without changes