Replaces IOError by OSError (#26428)

This commit is contained in:
Franck Nijhof 2019-09-04 19:09:24 +02:00 committed by Pascal Vizeli
parent 4004879ae0
commit 0df1b4c7a1
20 changed files with 24 additions and 24 deletions

View File

@ -216,7 +216,7 @@ def check_pid(pid_file: str) -> None:
try:
with open(pid_file, "r") as file:
pid = int(file.readline())
except IOError:
except OSError:
# PID File does not exist
return
@ -239,7 +239,7 @@ def write_pid(pid_file: str) -> None:
try:
with open(pid_file, "w") as file:
file.write(str(pid))
except IOError:
except OSError:
print(f"Fatal Error: Unable to write pid file {pid_file}")
sys.exit(1)
@ -258,7 +258,7 @@ def closefds_osx(min_fd: int, max_fd: int) -> None:
val = fcntl(_fd, F_GETFD)
if not val & FD_CLOEXEC:
fcntl(_fd, F_SETFD, val | FD_CLOEXEC)
except IOError:
except OSError:
pass

View File

@ -171,7 +171,7 @@ def _setup_bme680(config):
sensor.select_gas_heater_profile(0)
else:
sensor.set_gas_status(bme680.DISABLE_GAS_MEAS)
except (RuntimeError, IOError):
except (RuntimeError, OSError):
_LOGGER.error("BME680 sensor not detected at 0x%02x", i2c_address)
return None

View File

@ -142,7 +142,7 @@ class BMWConnectedDriveAccount:
self.account.update_vehicle_states()
for listener in self._update_listeners:
listener()
except IOError as exception:
except OSError as exception:
_LOGGER.error(
"Could not connect to the BMW Connected Drive portal. "
"The vehicle state could not be updated."

View File

@ -110,7 +110,7 @@ def setup(hass, config):
server = egardiaserver.EgardiaServer("", rs_port)
bound = server.bind()
if not bound:
raise IOError(
raise OSError(
"Binding error occurred while " + "starting EgardiaServer."
)
hass.data[EGARDIA_SERVER] = server
@ -123,7 +123,7 @@ def setup(hass, config):
# listen to home assistant stop event
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, handle_stop_event)
except IOError:
except OSError:
_LOGGER.error("Binding error occurred while starting EgardiaServer")
return False

View File

@ -293,7 +293,7 @@ class HangoutsBot:
if self.hass.config.is_allowed_path(uri):
try:
image_file = open(uri, "rb")
except IOError as error:
except OSError as error:
_LOGGER.error(
"Image file I/O error(%s): %s", error.errno, error.strerror
)

View File

@ -157,7 +157,7 @@ class KeyboardRemoteThread(threading.Thread):
try:
event = self.dev.read_one()
except IOError: # Keyboard Disconnected
except OSError: # Keyboard Disconnected
self.dev = None
self.hass.bus.fire(
KEYBOARD_REMOTE_DISCONNECTED,

View File

@ -70,7 +70,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
try:
device = LiveboxPlayTvDevice(host, port, name)
livebox_devices.append(device)
except IOError:
except OSError:
_LOGGER.error(
"Failed to connect to Livebox Play TV at %s:%s. "
"Please check your configuration",

View File

@ -157,7 +157,7 @@ class MiFloraSensor(Entity):
try:
_LOGGER.debug("Polling data for %s", self.name)
data = self.poller.parameter_value(self.parameter)
except IOError as ioerr:
except OSError as ioerr:
_LOGGER.info("Polling error %s", ioerr)
return
except BluetoothBackendException as bterror:

View File

@ -157,7 +157,7 @@ class MiTempBtSensor(Entity):
try:
_LOGGER.debug("Polling data for %s", self.name)
data = self.poller.parameter_value(self.parameter)
except IOError as ioerr:
except OSError as ioerr:
_LOGGER.warning("Polling error %s", ioerr)
return
except BluetoothBackendException as bterror:

View File

@ -92,7 +92,7 @@ def setup(hass, config):
try:
pilight_client.send_code(message_data)
except IOError:
except OSError:
_LOGGER.error("Pilight send failed for %s", str(message_data))
hass.services.register(DOMAIN, SERVICE_NAME, send_code, schema=RF_CODE_SCHEMA)

View File

@ -66,7 +66,7 @@ def _precheck_image(image, opts):
raise ValueError()
try:
img = Image.open(io.BytesIO(image))
except IOError:
except OSError:
_LOGGER.warning("Failed to open image")
raise ValueError()
imgfmt = str(img.format)

View File

@ -47,7 +47,7 @@ def setup_input(address, port, pull_mode, bouncetime):
bounce_time=bouncetime,
pin_factory=PiGPIOFactory(address),
)
except (ValueError, IndexError, KeyError, IOError):
except (ValueError, IndexError, KeyError, OSError):
return None

View File

@ -51,7 +51,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
button = remote_rpi_gpio.setup_input(
address, port_num, pull_mode, bouncetime
)
except (ValueError, IndexError, KeyError, IOError):
except (ValueError, IndexError, KeyError, OSError):
return
new_sensor = RemoteRPiGPIOBinarySensor(port_name, button, invert_logic)
devices.append(new_sensor)

View File

@ -36,7 +36,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for port, name in ports.items():
try:
led = remote_rpi_gpio.setup_output(address, port, invert_logic)
except (ValueError, IndexError, KeyError, IOError):
except (ValueError, IndexError, KeyError, OSError):
return
new_switch = RemoteRPiGPIOSwitch(name, led, invert_logic)
devices.append(new_switch)

View File

@ -94,7 +94,7 @@ def _parse_skyhub_response(data_str):
"""Parse the Sky Hub data format."""
pattmatch = re.search("attach_dev = '(.*)'", data_str)
if pattmatch is None:
raise IOError(
raise OSError(
"Error: Impossible to fetch data from"
+ " Sky Hub. Try to reboot the router."
)

View File

@ -65,7 +65,7 @@ def setup(hass, base_config):
srv_info,
)
return False
except IOError:
except OSError:
_LOGGER.exception(
"Server: %s not configured. Error on Supla API access: ", server_address
)

View File

@ -117,7 +117,7 @@ class TelnetSwitch(SwitchDevice):
response = telnet.read_until(b"\r", timeout=self._timeout)
_LOGGER.debug("telnet response: %s", response.decode("ASCII").strip())
return response.decode("ASCII").strip()
except IOError as error:
except OSError as error:
_LOGGER.error(
'Command "%s" failed with exception: %s', command, repr(error)
)

View File

@ -96,7 +96,7 @@ class TemperSensor(Entity):
)
sensor_value = self.temper_device.get_temperature(format_str)
self.current_value = round(sensor_value, 1)
except IOError:
except OSError:
_LOGGER.error(
"Failed to get temperature. The device address may"
"have changed. Attempting to reset device"

View File

@ -289,7 +289,7 @@ def _write_default_config(config_dir: str) -> Optional[str]:
return config_path
except IOError:
except OSError:
print("Unable to create default configuration file", config_path)
return None
@ -393,7 +393,7 @@ def process_ha_config_upgrade(hass: HomeAssistant) -> None:
try:
with open(config_path, "wt", encoding="utf-8") as config_file:
config_file.write(config_raw)
except IOError:
except OSError:
_LOGGER.exception("Migrating to google_translate tts failed")
pass

View File

@ -27,7 +27,7 @@ def install_osx():
try:
with open(path, "w", encoding="utf-8") as outp:
outp.write(plist)
except IOError as err:
except OSError as err:
print("Unable to write to " + path, err)
return