mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Do not print warning when command line switch queries off (#38591)
This commit is contained in:
parent
e3e9ad1342
commit
95835326f3
@ -6,8 +6,12 @@ import subprocess
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def call_shell_with_timeout(command, timeout):
|
||||
"""Run a shell command with a timeout."""
|
||||
def call_shell_with_timeout(command, timeout, *, log_return_code=True):
|
||||
"""Run a shell command with a timeout.
|
||||
|
||||
If log_return_code is set to False, it will not print an error if a non-zero
|
||||
return code is returned.
|
||||
"""
|
||||
try:
|
||||
_LOGGER.debug("Running command: %s", command)
|
||||
subprocess.check_output(
|
||||
@ -15,7 +19,8 @@ def call_shell_with_timeout(command, timeout):
|
||||
)
|
||||
return 0
|
||||
except subprocess.CalledProcessError as proc_exception:
|
||||
_LOGGER.error("Command failed: %s", command)
|
||||
if log_return_code:
|
||||
_LOGGER.error("Command failed: %s", command)
|
||||
return proc_exception.returncode
|
||||
except subprocess.TimeoutExpired:
|
||||
_LOGGER.error("Timeout for command: %s", command)
|
||||
|
@ -114,7 +114,9 @@ class CommandSwitch(SwitchEntity):
|
||||
def _query_state_code(self, command):
|
||||
"""Execute state command for return code."""
|
||||
_LOGGER.info("Running state code command: %s", command)
|
||||
return call_shell_with_timeout(command, self._timeout) == 0
|
||||
return (
|
||||
call_shell_with_timeout(command, self._timeout, log_return_code=False) == 0
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user