Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions custom_components/monitor_docker/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ async def async_restart(parm) -> None:
"Service restart failed, container '%s' is not configured", cname
)

def find_rename(d: dict[str, str], item: str) -> str:
for k in d:
if re.match(k, item):
return d[k]

return item

if discovery_info is None:
return

Expand Down
1 change: 1 addition & 0 deletions custom_components/monitor_docker/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
API = "api"
CONFIG = "config"
CONTAINER = "container"
VERSION = "1.20b3"

CONF_CERTPATH = "certpath"
CONF_CONTAINERS = "containers"
Expand Down
47 changes: 29 additions & 18 deletions custom_components/monitor_docker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@
DOCKER_STATS_MEMORY_PERCENTAGE,
DOMAIN,
PRECISION,
VERSION,
)

VERSION = "1.20b3"

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -137,13 +136,33 @@ async def init(self, startCount: int = 0):
if url is not None and url == "":
url = None

# Try to fix unix:// to unix:/// (3 are required by aiodocker)
if url is not None and url.find("unix://") == 0 and url.find("unix:///") == -1:
url = url.replace("unix://", "unix:///")
# A Unix connection should contain 'unix://' in the URL
unixConnection = url is not None and url.find("unix://") == 0

# If it is not a Unix connection, it should be a TCP connection
tcpConnection = url is not None and not unixConnection

if unixConnection:
_LOGGER.debug("[%s]: Docker URL contains a Unix socket connection: '%s'", self._instance, url)

# Try to fix unix:// to unix:/// (3 are required by aiodocker)
if url.find("unix:///") == -1:
url = url.replace("unix://", "unix:///")

elif tcpConnection:
_LOGGER.debug("[%s]: Docker URL contains a TCP connection: '%s'", self._instance, url)

# When we reconnect with tcp, we should delay - docker is maybe not fully ready
if startCount > 0:
await asyncio.sleep(5)

else:
_LOGGER.debug(
"[%s]: Docker URL is auto-detect (most likely using 'unix://var/run/docker.socket')",
self._instance,
)


# When we reconnect with tcp, we should delay - docker is maybe not fully ready
if startCount > 0 and url is not None and url.find("unix:") != 0:
await asyncio.sleep(5)

# Remove Docker environment variables
os.environ.pop("DOCKER_TLS_VERIFY", None)
Expand All @@ -154,16 +173,8 @@ async def init(self, startCount: int = 0):
self._tcp_session = None
self._tcp_ssl_context = None

if url is not None:
_LOGGER.debug("[%s]: Docker URL is '%s'", self._instance, url)
else:
_LOGGER.debug(
"[%s]: Docker URL is auto-detect (most likely using 'unix://var/run/docker.socket')",
self._instance,
)

# If is not empty or an Unix socket, then do check TCP/SSL
if url and url.find("unix:") == -1:
# If is a TCP connection, then do check TCP/SSL
if tcpConnection:
# Check if URL is valid
if not (
url.find("tcp:") == 0
Expand Down
5 changes: 0 additions & 5 deletions custom_components/monitor_docker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ async def async_setup_platform(
):
"""Set up the Monitor Docker Sensor."""

def find_rename(d: dict[str, str], item: str) -> str:
for k in d:
if re.match(k, item):
return d[k]

return item

if discovery_info is None:
return
Expand Down
7 changes: 0 additions & 7 deletions custom_components/monitor_docker/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ async def async_restart(parm) -> None:
"Service restart failed, container '%s' is not configured", cname
)

def find_rename(d: dict[str, str], item: str) -> str:
for k in d:
if re.match(k, item):
return d[k]

return item

if discovery_info is None:
return

Expand Down