Pylint 2 fixes (#15487)

* pylint 2 inline disable syntax fixes

* pylint 2 logging-not-lazy fixes

* pylint 2 consider-using-in fixes

* Revert pylint 2 inline disable syntax fixes addressing unused-imports

Will have a go at removing more unused imports altogether first.
pull/15515/merge
Ville Skyttä 2018-07-17 20:34:29 +03:00 committed by Paulus Schoutsen
parent d2f4bce6c0
commit e31dd4404e
33 changed files with 55 additions and 73 deletions

View File

@ -55,7 +55,7 @@ def setup_platform(hass, config: ConfigType,
else: else:
device_type = _detect_device_type(node) device_type = _detect_device_type(node)
subnode_id = int(node.nid[-1]) subnode_id = int(node.nid[-1])
if (device_type == 'opening' or device_type == 'moisture'): if device_type in ('opening', 'moisture'):
# These sensors use an optional "negative" subnode 2 to snag # These sensors use an optional "negative" subnode 2 to snag
# all state changes # all state changes
if subnode_id == 2: if subnode_id == 2:

View File

@ -69,7 +69,7 @@ def _resize_image(image, opts):
img = Image.open(io.BytesIO(image)) img = Image.open(io.BytesIO(image))
imgfmt = str(img.format) imgfmt = str(img.format)
if imgfmt != 'PNG' and imgfmt != 'JPEG': if imgfmt not in ('PNG', 'JPEG'):
_LOGGER.debug("Image is of unsupported type: %s", imgfmt) _LOGGER.debug("Image is of unsupported type: %s", imgfmt)
return image return image

View File

@ -66,8 +66,7 @@ class VerisureSmartcam(Camera):
if not image_ids: if not image_ids:
return return
new_image_id = image_ids[0] new_image_id = image_ids[0]
if (new_image_id == '-1' or if new_image_id in ('-1', self._image_id):
self._image_id == new_image_id):
_LOGGER.debug("The image is the same, or loading image_id") _LOGGER.debug("The image is the same, or loading image_id")
return return
_LOGGER.debug("Download new image %s", new_image_id) _LOGGER.debug("Download new image %s", new_image_id)

View File

@ -145,7 +145,7 @@ class DaikinClimate(ClimateDevice):
if value is None: if value is None:
_LOGGER.error("Invalid value requested for key %s", key) _LOGGER.error("Invalid value requested for key %s", key)
else: else:
if value == "-" or value == "--": if value in ("-", "--"):
value = None value = None
elif cast_to_float: elif cast_to_float:
try: try:

View File

@ -308,7 +308,7 @@ class RadioThermostat(ClimateDevice):
def set_operation_mode(self, operation_mode): def set_operation_mode(self, operation_mode):
"""Set operation mode (auto, cool, heat, off).""" """Set operation mode (auto, cool, heat, off)."""
if operation_mode == STATE_OFF or operation_mode == STATE_AUTO: if operation_mode in (STATE_OFF, STATE_AUTO):
self.device.tmode = TEMP_MODE_TO_CODE[operation_mode] self.device.tmode = TEMP_MODE_TO_CODE[operation_mode]
# Setting t_cool or t_heat automatically changes tmode. # Setting t_cool or t_heat automatically changes tmode.

View File

@ -102,7 +102,7 @@ class TomatoDeviceScanner(DeviceScanner):
for param, value in \ for param, value in \
self.parse_api_pattern.findall(response.text): self.parse_api_pattern.findall(response.text):
if param == 'wldev' or param == 'dhcpd_lease': if param in ('wldev', 'dhcpd_lease'):
self.last_results[param] = \ self.last_results[param] = \
json.loads(value.replace("'", '"')) json.loads(value.replace("'", '"'))
return True return True

View File

@ -56,7 +56,7 @@ def _refresh_on_access_denied(func):
try: try:
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
except PermissionError: except PermissionError:
_LOGGER.warning("Invalid session detected." + _LOGGER.warning("Invalid session detected."
" Trying to refresh session_id and re-run RPC") " Trying to refresh session_id and re-run RPC")
self.session_id = _get_session_id( self.session_id = _get_session_id(
self.url, self.username, self.password) self.url, self.username, self.password)

View File

@ -81,7 +81,7 @@ def setup(hass, config):
device = hass.data[EGARDIA_DEVICE] = egardiadevice.EgardiaDevice( device = hass.data[EGARDIA_DEVICE] = egardiadevice.EgardiaDevice(
host, port, username, password, '', version) host, port, username, password, '', version)
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
_LOGGER.error("An error occurred accessing your Egardia device. " + _LOGGER.error("An error occurred accessing your Egardia device. "
"Please check config.") "Please check config.")
return False return False
except egardiadevice.UnauthorizedError: except egardiadevice.UnauthorizedError:
@ -108,7 +108,7 @@ def setup(hass, config):
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, handle_stop_event) hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, handle_stop_event)
except IOError: except IOError:
_LOGGER.error("Binding error occurred while starting " + _LOGGER.error("Binding error occurred while starting "
"EgardiaServer.") "EgardiaServer.")
return False return False

View File

@ -250,8 +250,7 @@ class TemplateFan(FanEntity):
await self._set_speed_script.async_run({ATTR_SPEED: speed}) await self._set_speed_script.async_run({ATTR_SPEED: speed})
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid speed: %s. ' + 'Received invalid speed: %s. Expected: %s.',
'Expected: %s.',
speed, self._speed_list) speed, self._speed_list)
async def async_oscillate(self, oscillating: bool) -> None: async def async_oscillate(self, oscillating: bool) -> None:
@ -265,8 +264,7 @@ class TemplateFan(FanEntity):
{ATTR_OSCILLATING: oscillating}) {ATTR_OSCILLATING: oscillating})
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid oscillating value: %s. ' + 'Received invalid oscillating value: %s. Expected: %s.',
'Expected: %s.',
oscillating, ', '.join(_VALID_OSC)) oscillating, ', '.join(_VALID_OSC))
async def async_set_direction(self, direction: str) -> None: async def async_set_direction(self, direction: str) -> None:
@ -280,8 +278,7 @@ class TemplateFan(FanEntity):
{ATTR_DIRECTION: direction}) {ATTR_DIRECTION: direction})
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid direction: %s. ' + 'Received invalid direction: %s. Expected: %s.',
'Expected: %s.',
direction, ', '.join(_VALID_DIRECTIONS)) direction, ', '.join(_VALID_DIRECTIONS))
async def async_added_to_hass(self): async def async_added_to_hass(self):
@ -319,8 +316,7 @@ class TemplateFan(FanEntity):
self._state = None self._state = None
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid fan is_on state: %s. ' + 'Received invalid fan is_on state: %s. Expected: %s.',
'Expected: %s.',
state, ', '.join(_VALID_STATES)) state, ', '.join(_VALID_STATES))
self._state = None self._state = None
@ -340,8 +336,7 @@ class TemplateFan(FanEntity):
self._speed = None self._speed = None
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid speed: %s. ' + 'Received invalid speed: %s. Expected: %s.',
'Expected: %s.',
speed, self._speed_list) speed, self._speed_list)
self._speed = None self._speed = None
@ -363,8 +358,8 @@ class TemplateFan(FanEntity):
self._oscillating = None self._oscillating = None
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid oscillating: %s. ' + 'Received invalid oscillating: %s. Expected: True/False.',
'Expected: True/False.', oscillating) oscillating)
self._oscillating = None self._oscillating = None
# Update direction if 'direction_template' is configured # Update direction if 'direction_template' is configured
@ -383,7 +378,6 @@ class TemplateFan(FanEntity):
self._direction = None self._direction = None
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid direction: %s. ' + 'Received invalid direction: %s. Expected: %s.',
'Expected: %s.',
direction, ', '.join(_VALID_DIRECTIONS)) direction, ', '.join(_VALID_DIRECTIONS))
self._direction = None self._direction = None

View File

@ -189,7 +189,7 @@ class StoredData(object):
with self._lock, open(self._data_file, 'rb') as myfile: with self._lock, open(self._data_file, 'rb') as myfile:
self._data = pickle.load(myfile) or {} self._data = pickle.load(myfile) or {}
self._cache_outdated = False self._cache_outdated = False
except: # noqa: E722 # pylint: disable=bare-except except: # noqa: E722 pylint: disable=bare-except
_LOGGER.error("Error loading data from pickled file %s", _LOGGER.error("Error loading data from pickled file %s",
self._data_file) self._data_file)
@ -207,7 +207,7 @@ class StoredData(object):
feed_id, self._data_file) feed_id, self._data_file)
try: try:
pickle.dump(self._data, myfile) pickle.dump(self._data, myfile)
except: # noqa: E722 # pylint: disable=bare-except except: # noqa: E722 pylint: disable=bare-except
_LOGGER.error( _LOGGER.error(
"Error saving pickled data to %s", self._data_file) "Error saving pickled data to %s", self._data_file)
self._cache_outdated = True self._cache_outdated = True

View File

@ -168,7 +168,7 @@ def get_accessory(hass, driver, state, aid, config):
def generate_aid(entity_id): def generate_aid(entity_id):
"""Generate accessory aid with zlib adler32.""" """Generate accessory aid with zlib adler32."""
aid = adler32(entity_id.encode('utf-8')) aid = adler32(entity_id.encode('utf-8'))
if aid == 0 or aid == 1: if aid in (0, 1):
return None return None
return aid return aid

View File

@ -181,6 +181,6 @@ class BinarySensor(HomeAccessory):
def update_state(self, new_state): def update_state(self, new_state):
"""Update accessory after state change.""" """Update accessory after state change."""
state = new_state.state state = new_state.state
detected = (state == STATE_ON) or (state == STATE_HOME) detected = state in (STATE_ON, STATE_HOME)
self.char_detected.set_value(detected) self.char_detected.set_value(detected)
_LOGGER.debug('%s: Set to %d', self.entity_id, detected) _LOGGER.debug('%s: Set to %d', self.entity_id, detected)

View File

@ -248,8 +248,7 @@ class LightTemplate(Light):
self._state = state in ('true', STATE_ON) self._state = state in ('true', STATE_ON)
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid light is_on state: %s. ' + 'Received invalid light is_on state: %s. Expected: %s',
'Expected: %s',
state, ', '.join(_VALID_STATES)) state, ', '.join(_VALID_STATES))
self._state = None self._state = None
@ -264,8 +263,7 @@ class LightTemplate(Light):
self._brightness = int(brightness) self._brightness = int(brightness)
else: else:
_LOGGER.error( _LOGGER.error(
'Received invalid brightness : %s' + 'Received invalid brightness : %s. Expected: 0-255',
'Expected: 0-255',
brightness) brightness)
self._brightness = None self._brightness = None

View File

@ -100,15 +100,14 @@ class AppleTvDevice(MediaPlayerDevice):
if self._playing: if self._playing:
from pyatv import const from pyatv import const
state = self._playing.play_state state = self._playing.play_state
if state == const.PLAY_STATE_IDLE or \ if state in (const.PLAY_STATE_IDLE, const.PLAY_STATE_NO_MEDIA,
state == const.PLAY_STATE_NO_MEDIA or \ const.PLAY_STATE_LOADING):
state == const.PLAY_STATE_LOADING:
return STATE_IDLE return STATE_IDLE
elif state == const.PLAY_STATE_PLAYING: elif state == const.PLAY_STATE_PLAYING:
return STATE_PLAYING return STATE_PLAYING
elif state == const.PLAY_STATE_PAUSED or \ elif state in (const.PLAY_STATE_PAUSED,
state == const.PLAY_STATE_FAST_FORWARD or \ const.PLAY_STATE_FAST_FORWARD,
state == const.PLAY_STATE_FAST_BACKWARD: const.PLAY_STATE_FAST_BACKWARD):
# Catch fast forward/backward here so "play" is default action # Catch fast forward/backward here so "play" is default action
return STATE_PAUSED return STATE_PAUSED
return STATE_STANDBY # Bad or unknown state? return STATE_STANDBY # Bad or unknown state?
@ -162,7 +161,7 @@ class AppleTvDevice(MediaPlayerDevice):
def media_position_updated_at(self): def media_position_updated_at(self):
"""Last valid time of media position.""" """Last valid time of media position."""
state = self.state state = self.state
if state == STATE_PLAYING or state == STATE_PAUSED: if state in (STATE_PLAYING, STATE_PAUSED):
return dt_util.utcnow() return dt_util.utcnow()
@asyncio.coroutine @asyncio.coroutine

View File

@ -528,9 +528,9 @@ class BluesoundPlayer(MediaPlayerDevice):
return STATE_GROUPED return STATE_GROUPED
status = self._status.get('state', None) status = self._status.get('state', None)
if status == 'pause' or status == 'stop': if status in ('pause', 'stop'):
return STATE_PAUSED return STATE_PAUSED
elif status == 'stream' or status == 'play': elif status in ('stream', 'play'):
return STATE_PLAYING return STATE_PLAYING
return STATE_IDLE return STATE_IDLE

View File

@ -294,8 +294,7 @@ class PandoraMediaPlayer(MediaPlayerDevice):
time_remaining = int(cur_minutes) * 60 + int(cur_seconds) time_remaining = int(cur_minutes) * 60 + int(cur_seconds)
self._media_duration = int(total_minutes) * 60 + int(total_seconds) self._media_duration = int(total_minutes) * 60 + int(total_seconds)
if (time_remaining != self._time_remaining and if time_remaining not in (self._time_remaining, self._media_duration):
time_remaining != self._media_duration):
self._player_state = STATE_PLAYING self._player_state = STATE_PLAYING
elif self._player_state == STATE_PLAYING: elif self._player_state == STATE_PLAYING:
self._player_state = STATE_PAUSED self._player_state = STATE_PAUSED

View File

@ -153,7 +153,7 @@ class SamsungTVDevice(MediaPlayerDevice):
def send_key(self, key): def send_key(self, key):
"""Send a key to the tv and handles exceptions.""" """Send a key to the tv and handles exceptions."""
if self._power_off_in_progress() \ if self._power_off_in_progress() \
and not (key == 'KEY_POWER' or key == 'KEY_POWEROFF'): and key not in ('KEY_POWER', 'KEY_POWEROFF'):
_LOGGER.info("TV is powering off, not sending command: %s", key) _LOGGER.info("TV is powering off, not sending command: %s", key)
return return
try: try:

View File

@ -232,13 +232,13 @@ class XiaomiMiioRemote(RemoteDevice):
@asyncio.coroutine @asyncio.coroutine
def async_turn_on(self, **kwargs): def async_turn_on(self, **kwargs):
"""Turn the device on.""" """Turn the device on."""
_LOGGER.error("Device does not support turn_on, " + _LOGGER.error("Device does not support turn_on, "
"please use 'remote.send_command' to send commands.") "please use 'remote.send_command' to send commands.")
@asyncio.coroutine @asyncio.coroutine
def async_turn_off(self, **kwargs): def async_turn_off(self, **kwargs):
"""Turn the device off.""" """Turn the device off."""
_LOGGER.error("Device does not support turn_off, " + _LOGGER.error("Device does not support turn_off, "
"please use 'remote.send_command' to send commands.") "please use 'remote.send_command' to send commands.")
def _send_command(self, payload): def _send_command(self, payload):

View File

@ -56,9 +56,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
SENSOR_TYPES[sensor_type][0], arlo, sensor_type)) SENSOR_TYPES[sensor_type][0], arlo, sensor_type))
else: else:
for camera in arlo.cameras: for camera in arlo.cameras:
if sensor_type == 'temperature' or \ if sensor_type in ('temperature', 'humidity', 'air_quality'):
sensor_type == 'humidity' or \
sensor_type == 'air_quality':
continue continue
name = '{0} {1}'.format( name = '{0} {1}'.format(
@ -66,10 +64,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
sensors.append(ArloSensor(name, camera, sensor_type)) sensors.append(ArloSensor(name, camera, sensor_type))
for base_station in arlo.base_stations: for base_station in arlo.base_stations:
if ((sensor_type == 'temperature' or if sensor_type in ('temperature', 'humidity', 'air_quality') \
sensor_type == 'humidity' or and base_station.model_id == 'ABC1000':
sensor_type == 'air_quality') and
base_station.model_id == 'ABC1000'):
name = '{0} {1}'.format( name = '{0} {1}'.format(
SENSOR_TYPES[sensor_type][0], base_station.name) SENSOR_TYPES[sensor_type][0], base_station.name)
sensors.append(ArloSensor(name, base_station, sensor_type)) sensors.append(ArloSensor(name, base_station, sensor_type))

View File

@ -85,7 +85,7 @@ class DaikinClimateSensor(Entity):
if value is None: if value is None:
_LOGGER.warning("Invalid value requested for key %s", key) _LOGGER.warning("Invalid value requested for key %s", key)
else: else:
if value == "-" or value == "--": if value in ("-", "--"):
value = None value = None
elif cast_to_float: elif cast_to_float:
try: try:

View File

@ -70,7 +70,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
phonebook = FritzBoxPhonebook( phonebook = FritzBoxPhonebook(
host=host, port=port, username=username, password=password, host=host, port=port, username=username, password=password,
phonebook_id=phonebook_id, prefixes=prefixes) phonebook_id=phonebook_id, prefixes=prefixes)
except: # noqa: E722 # pylint: disable=bare-except except: # noqa: E722 pylint: disable=bare-except
phonebook = None phonebook = None
_LOGGER.warning("Phonebook with ID %s not found on Fritz!Box", _LOGGER.warning("Phonebook with ID %s not found on Fritz!Box",
phonebook_id) phonebook_id)

View File

@ -86,8 +86,8 @@ class IOSSensor(Entity):
battery_level = device_battery[ios.ATTR_BATTERY_LEVEL] battery_level = device_battery[ios.ATTR_BATTERY_LEVEL]
charging = True charging = True
icon_state = DEFAULT_ICON_STATE icon_state = DEFAULT_ICON_STATE
if (battery_state == ios.ATTR_BATTERY_STATE_FULL or if battery_state in (ios.ATTR_BATTERY_STATE_FULL,
battery_state == ios.ATTR_BATTERY_STATE_UNPLUGGED): ios.ATTR_BATTERY_STATE_UNPLUGGED):
charging = False charging = False
icon_state = "{}-off".format(DEFAULT_ICON_STATE) icon_state = "{}-off".format(DEFAULT_ICON_STATE)
elif battery_state == ios.ATTR_BATTERY_STATE_UNKNOWN: elif battery_state == ios.ATTR_BATTERY_STATE_UNKNOWN:

View File

@ -259,8 +259,7 @@ class ISYSensorDevice(ISYDevice):
if len(self._node.uom) == 1: if len(self._node.uom) == 1:
if self._node.uom[0] in UOM_FRIENDLY_NAME: if self._node.uom[0] in UOM_FRIENDLY_NAME:
friendly_name = UOM_FRIENDLY_NAME.get(self._node.uom[0]) friendly_name = UOM_FRIENDLY_NAME.get(self._node.uom[0])
if friendly_name == TEMP_CELSIUS or \ if friendly_name in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
friendly_name == TEMP_FAHRENHEIT:
friendly_name = self.hass.config.units.temperature_unit friendly_name = self.hass.config.units.temperature_unit
return friendly_name return friendly_name
else: else:

View File

@ -62,7 +62,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the MiFlora sensor.""" """Set up the MiFlora sensor."""
from miflora import miflora_poller from miflora import miflora_poller
try: try:
import bluepy.btle # noqa: F401 # pylint: disable=unused-variable import bluepy.btle # noqa: F401 pylint: disable=unused-variable
from btlewrap import BluepyBackend from btlewrap import BluepyBackend
backend = BluepyBackend backend = BluepyBackend
except ImportError: except ImportError:

View File

@ -60,7 +60,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the MiTempBt sensor.""" """Set up the MiTempBt sensor."""
from mitemp_bt import mitemp_bt_poller from mitemp_bt import mitemp_bt_poller
try: try:
import bluepy.btle # noqa: F401 # pylint: disable=unused-variable import bluepy.btle # noqa: F401 pylint: disable=unused-variable
from btlewrap import BluepyBackend from btlewrap import BluepyBackend
backend = BluepyBackend backend = BluepyBackend
except ImportError: except ImportError:

View File

@ -107,7 +107,7 @@ class OctoPrintSensor(Entity):
def state(self): def state(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
sensor_unit = self.unit_of_measurement sensor_unit = self.unit_of_measurement
if sensor_unit == TEMP_CELSIUS or sensor_unit == "%": if sensor_unit in (TEMP_CELSIUS, "%"):
# API sometimes returns null and not 0 # API sometimes returns null and not 0
if self._state is None: if self._state is None:
self._state = 0 self._state = 0

View File

@ -192,7 +192,7 @@ class QNAPStatsAPI(object):
self.data["smart_drive_health"] = self._api.get_smart_disk_health() self.data["smart_drive_health"] = self._api.get_smart_disk_health()
self.data["volumes"] = self._api.get_volumes() self.data["volumes"] = self._api.get_volumes()
self.data["bandwidth"] = self._api.get_bandwidth() self.data["bandwidth"] = self._api.get_bandwidth()
except: # noqa: E722 # pylint: disable=bare-except except: # noqa: E722 pylint: disable=bare-except
_LOGGER.exception("Failed to fetch QNAP stats from the NAS") _LOGGER.exception("Failed to fetch QNAP stats from the NAS")

View File

@ -140,7 +140,7 @@ class SynoApi(object):
try: try:
self._api = SynologyDSM(host, port, username, password, self._api = SynologyDSM(host, port, username, password,
use_https=use_ssl) use_https=use_ssl)
except: # noqa: E722 # pylint: disable=bare-except except: # noqa: E722 pylint: disable=bare-except
_LOGGER.error("Error setting up Synology DSM") _LOGGER.error("Error setting up Synology DSM")
# Will be updated when update() gets called. # Will be updated when update() gets called.

View File

@ -151,7 +151,7 @@ def _ws_process_message(message, async_callback, *args):
"Unsuccessful websocket message delivered, ignoring: %s", message) "Unsuccessful websocket message delivered, ignoring: %s", message)
try: try:
yield from async_callback(message['data']['sia'], *args) yield from async_callback(message['data']['sia'], *args)
except: # noqa: E722 # pylint: disable=bare-except except: # noqa: E722 pylint: disable=bare-except
_LOGGER.exception("Exception in callback, ignoring") _LOGGER.exception("Exception in callback, ignoring")

View File

@ -452,7 +452,7 @@ def setup(hass, config):
_man = siren.wink.device_manufacturer() _man = siren.wink.device_manufacturer()
if (service.service != SERVICE_SET_AUTO_SHUTOFF and if (service.service != SERVICE_SET_AUTO_SHUTOFF and
service.service != SERVICE_ENABLE_SIREN and service.service != SERVICE_ENABLE_SIREN and
(_man != 'dome' and _man != 'wink')): _man not in ('dome', 'wink')):
_LOGGER.error("Service only valid for Dome or Wink sirens") _LOGGER.error("Service only valid for Dome or Wink sirens")
return return
@ -487,7 +487,7 @@ def setup(hass, config):
has_dome_or_wink_siren = False has_dome_or_wink_siren = False
for siren in pywink.get_sirens(): for siren in pywink.get_sirens():
_man = siren.device_manufacturer() _man = siren.device_manufacturer()
if _man == "dome" or _man == "wink": if _man in ("dome", "wink"):
has_dome_or_wink_siren = True has_dome_or_wink_siren = True
_id = siren.object_id() + siren.name() _id = siren.object_id() + siren.name()
if _id not in hass.data[DOMAIN]['unique_ids']: if _id not in hass.data[DOMAIN]['unique_ids']:

View File

@ -246,13 +246,11 @@ def sun(hass, before=None, after=None, before_offset=None, after_offset=None):
sunrise = get_astral_event_date(hass, 'sunrise', today) sunrise = get_astral_event_date(hass, 'sunrise', today)
sunset = get_astral_event_date(hass, 'sunset', today) sunset = get_astral_event_date(hass, 'sunset', today)
if sunrise is None and (before == SUN_EVENT_SUNRISE or if sunrise is None and SUN_EVENT_SUNRISE in (before, after):
after == SUN_EVENT_SUNRISE):
# There is no sunrise today # There is no sunrise today
return False return False
if sunset is None and (before == SUN_EVENT_SUNSET or if sunset is None and SUN_EVENT_SUNSET in (before, after):
after == SUN_EVENT_SUNSET):
# There is no sunset today # There is no sunset today
return False return False

View File

@ -89,7 +89,7 @@ class TestEmulatedHue(unittest.TestCase):
# Make sure the XML is parsable # Make sure the XML is parsable
try: try:
ET.fromstring(result.text) ET.fromstring(result.text)
except: # noqa: E722 # pylint: disable=bare-except except: # noqa: E722 pylint: disable=bare-except
self.fail('description.xml is not valid XML!') self.fail('description.xml is not valid XML!')
def test_create_username(self): def test_create_username(self):

View File

@ -28,7 +28,7 @@ async def get_error_log(hass, aiohttp_client, expected_count):
def _generate_and_log_exception(exception, log): def _generate_and_log_exception(exception, log):
try: try:
raise Exception(exception) raise Exception(exception)
except: # noqa: E722 # pylint: disable=bare-except except: # noqa: E722 pylint: disable=bare-except
_LOGGER.exception(log) _LOGGER.exception(log)