Replace OSError aliases with OSError (#33655)
This commit is contained in:
parent
03cae17992
commit
6f1900c6f4
23 changed files with 35 additions and 42 deletions
|
@ -1,7 +1,6 @@
|
|||
"""Support for ANEL PwrCtrl switches."""
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import socket
|
||||
|
||||
from anel_pwrctrl import DeviceMaster
|
||||
import voluptuous as vol
|
||||
|
@ -45,7 +44,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
write_port=port_recv,
|
||||
)
|
||||
master.query(ip_addr=host)
|
||||
except socket.error as ex:
|
||||
except OSError as ex:
|
||||
_LOGGER.error("Unable to discover PwrCtrl device: %s", str(ex))
|
||||
return False
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ from datetime import timedelta
|
|||
from ipaddress import ip_address
|
||||
from itertools import product
|
||||
import logging
|
||||
import socket
|
||||
|
||||
import broadlink
|
||||
import voluptuous as vol
|
||||
|
@ -103,7 +102,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
connected, loaded = await asyncio.gather(
|
||||
hass.async_add_executor_job(api.auth), remote.async_load_storage_files()
|
||||
)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
pass
|
||||
if not connected:
|
||||
hass.data[DOMAIN][COMPONENT].remove(unique_id)
|
||||
|
@ -327,7 +326,7 @@ class BroadlinkRemote(RemoteDevice):
|
|||
continue
|
||||
try:
|
||||
await self.hass.async_add_executor_job(function, *args)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
continue
|
||||
return
|
||||
raise ConnectionError
|
||||
|
@ -336,7 +335,7 @@ class BroadlinkRemote(RemoteDevice):
|
|||
"""Connect to the remote."""
|
||||
try:
|
||||
auth = await self.hass.async_add_executor_job(self._api.auth)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
auth = False
|
||||
if auth and not self._available:
|
||||
_LOGGER.warning("Connected to the remote")
|
||||
|
|
|
@ -82,7 +82,7 @@ def setup(hass, config):
|
|||
|
||||
_LOGGER.debug("Ebusd integration setup completed")
|
||||
return True
|
||||
except (socket.timeout, socket.error):
|
||||
except (socket.timeout, OSError):
|
||||
return False
|
||||
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ USN: uuid:Socket-1_0-221438K0100073::urn:schemas-upnp-org:device:basic:1
|
|||
else:
|
||||
# most likely the timeout, so check for interrupt
|
||||
continue
|
||||
except socket.error as ex:
|
||||
except OSError as ex:
|
||||
if self._interrupted:
|
||||
clean_socket_close(ssdp_socket)
|
||||
return
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support for Flux lights."""
|
||||
import logging
|
||||
import random
|
||||
import socket
|
||||
|
||||
from flux_led import BulbScanner, WifiLedBulb
|
||||
import voluptuous as vol
|
||||
|
@ -363,7 +362,7 @@ class FluxLight(Light):
|
|||
try:
|
||||
self._connect()
|
||||
self._error_reported = False
|
||||
except socket.error:
|
||||
except OSError:
|
||||
self._disconnect()
|
||||
if not self._error_reported:
|
||||
_LOGGER.warning(
|
||||
|
|
|
@ -63,7 +63,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
# Try to resolve a hostname; if it is already an IP, it will be returned as-is
|
||||
try:
|
||||
host = socket.gethostbyname(host)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
_LOGGER.error("Could not resolve hostname %s", host)
|
||||
return
|
||||
port = config.get(CONF_PORT)
|
||||
|
@ -170,7 +170,7 @@ class FritzBoxCallMonitor:
|
|||
try:
|
||||
self.sock.connect((self.host, self.port))
|
||||
threading.Thread(target=self._listen).start()
|
||||
except socket.error as err:
|
||||
except OSError as err:
|
||||
self.sock = None
|
||||
_LOGGER.error(
|
||||
"Cannot connect to %s on port %s: %s", self.host, self.port, err
|
||||
|
|
|
@ -58,7 +58,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
sock.connect((host, port))
|
||||
sock.shutdown(2)
|
||||
_LOGGER.debug("Connection to GPSD possible")
|
||||
except socket.error:
|
||||
except OSError:
|
||||
_LOGGER.error("Not able to connect to GPSD")
|
||||
return False
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ def setup(hass, config):
|
|||
sock.connect((host, port))
|
||||
sock.shutdown(2)
|
||||
_LOGGER.debug("Connection to Graphite possible")
|
||||
except socket.error:
|
||||
except OSError:
|
||||
_LOGGER.error("Not able to connect to Graphite")
|
||||
return False
|
||||
|
||||
|
@ -128,7 +128,7 @@ class GraphiteFeeder(threading.Thread):
|
|||
self._send_to_graphite("\n".join(lines))
|
||||
except socket.gaierror:
|
||||
_LOGGER.error("Unable to connect to host %s", self._host)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
_LOGGER.exception("Failed to send data to graphite")
|
||||
|
||||
def run(self):
|
||||
|
|
|
@ -444,7 +444,7 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
try:
|
||||
with open(self._config_path, "w+", encoding="utf-8") as file_out:
|
||||
json.dump(self._client.json_config, file_out, sort_keys=True, indent=4)
|
||||
except IOError as exc:
|
||||
except OSError as exc:
|
||||
_LOGGER.error(
|
||||
"%s: Unable to write HUB configuration to %s: %s",
|
||||
self.name,
|
||||
|
|
|
@ -355,7 +355,7 @@ class InfluxThread(threading.Thread):
|
|||
except (
|
||||
exceptions.InfluxDBClientError,
|
||||
exceptions.InfluxDBServerError,
|
||||
IOError,
|
||||
OSError,
|
||||
) as err:
|
||||
if retry < self.max_tries:
|
||||
time.sleep(RETRY_DELAY)
|
||||
|
|
|
@ -80,5 +80,5 @@ class LannouncerNotificationService(BaseNotificationService):
|
|||
sock.close()
|
||||
except socket.gaierror:
|
||||
_LOGGER.error("Unable to connect to host %s", self._host)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
_LOGGER.exception("Failed to send data to Lannnouncer")
|
||||
|
|
|
@ -122,7 +122,7 @@ class MaxCubeClimate(ClimateDevice):
|
|||
with self._cubehandle.mutex:
|
||||
try:
|
||||
cube.set_target_temperature(device, target_temperature)
|
||||
except (socket.timeout, socket.error):
|
||||
except (socket.timeout, OSError):
|
||||
_LOGGER.error("Setting target temperature failed")
|
||||
return False
|
||||
|
||||
|
@ -145,7 +145,7 @@ class MaxCubeClimate(ClimateDevice):
|
|||
with self._cubehandle.mutex:
|
||||
try:
|
||||
self._cubehandle.cube.set_mode(device, mode)
|
||||
except (socket.timeout, socket.error):
|
||||
except (socket.timeout, OSError):
|
||||
_LOGGER.error("Setting operation mode failed")
|
||||
return False
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ class MikrotikData:
|
|||
# get new hub firmware version if updated
|
||||
self.firmware = self.get_info(ATTR_FIRMWARE)
|
||||
|
||||
except (CannotConnect, socket.timeout, socket.error):
|
||||
except (CannotConnect, socket.timeout, OSError):
|
||||
self.available = False
|
||||
return
|
||||
|
||||
|
@ -249,7 +249,7 @@ class MikrotikData:
|
|||
response = list(self.api(cmd=cmd))
|
||||
except (
|
||||
librouteros.exceptions.ConnectionClosed,
|
||||
socket.error,
|
||||
OSError,
|
||||
socket.timeout,
|
||||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||
|
@ -407,7 +407,7 @@ def get_api(hass, entry):
|
|||
return api
|
||||
except (
|
||||
librouteros.exceptions.LibRouterosError,
|
||||
socket.error,
|
||||
OSError,
|
||||
socket.timeout,
|
||||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s error: %s", entry[CONF_HOST], api_error)
|
||||
|
|
|
@ -7,7 +7,6 @@ import json
|
|||
import logging
|
||||
from operator import attrgetter
|
||||
import os
|
||||
import socket
|
||||
import ssl
|
||||
import sys
|
||||
import time
|
||||
|
@ -996,7 +995,7 @@ class MQTT:
|
|||
self.connected = True
|
||||
_LOGGER.info("Successfully reconnected to the MQTT server")
|
||||
break
|
||||
except socket.error:
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
wait_time = min(2 ** tries, MAX_RECONNECT_WAIT)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support for Nest devices."""
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
import socket
|
||||
import threading
|
||||
|
||||
from nest import Nest
|
||||
|
@ -294,7 +293,7 @@ class NestDevice:
|
|||
if self.local_structure is None:
|
||||
self.local_structure = structure_names
|
||||
|
||||
except (AuthorizationError, APIError, socket.error) as err:
|
||||
except (AuthorizationError, APIError, OSError) as err:
|
||||
_LOGGER.error("Connection error while access Nest web service: %s", err)
|
||||
return False
|
||||
return True
|
||||
|
@ -312,7 +311,7 @@ class NestDevice:
|
|||
continue
|
||||
yield structure
|
||||
|
||||
except (AuthorizationError, APIError, socket.error) as err:
|
||||
except (AuthorizationError, APIError, OSError) as err:
|
||||
_LOGGER.error("Connection error while access Nest web service: %s", err)
|
||||
|
||||
def thermostats(self):
|
||||
|
@ -354,7 +353,7 @@ class NestDevice:
|
|||
continue
|
||||
yield (structure, device)
|
||||
|
||||
except (AuthorizationError, APIError, socket.error) as err:
|
||||
except (AuthorizationError, APIError, OSError) as err:
|
||||
_LOGGER.error("Connection error while access Nest web service: %s", err)
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support for Osram Lightify."""
|
||||
import logging
|
||||
import random
|
||||
import socket
|
||||
|
||||
from lightify import Lightify
|
||||
import voluptuous as vol
|
||||
|
@ -74,7 +73,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
host = config[CONF_HOST]
|
||||
try:
|
||||
bridge = Lightify(host, log_level=logging.NOTSET)
|
||||
except socket.error as err:
|
||||
except OSError as err:
|
||||
msg = "Error connecting to bridge: {} due to: {}".format(host, str(err))
|
||||
_LOGGER.exception(msg)
|
||||
return
|
||||
|
|
|
@ -67,7 +67,7 @@ def setup(hass, config):
|
|||
|
||||
try:
|
||||
pilight_client = pilight.Client(host=host, port=port)
|
||||
except (socket.error, socket.timeout) as err:
|
||||
except (OSError, socket.timeout) as err:
|
||||
_LOGGER.error("Unable to connect to %s on port %s: %s", host, port, err)
|
||||
return False
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ class TcpSensor(Entity):
|
|||
sock.settimeout(self._config[CONF_TIMEOUT])
|
||||
try:
|
||||
sock.connect((self._config[CONF_HOST], self._config[CONF_PORT]))
|
||||
except socket.error as err:
|
||||
except OSError as err:
|
||||
_LOGGER.error(
|
||||
"Unable to connect to %s on port %s: %s",
|
||||
self._config[CONF_HOST],
|
||||
|
@ -110,7 +110,7 @@ class TcpSensor(Entity):
|
|||
|
||||
try:
|
||||
sock.send(self._config[CONF_PAYLOAD].encode())
|
||||
except socket.error as err:
|
||||
except OSError as err:
|
||||
_LOGGER.error(
|
||||
"Unable to send payload %r to %s on port %s: %s",
|
||||
self._config[CONF_PAYLOAD],
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""Support for Ubiquiti's UVC cameras."""
|
||||
import logging
|
||||
import socket
|
||||
|
||||
import requests
|
||||
from uvcclient import camera as uvc_camera, nvr
|
||||
|
@ -154,7 +153,7 @@ class UnifiVideoCamera(Camera):
|
|||
)
|
||||
self._connect_addr = addr
|
||||
break
|
||||
except socket.error:
|
||||
except OSError:
|
||||
pass
|
||||
except uvc_camera.CameraConnectError:
|
||||
pass
|
||||
|
|
|
@ -208,7 +208,7 @@ class WatsonIOTThread(threading.Thread):
|
|||
_LOGGER.error("Failed to publish message to Watson IoT")
|
||||
continue
|
||||
break
|
||||
except (MissingMessageEncoderException, IOError):
|
||||
except (MissingMessageEncoderException, OSError):
|
||||
if retry < MAX_TRIES:
|
||||
time.sleep(RETRY_DELAY)
|
||||
else:
|
||||
|
|
|
@ -53,7 +53,7 @@ def setup(hass, config):
|
|||
|
||||
try:
|
||||
host_ip_pton = socket.inet_pton(socket.AF_INET, host_ip)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
host_ip_pton = socket.inet_pton(socket.AF_INET6, host_ip)
|
||||
|
||||
info = ServiceInfo(
|
||||
|
|
|
@ -85,7 +85,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
ZiggoMediaboxXLDevice(mediabox, host, name, connection_successful)
|
||||
)
|
||||
known_devices.add(ip_addr)
|
||||
except socket.error as error:
|
||||
except OSError as error:
|
||||
_LOGGER.error("Can't connect to %s: %s", host, error)
|
||||
else:
|
||||
_LOGGER.info("Ignoring duplicate Ziggo Mediabox XL %s", host)
|
||||
|
@ -115,7 +115,7 @@ class ZiggoMediaboxXLDevice(MediaPlayerDevice):
|
|||
self._available = True
|
||||
else:
|
||||
self._available = False
|
||||
except socket.error:
|
||||
except OSError:
|
||||
_LOGGER.error("Couldn't fetch state from %s", self._host)
|
||||
self._available = False
|
||||
|
||||
|
@ -123,7 +123,7 @@ class ZiggoMediaboxXLDevice(MediaPlayerDevice):
|
|||
"""Send keys to the device and handle exceptions."""
|
||||
try:
|
||||
self._mediabox.send_keys(keys)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
_LOGGER.error("Couldn't send keys to %s", self._host)
|
||||
|
||||
@property
|
||||
|
|
|
@ -101,7 +101,7 @@ def get_local_ip() -> str:
|
|||
sock.connect(("8.8.8.8", 80))
|
||||
|
||||
return sock.getsockname()[0] # type: ignore
|
||||
except socket.error:
|
||||
except OSError:
|
||||
try:
|
||||
return socket.gethostbyname(socket.gethostname())
|
||||
except socket.gaierror:
|
||||
|
|
Loading…
Add table
Reference in a new issue