Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/isy994.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setup_platform(hass, config: ConfigType,
else:
device_type = _detect_device_type(node)
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
# all state changes
if subnode_id == 2:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/camera/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _resize_image(image, opts):

img = Image.open(io.BytesIO(image))
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)
return image

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/camera/verisure.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def check_imagelist(self):
if not image_ids:
return
new_image_id = image_ids[0]
if (new_image_id == '-1' or
self._image_id == new_image_id):
if new_image_id in ('-1', self._image_id):
_LOGGER.debug("The image is the same, or loading image_id")
return
_LOGGER.debug("Download new image %s", new_image_id)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/climate/daikin.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get(self, key):
if value is None:
_LOGGER.error("Invalid value requested for key %s", key)
else:
if value == "-" or value == "--":
if value in ("-", "--"):
value = None
elif cast_to_float:
try:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/climate/radiotherm.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def set_time(self):

def set_operation_mode(self, operation_mode):
"""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]

# Setting t_cool or t_heat automatically changes tmode.
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/device_tracker/tomato.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _update_tomato_info(self):
for param, value in \
self.parse_api_pattern.findall(response.text):

if param == 'wldev' or param == 'dhcpd_lease':
if param in ('wldev', 'dhcpd_lease'):
self.last_results[param] = \
json.loads(value.replace("'", '"'))
return True
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/device_tracker/ubus.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def decorator(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except PermissionError:
_LOGGER.warning("Invalid session detected." +
_LOGGER.warning("Invalid session detected."
" Trying to refresh session_id and re-run RPC")
self.session_id = _get_session_id(
self.url, self.username, self.password)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/egardia.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def setup(hass, config):
device = hass.data[EGARDIA_DEVICE] = egardiadevice.EgardiaDevice(
host, port, username, password, '', version)
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.")
return False
except egardiadevice.UnauthorizedError:
Expand All @@ -108,7 +108,7 @@ def handle_stop_event(event):
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, handle_stop_event)

except IOError:
_LOGGER.error("Binding error occurred while starting " +
_LOGGER.error("Binding error occurred while starting "
"EgardiaServer.")
return False

Expand Down
22 changes: 8 additions & 14 deletions homeassistant/components/fan/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ async def async_set_speed(self, speed: str) -> None:
await self._set_speed_script.async_run({ATTR_SPEED: speed})
else:
_LOGGER.error(
'Received invalid speed: %s. ' +
'Expected: %s.',
'Received invalid speed: %s. Expected: %s.',
speed, self._speed_list)

async def async_oscillate(self, oscillating: bool) -> None:
Expand All @@ -265,8 +264,7 @@ async def async_oscillate(self, oscillating: bool) -> None:
{ATTR_OSCILLATING: oscillating})
else:
_LOGGER.error(
'Received invalid oscillating value: %s. ' +
'Expected: %s.',
'Received invalid oscillating value: %s. Expected: %s.',
oscillating, ', '.join(_VALID_OSC))

async def async_set_direction(self, direction: str) -> None:
Expand All @@ -280,8 +278,7 @@ async def async_set_direction(self, direction: str) -> None:
{ATTR_DIRECTION: direction})
else:
_LOGGER.error(
'Received invalid direction: %s. ' +
'Expected: %s.',
'Received invalid direction: %s. Expected: %s.',
direction, ', '.join(_VALID_DIRECTIONS))

async def async_added_to_hass(self):
Expand Down Expand Up @@ -319,8 +316,7 @@ async def async_update(self):
self._state = None
else:
_LOGGER.error(
'Received invalid fan is_on state: %s. ' +
'Expected: %s.',
'Received invalid fan is_on state: %s. Expected: %s.',
state, ', '.join(_VALID_STATES))
self._state = None

Expand All @@ -340,8 +336,7 @@ async def async_update(self):
self._speed = None
else:
_LOGGER.error(
'Received invalid speed: %s. ' +
'Expected: %s.',
'Received invalid speed: %s. Expected: %s.',
speed, self._speed_list)
self._speed = None

Expand All @@ -363,8 +358,8 @@ async def async_update(self):
self._oscillating = None
else:
_LOGGER.error(
'Received invalid oscillating: %s. ' +
'Expected: True/False.', oscillating)
'Received invalid oscillating: %s. Expected: True/False.',
oscillating)
self._oscillating = None

# Update direction if 'direction_template' is configured
Expand All @@ -383,7 +378,6 @@ async def async_update(self):
self._direction = None
else:
_LOGGER.error(
'Received invalid direction: %s. ' +
'Expected: %s.',
'Received invalid direction: %s. Expected: %s.',
direction, ', '.join(_VALID_DIRECTIONS))
self._direction = None
4 changes: 2 additions & 2 deletions homeassistant/components/feedreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _fetch_data(self):
with self._lock, open(self._data_file, 'rb') as myfile:
self._data = pickle.load(myfile) or {}
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",
self._data_file)

Expand All @@ -207,7 +207,7 @@ def put_timestamp(self, feed_id, timestamp):
feed_id, self._data_file)
try:
pickle.dump(self._data, myfile)
except: # noqa: E722 # pylint: disable=bare-except
except: # noqa: E722 pylint: disable=bare-except
_LOGGER.error(
"Error saving pickled data to %s", self._data_file)
self._cache_outdated = True
2 changes: 1 addition & 1 deletion homeassistant/components/homekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_accessory(hass, driver, state, aid, config):
def generate_aid(entity_id):
"""Generate accessory aid with zlib adler32."""
aid = adler32(entity_id.encode('utf-8'))
if aid == 0 or aid == 1:
if aid in (0, 1):
return None
return aid

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/homekit/type_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,6 @@ def __init__(self, *args):
def update_state(self, new_state):
"""Update accessory after state change."""
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)
_LOGGER.debug('%s: Set to %d', self.entity_id, detected)
6 changes: 2 additions & 4 deletions homeassistant/components/light/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ def async_update(self):
self._state = state in ('true', STATE_ON)
else:
_LOGGER.error(
'Received invalid light is_on state: %s. ' +
'Expected: %s',
'Received invalid light is_on state: %s. Expected: %s',
state, ', '.join(_VALID_STATES))
self._state = None

Expand All @@ -264,8 +263,7 @@ def async_update(self):
self._brightness = int(brightness)
else:
_LOGGER.error(
'Received invalid brightness : %s' +
'Expected: 0-255',
'Received invalid brightness : %s. Expected: 0-255',
brightness)
self._brightness = None

Expand Down
13 changes: 6 additions & 7 deletions homeassistant/components/media_player/apple_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,14 @@ def state(self):
if self._playing:
from pyatv import const
state = self._playing.play_state
if state == const.PLAY_STATE_IDLE or \
state == const.PLAY_STATE_NO_MEDIA or \
state == const.PLAY_STATE_LOADING:
if state in (const.PLAY_STATE_IDLE, const.PLAY_STATE_NO_MEDIA,
const.PLAY_STATE_LOADING):
return STATE_IDLE
elif state == const.PLAY_STATE_PLAYING:
return STATE_PLAYING
elif state == const.PLAY_STATE_PAUSED or \
state == const.PLAY_STATE_FAST_FORWARD or \
state == const.PLAY_STATE_FAST_BACKWARD:
elif state in (const.PLAY_STATE_PAUSED,
const.PLAY_STATE_FAST_FORWARD,
const.PLAY_STATE_FAST_BACKWARD):
# Catch fast forward/backward here so "play" is default action
return STATE_PAUSED
return STATE_STANDBY # Bad or unknown state?
Expand Down Expand Up @@ -162,7 +161,7 @@ def media_position(self):
def media_position_updated_at(self):
"""Last valid time of media position."""
state = self.state
if state == STATE_PLAYING or state == STATE_PAUSED:
if state in (STATE_PLAYING, STATE_PAUSED):
return dt_util.utcnow()

@asyncio.coroutine
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/media_player/bluesound.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ def state(self):
return STATE_GROUPED

status = self._status.get('state', None)
if status == 'pause' or status == 'stop':
if status in ('pause', 'stop'):
return STATE_PAUSED
elif status == 'stream' or status == 'play':
elif status in ('stream', 'play'):
return STATE_PLAYING
return STATE_IDLE

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/media_player/pandora.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ def _update_song_position(self):
time_remaining = int(cur_minutes) * 60 + int(cur_seconds)
self._media_duration = int(total_minutes) * 60 + int(total_seconds)

if (time_remaining != self._time_remaining and
time_remaining != self._media_duration):
if time_remaining not in (self._time_remaining, self._media_duration):
self._player_state = STATE_PLAYING
elif self._player_state == STATE_PLAYING:
self._player_state = STATE_PAUSED
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/media_player/samsungtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_remote(self):
def send_key(self, key):
"""Send a key to the tv and handles exceptions."""
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)
return
try:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/remote/xiaomi_miio.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ def device_state_attributes(self):
@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""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.")

@asyncio.coroutine
def async_turn_off(self, **kwargs):
"""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.")

def _send_command(self, payload):
Expand Down
10 changes: 3 additions & 7 deletions homeassistant/components/sensor/arlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
SENSOR_TYPES[sensor_type][0], arlo, sensor_type))
else:
for camera in arlo.cameras:
if sensor_type == 'temperature' or \
sensor_type == 'humidity' or \
sensor_type == 'air_quality':
if sensor_type in ('temperature', 'humidity', 'air_quality'):
continue

name = '{0} {1}'.format(
SENSOR_TYPES[sensor_type][0], camera.name)
sensors.append(ArloSensor(name, camera, sensor_type))

for base_station in arlo.base_stations:
if ((sensor_type == 'temperature' or
sensor_type == 'humidity' or
sensor_type == 'air_quality') and
base_station.model_id == 'ABC1000'):
if sensor_type in ('temperature', 'humidity', 'air_quality') \
and base_station.model_id == 'ABC1000':
name = '{0} {1}'.format(
SENSOR_TYPES[sensor_type][0], base_station.name)
sensors.append(ArloSensor(name, base_station, sensor_type))
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/daikin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get(self, key):
if value is None:
_LOGGER.warning("Invalid value requested for key %s", key)
else:
if value == "-" or value == "--":
if value in ("-", "--"):
value = None
elif cast_to_float:
try:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/fritzbox_callmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
phonebook = FritzBoxPhonebook(
host=host, port=port, username=username, password=password,
phonebook_id=phonebook_id, prefixes=prefixes)
except: # noqa: E722 # pylint: disable=bare-except
except: # noqa: E722 pylint: disable=bare-except
phonebook = None
_LOGGER.warning("Phonebook with ID %s not found on Fritz!Box",
phonebook_id)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/sensor/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def icon(self):
battery_level = device_battery[ios.ATTR_BATTERY_LEVEL]
charging = True
icon_state = DEFAULT_ICON_STATE
if (battery_state == ios.ATTR_BATTERY_STATE_FULL or
battery_state == ios.ATTR_BATTERY_STATE_UNPLUGGED):
if battery_state in (ios.ATTR_BATTERY_STATE_FULL,
ios.ATTR_BATTERY_STATE_UNPLUGGED):
charging = False
icon_state = "{}-off".format(DEFAULT_ICON_STATE)
elif battery_state == ios.ATTR_BATTERY_STATE_UNKNOWN:
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/sensor/isy994.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ def raw_unit_of_measurement(self) -> str:
if len(self._node.uom) == 1:
if self._node.uom[0] in UOM_FRIENDLY_NAME:
friendly_name = UOM_FRIENDLY_NAME.get(self._node.uom[0])
if friendly_name == TEMP_CELSIUS or \
friendly_name == TEMP_FAHRENHEIT:
if friendly_name in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
friendly_name = self.hass.config.units.temperature_unit
return friendly_name
else:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/miflora.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the MiFlora sensor."""
from miflora import miflora_poller
try:
import bluepy.btle # noqa: F401 # pylint: disable=unused-variable
import bluepy.btle # noqa: F401 pylint: disable=unused-variable
from btlewrap import BluepyBackend
backend = BluepyBackend
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/mitemp_bt.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the MiTempBt sensor."""
from mitemp_bt import mitemp_bt_poller
try:
import bluepy.btle # noqa: F401 # pylint: disable=unused-variable
import bluepy.btle # noqa: F401 pylint: disable=unused-variable
from btlewrap import BluepyBackend
backend = BluepyBackend
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/octoprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def name(self):
def state(self):
"""Return the state of the sensor."""
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
if self._state is None:
self._state = 0
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/qnap.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def update(self):
self.data["smart_drive_health"] = self._api.get_smart_disk_health()
self.data["volumes"] = self._api.get_volumes()
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")


Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/synologydsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, host, port, username, password, temp_unit, use_ssl):
try:
self._api = SynologyDSM(host, port, username, password,
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")

# Will be updated when update() gets called.
Expand Down
Loading