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