From fb849b81b5307a25112b89f8994f83fb8fc1f4f1 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 20 Mar 2021 01:27:04 +0100 Subject: [PATCH] Rewrite of not a == b occurances (#48132) --- homeassistant/components/glances/sensor.py | 2 +- homeassistant/components/isy994/helpers.py | 4 ++-- homeassistant/components/isy994/services.py | 8 ++++---- .../components/openhome/media_player.py | 2 +- homeassistant/components/proxy/camera.py | 2 +- .../components/pulseaudio_loopback/switch.py | 2 +- homeassistant/components/roon/media_player.py | 2 +- homeassistant/components/vlc/media_player.py | 2 +- homeassistant/components/zha/device_tracker.py | 2 +- homeassistant/components/zwave_js/sensor.py | 4 ++-- homeassistant/helpers/template.py | 2 +- homeassistant/util/timeout.py | 2 +- script/hassfest/coverage.py | 4 ++-- tests/components/mqtt/test_cover.py | 18 +++++++++--------- tests/components/pilight/test_init.py | 2 +- tests/components/recorder/test_purge.py | 2 +- .../components/universal/test_media_player.py | 2 +- 17 files changed, 31 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/glances/sensor.py b/homeassistant/components/glances/sensor.py index 4c534a90ae1..006333b321a 100644 --- a/homeassistant/components/glances/sensor.py +++ b/homeassistant/components/glances/sensor.py @@ -15,7 +15,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): dev = [] for sensor_type, sensor_details in SENSOR_TYPES.items(): - if not sensor_details[0] in client.api.data: + if sensor_details[0] not in client.api.data: continue if sensor_details[0] in client.api.data: if sensor_details[0] == "fs": diff --git a/homeassistant/components/isy994/helpers.py b/homeassistant/components/isy994/helpers.py index 780e24843bd..81a74430d3a 100644 --- a/homeassistant/components/isy994/helpers.py +++ b/homeassistant/components/isy994/helpers.py @@ -326,7 +326,7 @@ def _categorize_programs(hass_isy_data: dict, programs: Programs) -> None: actions = None status = entity_folder.get_by_name(KEY_STATUS) - if not status or not status.protocol == PROTO_PROGRAM: + if not status or status.protocol != PROTO_PROGRAM: _LOGGER.warning( "Program %s entity '%s' not loaded, invalid/missing status program", platform, @@ -336,7 +336,7 @@ def _categorize_programs(hass_isy_data: dict, programs: Programs) -> None: if platform != BINARY_SENSOR: actions = entity_folder.get_by_name(KEY_ACTIONS) - if not actions or not actions.protocol == PROTO_PROGRAM: + if not actions or actions.protocol != PROTO_PROGRAM: _LOGGER.warning( "Program %s entity '%s' not loaded, invalid/missing actions program", platform, diff --git a/homeassistant/components/isy994/services.py b/homeassistant/components/isy994/services.py index b9c4bcdeef2..39966a9d994 100644 --- a/homeassistant/components/isy994/services.py +++ b/homeassistant/components/isy994/services.py @@ -174,7 +174,7 @@ def async_setup_services(hass: HomeAssistantType): for config_entry_id in hass.data[DOMAIN]: isy = hass.data[DOMAIN][config_entry_id][ISY994_ISY] - if isy_name and not isy_name == isy.configuration["name"]: + if isy_name and isy_name != isy.configuration["name"]: continue # If an address is provided, make sure we query the correct ISY. # Otherwise, query the whole system on all ISY's connected. @@ -199,7 +199,7 @@ def async_setup_services(hass: HomeAssistantType): for config_entry_id in hass.data[DOMAIN]: isy = hass.data[DOMAIN][config_entry_id][ISY994_ISY] - if isy_name and not isy_name == isy.configuration["name"]: + if isy_name and isy_name != isy.configuration["name"]: continue if not hasattr(isy, "networking") or isy.networking is None: continue @@ -224,7 +224,7 @@ def async_setup_services(hass: HomeAssistantType): for config_entry_id in hass.data[DOMAIN]: isy = hass.data[DOMAIN][config_entry_id][ISY994_ISY] - if isy_name and not isy_name == isy.configuration["name"]: + if isy_name and isy_name != isy.configuration["name"]: continue program = None if address: @@ -247,7 +247,7 @@ def async_setup_services(hass: HomeAssistantType): for config_entry_id in hass.data[DOMAIN]: isy = hass.data[DOMAIN][config_entry_id][ISY994_ISY] - if isy_name and not isy_name == isy.configuration["name"]: + if isy_name and isy_name != isy.configuration["name"]: continue variable = None if name: diff --git a/homeassistant/components/openhome/media_player.py b/homeassistant/components/openhome/media_player.py index f9dbd4272ba..270eb22ebda 100644 --- a/homeassistant/components/openhome/media_player.py +++ b/homeassistant/components/openhome/media_player.py @@ -139,7 +139,7 @@ class OpenhomeDevice(MediaPlayerEntity): def play_media(self, media_type, media_id, **kwargs): """Send the play_media command to the media player.""" - if not media_type == MEDIA_TYPE_MUSIC: + if media_type != MEDIA_TYPE_MUSIC: _LOGGER.error( "Invalid media type %s. Only %s is supported", media_type, diff --git a/homeassistant/components/proxy/camera.py b/homeassistant/components/proxy/camera.py index c3f7151431a..8fda507ace2 100644 --- a/homeassistant/components/proxy/camera.py +++ b/homeassistant/components/proxy/camera.py @@ -77,7 +77,7 @@ def _precheck_image(image, opts): if imgfmt not in ("PNG", "JPEG"): _LOGGER.warning("Image is of unsupported type: %s", imgfmt) raise ValueError() - if not img.mode == "RGB": + if img.mode != "RGB": img = img.convert("RGB") return img diff --git a/homeassistant/components/pulseaudio_loopback/switch.py b/homeassistant/components/pulseaudio_loopback/switch.py index 9c27ab4e027..260fbe65c1b 100644 --- a/homeassistant/components/pulseaudio_loopback/switch.py +++ b/homeassistant/components/pulseaudio_loopback/switch.py @@ -73,7 +73,7 @@ class PALoopbackSwitch(SwitchEntity): self._pa_svr.connect() for module in self._pa_svr.module_list(): - if not module.name == "module-loopback": + if module.name != "module-loopback": continue if f"sink={self._sink_name}" not in module.argument: diff --git a/homeassistant/components/roon/media_player.py b/homeassistant/components/roon/media_player.py index b2ae62ec250..773028da2d3 100644 --- a/homeassistant/components/roon/media_player.py +++ b/homeassistant/components/roon/media_player.py @@ -465,7 +465,7 @@ class RoonDevice(MediaPlayerEntity): return for source in self.player_data["source_controls"]: - if source["supports_standby"] and not source["status"] == "indeterminate": + if source["supports_standby"] and source["status"] != "indeterminate": self._server.roonapi.standby(self.output_id, source["control_key"]) return diff --git a/homeassistant/components/vlc/media_player.py b/homeassistant/components/vlc/media_player.py index fe387dd4adc..db5c26f4a0c 100644 --- a/homeassistant/components/vlc/media_player.py +++ b/homeassistant/components/vlc/media_player.py @@ -159,7 +159,7 @@ class VlcDevice(MediaPlayerEntity): def play_media(self, media_type, media_id, **kwargs): """Play media from a URL or file.""" - if not media_type == MEDIA_TYPE_MUSIC: + if media_type != MEDIA_TYPE_MUSIC: _LOGGER.error( "Invalid media type %s. Only %s is supported", media_type, diff --git a/homeassistant/components/zha/device_tracker.py b/homeassistant/components/zha/device_tracker.py index 53191789eba..ffb37e33b0f 100644 --- a/homeassistant/components/zha/device_tracker.py +++ b/homeassistant/components/zha/device_tracker.py @@ -83,7 +83,7 @@ class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity): @callback def async_battery_percentage_remaining_updated(self, attr_id, attr_name, value): """Handle tracking.""" - if not attr_name == "battery_percentage_remaining": + if attr_name != "battery_percentage_remaining": return self.debug("battery_percentage_remaining updated: %s", value) self._connected = True diff --git a/homeassistant/components/zwave_js/sensor.py b/homeassistant/components/zwave_js/sensor.py index ada6f6b5d06..5f116f0790c 100644 --- a/homeassistant/components/zwave_js/sensor.py +++ b/homeassistant/components/zwave_js/sensor.py @@ -197,8 +197,8 @@ class ZWaveListSensor(ZwaveSensorBase): if self.info.primary_value.value is None: return None if ( - not str(self.info.primary_value.value) - in self.info.primary_value.metadata.states + str(self.info.primary_value.value) + not in self.info.primary_value.metadata.states ): return str(self.info.primary_value.value) return str( diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 671009b8846..cfb7223752e 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -1439,7 +1439,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): def is_safe_attribute(self, obj, attr, value): """Test if attribute is safe.""" if isinstance(obj, (AllStates, DomainStates, TemplateState)): - return not attr[0] == "_" + return attr[0] != "_" if isinstance(obj, Namespace): return True diff --git a/homeassistant/util/timeout.py b/homeassistant/util/timeout.py index 64208d775ea..5821f89659e 100644 --- a/homeassistant/util/timeout.py +++ b/homeassistant/util/timeout.py @@ -243,7 +243,7 @@ class _GlobalTaskContext: """Wait until zones are done.""" await self._wait_zone.wait() await asyncio.sleep(self._cool_down) # Allow context switch - if not self.state == _State.TIMEOUT: + if self.state != _State.TIMEOUT: return self._cancel_task() diff --git a/script/hassfest/coverage.py b/script/hassfest/coverage.py index 1a0c684cfab..06e38902060 100644 --- a/script/hassfest/coverage.py +++ b/script/hassfest/coverage.py @@ -106,8 +106,8 @@ def validate(integrations: dict[str, Integration], config: Config): if ( not line.startswith("homeassistant/components/") - or not len(path.parts) == 4 - or not path.parts[-1] == "*" + or len(path.parts) != 4 + or path.parts[-1] != "*" ): continue diff --git a/tests/components/mqtt/test_cover.py b/tests/components/mqtt/test_cover.py index 2a29bf9e15e..508869c7b51 100644 --- a/tests/components/mqtt/test_cover.py +++ b/tests/components/mqtt/test_cover.py @@ -525,9 +525,9 @@ async def test_current_cover_position(hass, mqtt_mock): await hass.async_block_till_done() state_attributes_dict = hass.states.get("cover.test").attributes - assert not (ATTR_CURRENT_POSITION in state_attributes_dict) - assert not (ATTR_CURRENT_TILT_POSITION in state_attributes_dict) - assert not (4 & hass.states.get("cover.test").attributes["supported_features"] == 4) + assert ATTR_CURRENT_POSITION not in state_attributes_dict + assert ATTR_CURRENT_TILT_POSITION not in state_attributes_dict + assert 4 & hass.states.get("cover.test").attributes["supported_features"] != 4 async_fire_mqtt_message(hass, "get-position-topic", "0") current_cover_position = hass.states.get("cover.test").attributes[ @@ -576,9 +576,9 @@ async def test_current_cover_position_inverted(hass, mqtt_mock): await hass.async_block_till_done() state_attributes_dict = hass.states.get("cover.test").attributes - assert not (ATTR_CURRENT_POSITION in state_attributes_dict) - assert not (ATTR_CURRENT_TILT_POSITION in state_attributes_dict) - assert not (4 & hass.states.get("cover.test").attributes["supported_features"] == 4) + assert ATTR_CURRENT_POSITION not in state_attributes_dict + assert ATTR_CURRENT_TILT_POSITION not in state_attributes_dict + assert 4 & hass.states.get("cover.test").attributes["supported_features"] != 4 async_fire_mqtt_message(hass, "get-position-topic", "100") current_percentage_cover_position = hass.states.get("cover.test").attributes[ @@ -659,14 +659,14 @@ async def test_position_update(hass, mqtt_mock): await hass.async_block_till_done() state_attributes_dict = hass.states.get("cover.test").attributes - assert not (ATTR_CURRENT_POSITION in state_attributes_dict) - assert not (ATTR_CURRENT_TILT_POSITION in state_attributes_dict) + assert ATTR_CURRENT_POSITION not in state_attributes_dict + assert ATTR_CURRENT_TILT_POSITION not in state_attributes_dict assert 4 & hass.states.get("cover.test").attributes["supported_features"] == 4 async_fire_mqtt_message(hass, "get-position-topic", "22") state_attributes_dict = hass.states.get("cover.test").attributes assert ATTR_CURRENT_POSITION in state_attributes_dict - assert not (ATTR_CURRENT_TILT_POSITION in state_attributes_dict) + assert ATTR_CURRENT_TILT_POSITION not in state_attributes_dict current_cover_position = hass.states.get("cover.test").attributes[ ATTR_CURRENT_POSITION ] diff --git a/tests/components/pilight/test_init.py b/tests/components/pilight/test_init.py index b69e03058bf..4b8b017f7fd 100644 --- a/tests/components/pilight/test_init.py +++ b/tests/components/pilight/test_init.py @@ -360,7 +360,7 @@ async def test_whitelist_no_match(mock_debug, hass): await hass.async_block_till_done() debug_log_call = mock_debug.call_args_list[-3] - assert not ("Event pilight_received" in debug_log_call) + assert "Event pilight_received" not in debug_log_call async def test_call_rate_delay_throttle_enabled(hass): diff --git a/tests/components/recorder/test_purge.py b/tests/components/recorder/test_purge.py index bbc16cef825..e487e542958 100644 --- a/tests/components/recorder/test_purge.py +++ b/tests/components/recorder/test_purge.py @@ -157,7 +157,7 @@ async def test_purge_method( assert runs[1] == runs_before_purge[5] assert runs[2] == runs_before_purge[6] - assert not ("EVENT_TEST_PURGE" in (event.event_type for event in events.all())) + assert "EVENT_TEST_PURGE" not in (event.event_type for event in events.all()) # run purge method - correct service data, with repack service_data["repack"] = True diff --git a/tests/components/universal/test_media_player.py b/tests/components/universal/test_media_player.py index 8d8bc80234e..3914f580724 100644 --- a/tests/components/universal/test_media_player.py +++ b/tests/components/universal/test_media_player.py @@ -333,7 +333,7 @@ class TestMediaPlayer(unittest.TestCase): config = {"name": "test", "asdf": 5, "platform": "universal"} config = validate_config(config) - assert not ("asdf" in config) + assert "asdf" not in config def test_platform_setup(self): """Test platform setup."""