diff --git a/README.md b/README.md index 09be384..523c535 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,6 @@ monitor_docker: mosquitto: Mosquitto nodered: "Node-RED" unifi: UniFi - sensorname: "{name}" - switchname: "{name}" monitored_conditions: - version - containers_running @@ -68,8 +66,8 @@ monitor_docker: | containers | list (Optional) | Array of containers to monitor. Defaults to all containers. | | monitored_conditions | list (Optional) | Array of conditions to be monitored. Defaults to all conditions. | | rename | dictionary (Optional) | Dictionary of containers to rename. Default no renaming. | -| sensorname | string (Optional) | Sensor string to format the name used in Home Assistant. Defaults to `Docker {name} {sensorname}`, where `{name}` is the container name and `{sensorname}` is e.g. Memory, Status, Network speed Up | -| switchname | string (optional) | Switch string to format the name used in Home Assistant. Defaults to `Docker {name}`, where `{name}` is the container name. | +| sensorname | string (Optional) | Sensor string to format the name used in Home Assistant. Defaults to `{name} {sensor}`, where `{name}` is the container name and `{sensor}` is e.g. Memory, Status, Network speed Up | +| switchname | string (optional) | Switch string to format the name used in Home Assistant. Defaults to `{name}`, where `{name}` is the container name. | | Monitored Conditions | Description | Unit | | --------------------------------- | ------------------------------- | ----- | @@ -90,6 +88,16 @@ monitor_docker: | network_total_up | Network total upstream | MB | | network_total_down | Network total downstream | MB | +### Debugging + +It is possible to debug the Monito Docker component, this can be done by adding the following lines to the `configuration.yaml` file: + +```yaml +logger: + logs: + custom_components.monitor_docker: debug +``` + ## Credits * [Sanderhuisman](https://github.com/Sanderhuisman/docker_monitor) diff --git a/custom_components/monitor_docker/const.py b/custom_components/monitor_docker/const.py index 3342472..7cd0fdf 100644 --- a/custom_components/monitor_docker/const.py +++ b/custom_components/monitor_docker/const.py @@ -11,8 +11,8 @@ CONF_SWITCHNAME = "switchname" DEFAULT_NAME = "Docker" -DEFAULT_SENSORNAME = "Docker {name} {sensorname}" -DEFAULT_SWITCHNAME = "Docker {name}" +DEFAULT_SENSORNAME = "{name} {sensor}" +DEFAULT_SWITCHNAME = "{name}" COMPONENTS = ["sensor", "switch"] diff --git a/custom_components/monitor_docker/sensor.py b/custom_components/monitor_docker/sensor.py index c88594e..a2a8971 100644 --- a/custom_components/monitor_docker/sensor.py +++ b/custom_components/monitor_docker/sensor.py @@ -23,9 +23,11 @@ CONF_SENSORNAME, DOCKER_INFO_VERSION, CONTAINER, + CONTAINER_INFO_IMAGE, CONTAINER_INFO_NETWORKMODE, CONTAINER_INFO_STATE, CONTAINER_INFO_STATUS, + CONTAINER_INFO_UPTIME, CONTAINER_MONITOR_LIST, CONTAINER_MONITOR_NETWORK_LIST, DOCKER_MONITOR_LIST, @@ -35,7 +37,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): - """Set up the Monitor Docker Switch.""" + """Set up the Monitor Docker Sensor.""" if discovery_info is None: return @@ -108,6 +110,8 @@ def __init__(self, api, prefix, variable): slugify(self._prefix + "_" + self._var_name) ) + self._name = "{name} {sensor}".format(name=self._prefix, sensor=self._var_name) + self._state = None self._attributes = {} @@ -121,7 +125,7 @@ def entity_id(self): @property def name(self): """Return the name of the sensor.""" - return "{} {}".format(self._prefix, self._var_name) + return self._name @property def icon(self): @@ -184,7 +188,9 @@ def __init__(self, container, prefix, cname, alias, variable, sensor_name_format self._entity_id = ENTITY_ID_FORMAT.format( slugify(self._prefix + "_" + self._cname + "_" + self._var_name) ) - self._name = sensor_name_format.format(name=alias, sensorname=self._var_name) + self._name = sensor_name_format.format( + name=alias, sensorname=self._var_name, sensor=self._var_name + ) self._state = None self._state_extra = None @@ -275,7 +281,10 @@ def event_callback(self, remove=False): self._state_extra = info.get(CONTAINER_INFO_STATE) elif info.get(CONTAINER_INFO_STATE) == "running": if self._var_id in CONTAINER_MONITOR_LIST: - state = stats.get(self._var_id) + if self._var_id in [CONTAINER_INFO_STATE, CONTAINER_INFO_UPTIME, CONTAINER_INFO_IMAGE]: + state = info.get(self._var_id) + else: + state = stats.get(self._var_id) if state != self._state: self._state = state diff --git a/info.md b/info.md index 05cb7d2..9cc27f2 100644 --- a/info.md +++ b/info.md @@ -41,8 +41,6 @@ monitor_docker: mosquitto: Mosquitto nodered: "Node-RED" unifi: UniFi - sensorname: "{name}" - switchname: "{name}" monitored_conditions: - version - containers_running @@ -61,8 +59,8 @@ monitor_docker: | containers | list (Optional) | Array of containers to monitor. Defaults to all containers. | | monitored_conditions | list (Optional) | Array of conditions to be monitored. Defaults to all conditions. | | rename | dictionary (Optional) | Dictionary of containers to rename. Default no renaming. | -| sensorname | string (Optional) | Sensor string to format the name used in Home Assistant. Defaults to `Docker {name} {sensorname}`, where `{name}` is the container name and `{sensorname}` is e.g. Memory, Status, Network speed Up | -| switchname | string (optional) | Switch string to format the name used in Home Assistant. Defaults to `Docker {name}`, where `{name}` is the container name. | +| sensorname | string (Optional) | Sensor string to format the name used in Home Assistant. Defaults to `{name} {sensor}`, where `{name}` is the container name and `{sensor}` is e.g. Memory, Status, Network speed Up | +| switchname | string (optional) | Switch string to format the name used in Home Assistant. Defaults to `{name}`, where `{name}` is the container name. | | Monitored Conditions | Description | Unit | | --------------------------------- | ------------------------------- | ----- | @@ -83,6 +81,16 @@ monitor_docker: | network_total_up | Network total upstream | MB | | network_total_down | Network total downstream | MB | +### Debugging + +It is possible to debug the Monito Docker component, this can be done by adding the following lines to the `configuration.yaml` file: + +```yaml +logger: + logs: + custom_components.monitor_docker: debug +``` + ## Credits * [Sanderhuisman](https://github.com/Sanderhuisman/docker_monitor)