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