mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Fix glances docker container errors (#22846)
* Fix unavailable container errors * Update to dev * Use const
This commit is contained in:
parent
02b7fd93ed
commit
c7a49e0820
@ -7,7 +7,7 @@ import voluptuous as vol
|
|||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST, CONF_NAME, CONF_PORT, CONF_USERNAME, CONF_PASSWORD, CONF_SSL,
|
CONF_HOST, CONF_NAME, CONF_PORT, CONF_USERNAME, CONF_PASSWORD, CONF_SSL,
|
||||||
CONF_VERIFY_SSL, CONF_RESOURCES, TEMP_CELSIUS)
|
CONF_VERIFY_SSL, CONF_RESOURCES, STATE_UNAVAILABLE, TEMP_CELSIUS)
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -183,21 +183,34 @@ class GlancesSensor(Entity):
|
|||||||
self._state = sensor['value']
|
self._state = sensor['value']
|
||||||
elif self.type == 'docker_active':
|
elif self.type == 'docker_active':
|
||||||
count = 0
|
count = 0
|
||||||
for container in value['docker']['containers']:
|
try:
|
||||||
if container['Status'] == 'running' or \
|
for container in value['docker']['containers']:
|
||||||
'Up' in container['Status']:
|
if container['Status'] == 'running' or \
|
||||||
count += 1
|
'Up' in container['Status']:
|
||||||
self._state = count
|
count += 1
|
||||||
|
self._state = count
|
||||||
|
except KeyError:
|
||||||
|
self._state = count
|
||||||
elif self.type == 'docker_cpu_use':
|
elif self.type == 'docker_cpu_use':
|
||||||
use = 0.0
|
cpu_use = 0.0
|
||||||
for container in value['docker']['containers']:
|
try:
|
||||||
use += container['cpu']['total']
|
for container in value['docker']['containers']:
|
||||||
self._state = round(use, 1)
|
if container['Status'] == 'running' or \
|
||||||
|
'Up' in container['Status']:
|
||||||
|
cpu_use += container['cpu']['total']
|
||||||
|
self._state = round(cpu_use, 1)
|
||||||
|
except KeyError:
|
||||||
|
self._state = STATE_UNAVAILABLE
|
||||||
elif self.type == 'docker_memory_use':
|
elif self.type == 'docker_memory_use':
|
||||||
use = 0.0
|
mem_use = 0.0
|
||||||
for container in value['docker']['containers']:
|
try:
|
||||||
use += container['memory']['usage']
|
for container in value['docker']['containers']:
|
||||||
self._state = round(use / 1024**2, 1)
|
if container['Status'] == 'running' or \
|
||||||
|
'Up' in container['Status']:
|
||||||
|
mem_use += container['memory']['usage']
|
||||||
|
self._state = round(mem_use / 1024**2, 1)
|
||||||
|
except KeyError:
|
||||||
|
self._state = STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
class GlancesData:
|
class GlancesData:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user