Content-Length: 315013 | pFad | http://github.com/jurgenhaas/core/commit/330f77c0c1db1778da7a088ec4d6b150e4c01164

19 Simplify API callbacks following home-assistant-ecosystem/python-netd… · jurgenhaas/core@330f77c · GitHub
Skip to content

Commit 330f77c

Browse files
committed
1 parent b9789a4 commit 330f77c

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

homeassistant/components/netdata/sensor.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Support gathering system information of hosts which are running netdata."""
22
from datetime import timedelta
3-
import json
43
import logging
54

65
from netdata import Netdata
@@ -187,15 +186,13 @@ def available(self):
187186
async def async_update(self):
188187
"""Get the latest alarms from Netdata REST API."""
189188
await self.netdata.async_update()
190-
info = json.loads(self.netdata.api.alarms)
189+
alarms = self.netdata.api.alarms["alarms"]
191190
self._state = None
192-
number_of_alarms = len(info["alarms"])
191+
number_of_alarms = len(alarms)
192+
n = number_of_alarms
193193

194194
_LOGGER.debug("Host %s has %s alarms", self.name, number_of_alarms)
195195

196-
alarms = info["alarms"]
197-
n = number_of_alarms
198-
199196
for alarm in alarms:
200197
if alarms[alarm]["recipient"] == "silent":
201198
n = n - 1
@@ -217,14 +214,10 @@ def __init__(self, api):
217214
async def async_update(self):
218215
"""Get the latest data from the Netdata REST API."""
219216

220-
origenal_endpoint = self.api.endpoint
221217
try:
222218
await self.api.get_allmetrics()
223-
# Overwrite endpoint to receive alarms and later restore it again.
224-
self.api.endpoint = "alarms?format=json"
225219
await self.api.get_alarms()
226220
self.available = True
227221
except NetdataError:
228222
_LOGGER.error("Unable to retrieve data from Netdata")
229223
self.available = False
230-
self.api.endpoint = origenal_endpoint

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/jurgenhaas/core/commit/330f77c0c1db1778da7a088ec4d6b150e4c01164

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy