From 22ae498f3a3cb9de82ab652e70c9690c5cdaec09 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 4 Apr 2020 22:49:15 +0200 Subject: [PATCH] Remove redundant open modes (#33652) --- homeassistant/__main__.py | 4 ++-- homeassistant/components/config/zwave.py | 2 +- homeassistant/components/fail2ban/sensor.py | 2 +- homeassistant/components/file/sensor.py | 2 +- homeassistant/components/google/__init__.py | 2 +- homeassistant/components/onewire/sensor.py | 4 ++-- homeassistant/components/remember_the_milk/__init__.py | 2 +- homeassistant/config.py | 4 ++-- homeassistant/scripts/macos/__init__.py | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index 5e7fab5bd54..6dd5edb81b4 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -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 diff --git a/homeassistant/components/config/zwave.py b/homeassistant/components/config/zwave.py index b792fcccec3..7e045934f7d 100644 --- a/homeassistant/components/config/zwave.py +++ b/homeassistant/components/config/zwave.py @@ -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) diff --git a/homeassistant/components/fail2ban/sensor.py b/homeassistant/components/fail2ban/sensor.py index 224ce83c214..5a7e673ca02 100644 --- a/homeassistant/components/fail2ban/sensor.py +++ b/homeassistant/components/fail2ban/sensor.py @@ -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): diff --git a/homeassistant/components/file/sensor.py b/homeassistant/components/file/sensor.py index 96ae885ca77..3f6d69325f0 100644 --- a/homeassistant/components/file/sensor.py +++ b/homeassistant/components/file/sensor.py @@ -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() diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index f3321416b1f..ec5afde0bac 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -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 diff --git a/homeassistant/components/onewire/sensor.py b/homeassistant/components/onewire/sensor.py index 41f41a6e93d..da8b1ed359b 100644 --- a/homeassistant/components/onewire/sensor.py +++ b/homeassistant/components/onewire/sensor.py @@ -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 diff --git a/homeassistant/components/remember_the_milk/__init__.py b/homeassistant/components/remember_the_milk/__init__.py index d31d83d3e9d..52199b2b9c6 100644 --- a/homeassistant/components/remember_the_milk/__init__.py +++ b/homeassistant/components/remember_the_milk/__init__.py @@ -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( diff --git a/homeassistant/config.py b/homeassistant/config.py index 169f3c77197..0ac86c4eb4b 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -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: diff --git a/homeassistant/scripts/macos/__init__.py b/homeassistant/scripts/macos/__init__.py index c09f9f09337..b1c91001351 100644 --- a/homeassistant/scripts/macos/__init__.py +++ b/homeassistant/scripts/macos/__init__.py @@ -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)