From 61e69e017264cd677cca5d84affff96395cc8b72 Mon Sep 17 00:00:00 2001 From: ualex73 Date: Thu, 16 Jul 2020 12:41:24 +0200 Subject: [PATCH] Added: If only allinone is configured, it defaults to all sensors now Fixed: allinone statistics didn't update properly --- custom_components/monitor_docker/__init__.py | 9 +++++++++ custom_components/monitor_docker/helpers.py | 10 +++++++--- custom_components/monitor_docker/sensor.py | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/custom_components/monitor_docker/__init__.py b/custom_components/monitor_docker/__init__.py index a43b962..4a95828 100644 --- a/custom_components/monitor_docker/__init__.py +++ b/custom_components/monitor_docker/__init__.py @@ -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", diff --git a/custom_components/monitor_docker/helpers.py b/custom_components/monitor_docker/helpers.py index 11a3797..a13f7d2 100644 --- a/custom_components/monitor_docker/helpers.py +++ b/custom_components/monitor_docker/helpers.py @@ -705,7 +705,7 @@ 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]), @@ -713,7 +713,7 @@ async def _run_container_stats(self): # ) # else: # cpu_stats["total_1cpu"] = 0.0 - #else: + # else: # cpu_stats["total_1cpu"] = 0.0 _LOGGER.debug( @@ -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") diff --git a/custom_components/monitor_docker/sensor.py b/custom_components/monitor_docker/sensor.py index 97a5ec7..caa9a87 100644 --- a/custom_components/monitor_docker/sensor.py +++ b/custom_components/monitor_docker/sensor.py @@ -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: