Skip to content

Commit

Permalink
Added: If only allinone is configured, it defaults to all sensors now
Browse files Browse the repository at this point in the history
Fixed: allinone statistics didn't update properly
  • Loading branch information
ualex73 committed Jul 16, 2020
1 parent 6ebc174 commit 61e69e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 9 additions & 0 deletions custom_components/monitor_docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def RunDocker(hass, entry):

# Now go through all possible entries, we support 1 or more docker hosts (untested)
for entry in config[DOMAIN]:
# Check if CONF_MONITORED_CONDITIONS has only ALLINONE, then expand to all
if (
len(entry[CONF_MONITORED_CONDITIONS]) == 1
and CONTAINER_INFO_ALLINONE in entry[CONF_MONITORED_CONDITIONS]
):
entry[CONF_MONITORED_CONDITIONS] = list(MONITORED_CONDITIONS_LIST) + list(
[CONTAINER_INFO_ALLINONE]
)

if entry[CONF_NAME] in hass.data[DOMAIN]:
_LOGGER.error(
"Instance %s is duplicate, please assign an unique name",
Expand Down
10 changes: 7 additions & 3 deletions custom_components/monitor_docker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,15 +705,15 @@ async def _run_container_stats(self):
else:
_LOGGER.error("%s: No 'memory_stats' found in raw packet", self._name)

#if "total" in cpu_stats:
# if "total" in cpu_stats:
# if cpu_stats.get("total", None) is not None:
# cpu_stats["total_1cpu"] = (
# (cpu_stats["total"] / self._info[ATTR_ONLINE_CPUS]),
# PRECISION,
# )
# else:
# cpu_stats["total_1cpu"] = 0.0
#else:
# else:
# cpu_stats["total_1cpu"] = 0.0

_LOGGER.debug(
Expand Down Expand Up @@ -784,7 +784,11 @@ async def _run_container_stats(self):
stats["network"] = network_stats

stats[CONTAINER_STATS_CPU_PERCENTAGE] = cpu_stats.get("total")
#stats[CONTAINER_STATS_1CPU_PERCENTAGE] = cpu_stats.get("total_1cpu")
if "online_cpus" in cpu_stats and cpu_stats.get("total") is not None:
stats[CONTAINER_STATS_1CPU_PERCENTAGE] = round(
cpu_stats.get("total") / cpu_stats["online_cpus"], PRECISION
)
# stats[CONTAINER_STATS_1CPU_PERCENTAGE] = cpu_stats.get("total_1cpu")
stats[CONTAINER_STATS_MEMORY] = memory_stats.get("usage")
stats[CONTAINER_STATS_MEMORY_PERCENTAGE] = memory_stats.get("usage_percent")
stats[CONTAINER_STATS_NETWORK_SPEED_UP] = network_stats.get("speed_tx")
Expand Down
2 changes: 1 addition & 1 deletion custom_components/monitor_docker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def event_callback(self, remove=False):
else:
state = stats.get(self._var_id)

if state != self._state:
if state != self._state or self._var_id == CONTAINER_INFO_ALLINONE:
self._state = state

try:
Expand Down

0 comments on commit 61e69e0

Please sign in to comment.