Skip to content

Commit

Permalink
Fixed: Less, not impacting, error messages in HA during restart
Browse files Browse the repository at this point in the history
  • Loading branch information
ualex73 committed Dec 11, 2021
1 parent 6349177 commit 95933ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions custom_components/monitor_docker/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def __init__(self, api, instance, prefix, variable):

self._state = None
self._attributes = {}
self._removed = False

_LOGGER.info(
"[%s]: Initializing Docker sensor '%s'", self._instance, self._var_id
Expand Down Expand Up @@ -247,11 +248,16 @@ async def async_added_to_hass(self):
def event_callback(self, remove=False):
"""Callback to remove Docker entity."""

# If already called before, do not remove it again
if self._removed:
return

if remove:
_LOGGER.info(
"[%s]: Removing sensor entity: %s", self._instance, self._var_id
)
self._loop.create_task(self.async_remove())
self._removed = True
return


Expand Down Expand Up @@ -311,6 +317,7 @@ def __init__(
self._state_extra = None

self._attributes = {}
self._removed = False

_LOGGER.info(
"[%s] %s: Initializing sensor with parameter: %s",
Expand Down Expand Up @@ -380,13 +387,18 @@ def event_callback(self, name="", remove=False):
"""Callback for update of container information."""

if remove:
# If already called before, do not remove it again
if self._removed:
return

_LOGGER.info(
"[%s] %s: Removing sensor entity: %s",
self._instance,
self._cname,
self._var_id,
)
self._loop.create_task(self.async_remove())
self._removed = True
return

state = None
Expand Down
6 changes: 6 additions & 0 deletions custom_components/monitor_docker/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(self, container, instance, prefix, cname, alias, name_format):
slugify(self._prefix + "_" + self._cname)
)
self._name = name_format.format(name=alias)
self._removed = False

@property
def entity_id(self):
Expand Down Expand Up @@ -197,8 +198,13 @@ def event_callback(self, name="", remove=False):
"""Callback for update of container information."""

if remove:
# If already called before, do not remove it again
if self._removed:
return

_LOGGER.info("[%s] %s: Removing switch entity", self._instance, self._cname)
self._loop.create_task(self.async_remove())
self._removed = True
return

state = None
Expand Down

0 comments on commit 95933ed

Please sign in to comment.