Remove redundant open modes (#33652)
This commit is contained in:
parent
fddaea797e
commit
22ae498f3a
9 changed files with 12 additions and 12 deletions
|
@ -167,7 +167,7 @@ def daemonize() -> None:
|
|||
sys.exit(0)
|
||||
|
||||
# redirect standard file descriptors to devnull
|
||||
infd = open(os.devnull, "r")
|
||||
infd = open(os.devnull)
|
||||
outfd = open(os.devnull, "a+")
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
|
@ -180,7 +180,7 @@ def check_pid(pid_file: str) -> None:
|
|||
"""Check that Home Assistant is not already running."""
|
||||
# Check pid file
|
||||
try:
|
||||
with open(pid_file, "r") as file:
|
||||
with open(pid_file) as file:
|
||||
pid = int(file.readline())
|
||||
except OSError:
|
||||
# PID File does not exist
|
||||
|
|
|
@ -61,7 +61,7 @@ class ZWaveLogView(HomeAssistantView):
|
|||
def _get_log(self, hass, lines):
|
||||
"""Retrieve the logfile content."""
|
||||
logfilepath = hass.config.path(OZW_LOG_FILENAME)
|
||||
with open(logfilepath, "r") as logfile:
|
||||
with open(logfilepath) as logfile:
|
||||
data = (line.rstrip() for line in logfile)
|
||||
if lines == 0:
|
||||
loglines = list(data)
|
||||
|
|
|
@ -114,7 +114,7 @@ class BanLogParser:
|
|||
"""Read the fail2ban log and find entries for jail."""
|
||||
self.data = list()
|
||||
try:
|
||||
with open(self.log_file, "r", encoding="utf-8") as file_data:
|
||||
with open(self.log_file, encoding="utf-8") as file_data:
|
||||
self.data = self.ip_regex[jail].findall(file_data.read())
|
||||
|
||||
except (IndexError, FileNotFoundError, IsADirectoryError, UnboundLocalError):
|
||||
|
|
|
@ -77,7 +77,7 @@ class FileSensor(Entity):
|
|||
def update(self):
|
||||
"""Get the latest entry from a file and updates the state."""
|
||||
try:
|
||||
with open(self._file_path, "r", encoding="utf-8") as file_data:
|
||||
with open(self._file_path, encoding="utf-8") as file_data:
|
||||
for line in file_data:
|
||||
data = line
|
||||
data = data.strip()
|
||||
|
|
|
@ -221,7 +221,7 @@ def setup(hass, config):
|
|||
|
||||
def check_correct_scopes(token_file):
|
||||
"""Check for the correct scopes in file."""
|
||||
tokenfile = open(token_file, "r").read()
|
||||
tokenfile = open(token_file).read()
|
||||
if "readonly" in tokenfile:
|
||||
_LOGGER.warning("Please re-authenticate with Google.")
|
||||
return False
|
||||
|
|
|
@ -176,7 +176,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
# We have an owfs mounted
|
||||
else:
|
||||
for family_file_path in glob(os.path.join(base_dir, "*", "family")):
|
||||
with open(family_file_path, "r") as family_file:
|
||||
with open(family_file_path) as family_file:
|
||||
family = family_file.read()
|
||||
if "EF" in family:
|
||||
continue
|
||||
|
@ -218,7 +218,7 @@ class OneWire(Entity):
|
|||
|
||||
def _read_value_raw(self):
|
||||
"""Read the value as it is returned by the sensor."""
|
||||
with open(self._device_file, "r") as ds_device_file:
|
||||
with open(self._device_file) as ds_device_file:
|
||||
lines = ds_device_file.readlines()
|
||||
return lines
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ class RememberTheMilkConfiguration:
|
|||
return
|
||||
try:
|
||||
_LOGGER.debug("Loading configuration from file: %s", self._config_file_path)
|
||||
with open(self._config_file_path, "r") as config_file:
|
||||
with open(self._config_file_path) as config_file:
|
||||
self._config = json.load(config_file)
|
||||
except ValueError:
|
||||
_LOGGER.error(
|
||||
|
|
|
@ -339,7 +339,7 @@ def process_ha_config_upgrade(hass: HomeAssistant) -> None:
|
|||
version_path = hass.config.path(VERSION_FILE)
|
||||
|
||||
try:
|
||||
with open(version_path, "rt") as inp:
|
||||
with open(version_path) as inp:
|
||||
conf_version = inp.readline().strip()
|
||||
except FileNotFoundError:
|
||||
# Last version to not have this file
|
||||
|
@ -364,7 +364,7 @@ def process_ha_config_upgrade(hass: HomeAssistant) -> None:
|
|||
# 0.92 moved google/tts.py to google_translate/tts.py
|
||||
config_path = hass.config.path(YAML_CONFIG_FILE)
|
||||
|
||||
with open(config_path, "rt", encoding="utf-8") as config_file:
|
||||
with open(config_path, encoding="utf-8") as config_file:
|
||||
config_raw = config_file.read()
|
||||
|
||||
if TTS_PRE_92 in config_raw:
|
||||
|
|
|
@ -15,7 +15,7 @@ def install_osx():
|
|||
|
||||
template_path = os.path.join(os.path.dirname(__file__), "launchd.plist")
|
||||
|
||||
with open(template_path, "r", encoding="utf-8") as inp:
|
||||
with open(template_path, encoding="utf-8") as inp:
|
||||
plist = inp.read()
|
||||
|
||||
plist = plist.replace("$HASS_PATH$", hass_path)
|
||||
|
|
Loading…
Add table
Reference in a new issue