mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
OSError is alias for IOException and base class for many other exceptions - no need to catch redundant exceptions if OSError already present in except-clause (#4111)
This commit is contained in:
parent
9c0455e3dc
commit
3317b4916b
@ -6,7 +6,6 @@ https://home-assistant.io/components/climate.radiotherm/
|
||||
"""
|
||||
import datetime
|
||||
import logging
|
||||
from urllib.error import URLError
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -52,7 +51,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
try:
|
||||
tstat = radiotherm.get_thermostat(host)
|
||||
tstats.append(RadioThermostat(tstat, hold_temp))
|
||||
except (URLError, OSError):
|
||||
except OSError:
|
||||
_LOGGER.exception("Unable to connect to Radio Thermostat: %s",
|
||||
host)
|
||||
|
||||
|
@ -5,7 +5,6 @@ For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/media_player.panasonic_viera/
|
||||
"""
|
||||
import logging
|
||||
import socket
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -60,9 +59,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
|
||||
try:
|
||||
remote.get_mute()
|
||||
except (socket.timeout, TimeoutError, OSError):
|
||||
_LOGGER.error('Panasonic Viera TV is not available at %s:%d',
|
||||
host, port)
|
||||
except OSError as error:
|
||||
_LOGGER.error('Panasonic Viera TV is not available at %s:%d: %s',
|
||||
host, port, error)
|
||||
return False
|
||||
|
||||
add_devices([PanasonicVieraTVDevice(name, remote)])
|
||||
@ -88,7 +87,7 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
||||
try:
|
||||
self._muted = self._remote.get_mute()
|
||||
self._state = STATE_ON
|
||||
except (socket.timeout, TimeoutError, OSError):
|
||||
except OSError:
|
||||
self._state = STATE_OFF
|
||||
return False
|
||||
return True
|
||||
@ -98,7 +97,7 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
||||
try:
|
||||
self._remote.send_key(key)
|
||||
self._state = STATE_ON
|
||||
except (socket.timeout, TimeoutError, OSError):
|
||||
except OSError:
|
||||
self._state = STATE_OFF
|
||||
return False
|
||||
return True
|
||||
@ -120,7 +119,7 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
||||
try:
|
||||
volume = self._remote.get_volume() / 100
|
||||
self._state = STATE_ON
|
||||
except (socket.timeout, TimeoutError, OSError):
|
||||
except OSError:
|
||||
self._state = STATE_OFF
|
||||
return volume
|
||||
|
||||
@ -156,7 +155,7 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
||||
try:
|
||||
self._remote.set_volume(volume)
|
||||
self._state = STATE_ON
|
||||
except (socket.timeout, TimeoutError, OSError):
|
||||
except OSError:
|
||||
self._state = STATE_OFF
|
||||
|
||||
def media_play_pause(self):
|
||||
|
@ -5,7 +5,6 @@ For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/media_player.samsungtv/
|
||||
"""
|
||||
import logging
|
||||
import socket
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -101,8 +100,7 @@ class SamsungTVDevice(MediaPlayerDevice):
|
||||
self._state = STATE_ON
|
||||
self._remote = None
|
||||
return False
|
||||
except (self._remote_class.ConnectionClosed, socket.timeout,
|
||||
TimeoutError, OSError):
|
||||
except (self._remote_class.ConnectionClosed, OSError):
|
||||
self._state = STATE_OFF
|
||||
self._remote = None
|
||||
return False
|
||||
|
@ -163,7 +163,7 @@ class LogitechMediaServer(object):
|
||||
|
||||
return response
|
||||
|
||||
except (OSError, ConnectionError, EOFError) as error:
|
||||
except (OSError, EOFError) as error:
|
||||
_LOGGER.error("Could not communicate with %s:%d: %s",
|
||||
self.host,
|
||||
self.port,
|
||||
|
@ -71,8 +71,8 @@ def load_data(url=None, file=None, username=None, password=None):
|
||||
else:
|
||||
_LOGGER.warning("Can't load photo no photo found in params!")
|
||||
|
||||
except (OSError, IOError, requests.exceptions.RequestException):
|
||||
_LOGGER.error("Can't load photo into ByteIO")
|
||||
except OSError as error:
|
||||
_LOGGER.error("Can't load photo into ByteIO: %s", error)
|
||||
|
||||
return None
|
||||
|
||||
|
@ -157,7 +157,7 @@ class TelldusLiveData(object):
|
||||
response = self._client.request(what, params)
|
||||
_LOGGER.debug("got response %s", response)
|
||||
return response
|
||||
except (ConnectionError, TimeoutError, OSError) as error:
|
||||
except OSError as error:
|
||||
_LOGGER.error("failed to make request to Tellduslive servers: %s",
|
||||
error)
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user