diff --git a/homeassistant/components/bayesian/binary_sensor.py b/homeassistant/components/bayesian/binary_sensor.py index c4150131901..bd0fa797fd0 100644 --- a/homeassistant/components/bayesian/binary_sensor.py +++ b/homeassistant/components/bayesian/binary_sensor.py @@ -91,8 +91,7 @@ def update_probability(prior, prob_given_true, prob_given_false): """Update probability using Bayes' rule.""" numerator = prob_given_true * prior denominator = numerator + prob_given_false * (1 - prior) - probability = numerator / denominator - return probability + return numerator / denominator async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): @@ -246,7 +245,7 @@ class BayesianBinarySensor(BinarySensorEntity): """Return True if numeric condition is met.""" entity = entity_observation["entity_id"] - should_trigger = condition.async_numeric_state( + return condition.async_numeric_state( self.hass, entity, entity_observation.get("below"), @@ -254,26 +253,18 @@ class BayesianBinarySensor(BinarySensorEntity): None, entity_observation, ) - return should_trigger def _process_state(self, entity_observation): """Return True if state conditions are met.""" entity = entity_observation["entity_id"] - should_trigger = condition.state( - self.hass, entity, entity_observation.get("to_state") - ) - - return should_trigger + return condition.state(self.hass, entity, entity_observation.get("to_state")) def _process_template(self, entity_observation): """Return True if template condition is True.""" template = entity_observation.get(CONF_VALUE_TEMPLATE) template.hass = self.hass - should_trigger = condition.async_template( - self.hass, template, entity_observation - ) - return should_trigger + return condition.async_template(self.hass, template, entity_observation) @property def name(self): @@ -299,9 +290,9 @@ class BayesianBinarySensor(BinarySensorEntity): def device_state_attributes(self): """Return the state attributes of the sensor.""" - attr_observations_list = list( + attr_observations_list = [ obs.copy() for obs in self.current_observations.values() if obs is not None - ) + ] for item in attr_observations_list: item.pop("value_template", None) diff --git a/homeassistant/components/blebox/__init__.py b/homeassistant/components/blebox/__init__.py index dcdd4c7f1e4..37b5569beb5 100644 --- a/homeassistant/components/blebox/__init__.py +++ b/homeassistant/components/blebox/__init__.py @@ -77,10 +77,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): def create_blebox_entities(product, async_add, entity_klass, entity_type): """Create entities from a BleBox product's features.""" - entities = [] - for feature in product.features[entity_type]: - entities.append(entity_klass(feature)) - + entities = [entity_klass(feature) for feature in product.features[entity_type]] async_add(entities, True) diff --git a/homeassistant/components/demo/climate.py b/homeassistant/components/demo/climate.py index 9733d0f1147..fd5615c82bd 100644 --- a/homeassistant/components/demo/climate.py +++ b/homeassistant/components/demo/climate.py @@ -134,8 +134,6 @@ class DemoClimate(ClimateEntity): self._support_flags = self._support_flags | SUPPORT_TARGET_HUMIDITY if swing_mode is not None: self._support_flags = self._support_flags | SUPPORT_SWING_MODE - if hvac_action is not None: - self._support_flags = self._support_flags if aux is not None: self._support_flags = self._support_flags | SUPPORT_AUX_HEAT if HVAC_MODE_HEAT_COOL in hvac_modes or HVAC_MODE_AUTO in hvac_modes: diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index c956308ab8e..a65029fa4cd 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -288,7 +288,7 @@ class Thermostat(ClimateEntity): else: await self.data.update() self.thermostat = self.data.ecobee.get_thermostat(self.thermostat_index) - if self.hvac_mode is not HVAC_MODE_OFF: + if self.hvac_mode != HVAC_MODE_OFF: self._last_active_hvac_mode = self.hvac_mode @property diff --git a/homeassistant/components/google_assistant/__init__.py b/homeassistant/components/google_assistant/__init__.py index 2d848101def..160ec024c81 100644 --- a/homeassistant/components/google_assistant/__init__.py +++ b/homeassistant/components/google_assistant/__init__.py @@ -55,11 +55,8 @@ GOOGLE_SERVICE_ACCOUNT = vol.Schema( def _check_report_state(data): - if data[CONF_REPORT_STATE]: - if CONF_SERVICE_ACCOUNT not in data: - raise vol.Invalid( - "If report state is enabled, a service account must exist" - ) + if data[CONF_REPORT_STATE] and CONF_SERVICE_ACCOUNT not in data: + raise vol.Invalid("If report state is enabled, a service account must exist") return data diff --git a/homeassistant/components/horizon/media_player.py b/homeassistant/components/horizon/media_player.py index 79a94538b70..0ed98f73a38 100644 --- a/homeassistant/components/horizon/media_player.py +++ b/homeassistant/components/horizon/media_player.py @@ -116,12 +116,12 @@ class HorizonDevice(MediaPlayerEntity): def turn_on(self): """Turn the device on.""" - if self._state is STATE_OFF: + if self._state == STATE_OFF: self._send_key(self._keys.POWER) def turn_off(self): """Turn the device off.""" - if self._state is not STATE_OFF: + if self._state != STATE_OFF: self._send_key(self._keys.POWER) def media_previous_track(self): diff --git a/homeassistant/components/maxcube/climate.py b/homeassistant/components/maxcube/climate.py index ccfd44af4f7..69d9177da5d 100644 --- a/homeassistant/components/maxcube/climate.py +++ b/homeassistant/components/maxcube/climate.py @@ -144,14 +144,11 @@ class MaxCubeClimate(ClimateEntity): """Set new target hvac mode.""" device = self._cubehandle.cube.device_by_rf(self._rf_address) temp = device.target_temperature - mode = device.mode + mode = MAX_DEVICE_MODE_MANUAL if hvac_mode == HVAC_MODE_OFF: temp = OFF_TEMPERATURE - mode = MAX_DEVICE_MODE_MANUAL - elif hvac_mode == HVAC_MODE_HEAT: - mode = MAX_DEVICE_MODE_MANUAL - else: + elif hvac_mode != HVAC_MODE_HEAT: # Reset the temperature to a sane value. # Ideally, we should send 0 and the device will set its # temperature according to the schedule. However, current diff --git a/homeassistant/components/modbus/sensor.py b/homeassistant/components/modbus/sensor.py index 64fbc466b1c..8bf5f6f3115 100644 --- a/homeassistant/components/modbus/sensor.py +++ b/homeassistant/components/modbus/sensor.py @@ -99,9 +99,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Modbus sensors.""" sensors = [] - data_types = {DATA_TYPE_INT: {1: "h", 2: "i", 4: "q"}} - data_types[DATA_TYPE_UINT] = {1: "H", 2: "I", 4: "Q"} - data_types[DATA_TYPE_FLOAT] = {1: "e", 2: "f", 4: "d"} + data_types = { + DATA_TYPE_INT: {1: "h", 2: "i", 4: "q"}, + DATA_TYPE_UINT: {1: "H", 2: "I", 4: "Q"}, + DATA_TYPE_FLOAT: {1: "e", 2: "f", 4: "d"}, + } for register in config[CONF_REGISTERS]: structure = ">i" diff --git a/homeassistant/components/modbus/switch.py b/homeassistant/components/modbus/switch.py index 0d5a32c45e0..8037d926ef1 100644 --- a/homeassistant/components/modbus/switch.py +++ b/homeassistant/components/modbus/switch.py @@ -170,10 +170,8 @@ class ModbusCoilSwitch(ToggleEntity, RestoreEntity): self._available = False return - value = bool(result.bits[0]) self._available = True - - return value + return bool(result.bits[0]) def _write_coil(self, coil, value): """Write coil using the Modbus hub slave.""" @@ -288,10 +286,9 @@ class ModbusRegisterSwitch(ModbusCoilSwitch): self._available = False return - value = int(result.registers[0]) self._available = True - return value + return int(result.registers[0]) def _write_register(self, value): """Write holding register using the Modbus hub slave.""" diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index 6565be0c5c9..b4dc9530b90 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -325,9 +325,7 @@ def soco_error(errorcodes=None): try: return funct(*args, **kwargs) except SoCoUPnPException as err: - if errorcodes and err.error_code in errorcodes: - pass - else: + if not errorcodes or err.error_code not in errorcodes: _LOGGER.error("Error on %s with %s", funct.__name__, err) except SoCoException as err: _LOGGER.error("Error on %s with %s", funct.__name__, err) @@ -605,7 +603,6 @@ class SonosEntity(MediaPlayerEntity): variables = event and event.variables self.update_media_radio(variables, track_info) else: - variables = event and event.variables self.update_media_music(update_position, track_info) self.schedule_update_ha_state() diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 4569816eb7d..9a33c0514d5 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -438,9 +438,8 @@ class SpeechManager: album = provider.name artist = language - if options is not None: - if options.get("voice") is not None: - artist = options.get("voice") + if options is not None and options.get("voice") is not None: + artist = options.get("voice") try: tts_file = mutagen.File(data_bytes, easy=True) diff --git a/homeassistant/components/volumio/media_player.py b/homeassistant/components/volumio/media_player.py index 8d50f56bd65..82114cda68b 100644 --- a/homeassistant/components/volumio/media_player.py +++ b/homeassistant/components/volumio/media_player.py @@ -144,11 +144,7 @@ class Volumio(MediaPlayerEntity): ) return False - try: - return data - except AttributeError: - _LOGGER.error("Received invalid response: %s", data) - return False + return data async def async_update(self): """Update state.""" diff --git a/homeassistant/components/xiaomi_tv/media_player.py b/homeassistant/components/xiaomi_tv/media_player.py index c247559766b..6c0a55f787d 100644 --- a/homeassistant/components/xiaomi_tv/media_player.py +++ b/homeassistant/components/xiaomi_tv/media_player.py @@ -87,14 +87,14 @@ class XiaomiTV(MediaPlayerEntity): because the TV won't accept any input when turned off. Thus, the user would be unable to turn the TV back on, unless it's done manually. """ - if self._state is not STATE_OFF: + if self._state != STATE_OFF: self._tv.sleep() self._state = STATE_OFF def turn_on(self): """Wake the TV back up from sleep.""" - if self._state is not STATE_ON: + if self._state != STATE_ON: self._tv.wake() self._state = STATE_ON diff --git a/homeassistant/components/yamaha_musiccast/media_player.py b/homeassistant/components/yamaha_musiccast/media_player.py index 32f223f6728..bfec5b932a8 100644 --- a/homeassistant/components/yamaha_musiccast/media_player.py +++ b/homeassistant/components/yamaha_musiccast/media_player.py @@ -133,7 +133,7 @@ class YamahaDevice(MediaPlayerEntity): @property def state(self): """Return the state of the device.""" - if self.power == STATE_ON and self.status is not STATE_UNKNOWN: + if self.power == STATE_ON and self.status != STATE_UNKNOWN: return self.status return self.power