Skip to content

Commit

Permalink
Updated: README/info
Browse files Browse the repository at this point in the history
Fixed: Uptime/Image/Status container info
  • Loading branch information
ualex73 committed Jun 15, 2020
1 parent 7e78c5b commit 8a184e8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ monitor_docker:
mosquitto: Mosquitto
nodered: "Node-RED"
unifi: UniFi
sensorname: "{name}"
switchname: "{name}"
monitored_conditions:
- version
- containers_running
Expand All @@ -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 |
| --------------------------------- | ------------------------------- | ----- |
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/monitor_docker/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
17 changes: 13 additions & 4 deletions custom_components/monitor_docker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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 = {}

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ monitor_docker:
mosquitto: Mosquitto
nodered: "Node-RED"
unifi: UniFi
sensorname: "{name}"
switchname: "{name}"
monitored_conditions:
- version
- containers_running
Expand All @@ -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 |
| --------------------------------- | ------------------------------- | ----- |
Expand All @@ -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)
Expand Down

0 comments on commit 8a184e8

Please sign in to comment.