From a967f689c7efcdee550d1dd9e6894125dd0f70a8 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Wed, 28 Oct 2020 20:43:48 +0100 Subject: [PATCH] Remove unnecessary instances of dict.keys() (#42518) --- homeassistant/bootstrap.py | 2 +- homeassistant/components/alexa/capabilities.py | 2 +- homeassistant/components/alexa/handlers.py | 2 +- homeassistant/components/essent/sensor.py | 2 +- homeassistant/components/feedreader/__init__.py | 4 ++-- homeassistant/components/fibaro/__init__.py | 2 +- homeassistant/components/gitter/sensor.py | 2 +- homeassistant/components/google/calendar.py | 4 ++-- homeassistant/components/history_stats/sensor.py | 2 +- homeassistant/components/homematic/__init__.py | 2 +- homeassistant/components/hue/device_trigger.py | 2 +- homeassistant/components/isy994/services.py | 6 +++--- homeassistant/components/mailgun/__init__.py | 2 +- homeassistant/components/onvif/__init__.py | 2 +- homeassistant/components/scsgate/__init__.py | 2 +- homeassistant/components/shell_command/__init__.py | 2 +- homeassistant/components/stream/worker.py | 2 +- homeassistant/components/tensorflow/image_processing.py | 2 +- homeassistant/components/thethingsnetwork/sensor.py | 2 +- homeassistant/components/verisure/alarm_control_panel.py | 2 +- homeassistant/helpers/config_validation.py | 2 +- 21 files changed, 25 insertions(+), 25 deletions(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 1a8c1d554e3..2778747f15d 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -372,7 +372,7 @@ async def async_mount_local_lib_path(config_dir: str) -> str: def _get_domains(hass: core.HomeAssistant, config: Dict[str, Any]) -> Set[str]: """Get domains of components to set up.""" # Filter out the repeating and common config section [homeassistant] - domains = {key.split(" ")[0] for key in config.keys() if key != core.DOMAIN} + domains = {key.split(" ")[0] for key in config if key != core.DOMAIN} # Add config entry domains if not hass.config.safe_mode: diff --git a/homeassistant/components/alexa/capabilities.py b/homeassistant/components/alexa/capabilities.py index 63d8bb751bc..1163d0de101 100644 --- a/homeassistant/components/alexa/capabilities.py +++ b/homeassistant/components/alexa/capabilities.py @@ -784,7 +784,7 @@ class AlexaInputController(AlexaCapability): formatted_source = ( source.lower().replace("-", "").replace("_", "").replace(" ", "") ) - if formatted_source in Inputs.VALID_SOURCE_NAME_MAP.keys(): + if formatted_source in Inputs.VALID_SOURCE_NAME_MAP: input_list.append( {"name": Inputs.VALID_SOURCE_NAME_MAP[formatted_source]} ) diff --git a/homeassistant/components/alexa/handlers.py b/homeassistant/components/alexa/handlers.py index 783c7a36949..65c48ba0206 100644 --- a/homeassistant/components/alexa/handlers.py +++ b/homeassistant/components/alexa/handlers.py @@ -488,7 +488,7 @@ async def async_api_select_input(hass, config, directive, context): ) media_input = media_input.lower().replace(" ", "") if ( - formatted_source in Inputs.VALID_SOURCE_NAME_MAP.keys() + formatted_source in Inputs.VALID_SOURCE_NAME_MAP and formatted_source == media_input ) or ( media_input.endswith("1") and formatted_source == media_input.rstrip("1") diff --git a/homeassistant/components/essent/sensor.py b/homeassistant/components/essent/sensor.py index e3ce1ccaafa..3ac7af315b7 100644 --- a/homeassistant/components/essent/sensor.py +++ b/homeassistant/components/essent/sensor.py @@ -27,7 +27,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): meters = [] for meter in essent.retrieve_meters(): data = essent.retrieve_meter_data(meter) - for tariff in data["values"]["LVR"].keys(): + for tariff in data["values"]["LVR"]: meters.append( EssentMeter( essent, diff --git a/homeassistant/components/feedreader/__init__.py b/homeassistant/components/feedreader/__init__.py index 548654c11c0..b4d8c1ff75e 100644 --- a/homeassistant/components/feedreader/__init__.py +++ b/homeassistant/components/feedreader/__init__.py @@ -142,7 +142,7 @@ class FeedManager: def _update_and_fire_entry(self, entry): """Update last_entry_timestamp and fire entry.""" # Check if the entry has a published date. - if "published_parsed" in entry.keys() and entry.published_parsed: + if "published_parsed" in entry and entry.published_parsed: # We are lucky, `published_parsed` data available, let's make use of # it to publish only new available entries since the last run self._has_published_parsed = True @@ -166,7 +166,7 @@ class FeedManager: self._last_entry_timestamp = datetime.utcfromtimestamp(0).timetuple() for entry in self._feed.entries: if self._firstrun or ( - "published_parsed" in entry.keys() + "published_parsed" in entry and entry.published_parsed > self._last_entry_timestamp ): self._update_and_fire_entry(entry) diff --git a/homeassistant/components/fibaro/__init__.py b/homeassistant/components/fibaro/__init__.py index 6b56b146a9c..51e31cf27ad 100644 --- a/homeassistant/components/fibaro/__init__.py +++ b/homeassistant/components/fibaro/__init__.py @@ -164,7 +164,7 @@ class FibaroController: for change in state.get("changes", []): try: dev_id = change.pop("id") - if dev_id not in self._device_map.keys(): + if dev_id not in self._device_map: continue device = self._device_map[dev_id] for property_name, value in change.items(): diff --git a/homeassistant/components/gitter/sensor.py b/homeassistant/components/gitter/sensor.py index ee71599d9fc..aff6dc17923 100644 --- a/homeassistant/components/gitter/sensor.py +++ b/homeassistant/components/gitter/sensor.py @@ -98,7 +98,7 @@ class GitterSensor(Entity): _LOGGER.error(error) return - if "error" not in data.keys(): + if "error" not in data: self._mention = len(data["mention"]) self._state = len(data["chat"]) else: diff --git a/homeassistant/components/google/calendar.py b/homeassistant/components/google/calendar.py index 8a6eb644621..6448e035171 100644 --- a/homeassistant/components/google/calendar.py +++ b/homeassistant/components/google/calendar.py @@ -156,7 +156,7 @@ class GoogleCalendarData: items = result.get("items", []) event_list = [] for item in items: - if not self.ignore_availability and "transparency" in item.keys(): + if not self.ignore_availability and "transparency" in item: if item["transparency"] == "opaque": event_list.append(item) else: @@ -178,7 +178,7 @@ class GoogleCalendarData: new_event = None for item in items: - if not self.ignore_availability and "transparency" in item.keys(): + if not self.ignore_availability and "transparency" in item: if item["transparency"] == "opaque": new_event = item break diff --git a/homeassistant/components/history_stats/sensor.py b/homeassistant/components/history_stats/sensor.py index 9f59f67eb95..8f4a89e3e37 100644 --- a/homeassistant/components/history_stats/sensor.py +++ b/homeassistant/components/history_stats/sensor.py @@ -225,7 +225,7 @@ class HistoryStatsSensor(Entity): self.hass, start, end, str(self._entity_id) ) - if self._entity_id not in history_list.keys(): + if self._entity_id not in history_list: return # Get the first state diff --git a/homeassistant/components/homematic/__init__.py b/homeassistant/components/homematic/__init__.py index 2dd8349dcfc..1f727bab4e1 100644 --- a/homeassistant/components/homematic/__init__.py +++ b/homeassistant/components/homematic/__init__.py @@ -258,7 +258,7 @@ def setup(hass, config): # Init homematic hubs entity_hubs = [] - for hub_name in conf[CONF_HOSTS].keys(): + for hub_name in conf[CONF_HOSTS]: entity_hubs.append(HMHub(hass, homematic, hub_name)) def _hm_service_virtualkey(service): diff --git a/homeassistant/components/hue/device_trigger.py b/homeassistant/components/hue/device_trigger.py index c3dc18cd5df..e65b362f9e7 100644 --- a/homeassistant/components/hue/device_trigger.py +++ b/homeassistant/components/hue/device_trigger.py @@ -160,7 +160,7 @@ async def async_get_triggers(hass, device_id): return triggers = [] - for trigger, subtype in REMOTES[device.model].keys(): + for trigger, subtype in REMOTES[device.model]: triggers.append( { CONF_DEVICE_ID: device_id, diff --git a/homeassistant/components/isy994/services.py b/homeassistant/components/isy994/services.py index ee12cedbca4..3e9e0ae1d29 100644 --- a/homeassistant/components/isy994/services.py +++ b/homeassistant/components/isy994/services.py @@ -87,7 +87,7 @@ VALID_PROGRAM_COMMANDS = [ def valid_isy_commands(value: Any) -> str: """Validate the command is valid.""" value = str(value).upper() - if value in COMMAND_FRIENDLY_NAME.keys(): + if value in COMMAND_FRIENDLY_NAME: return value raise vol.Invalid("Invalid ISY Command.") @@ -162,7 +162,7 @@ def async_setup_services(hass: HomeAssistantType): """Create and register services for the ISY integration.""" existing_services = hass.services.async_services().get(DOMAIN) if existing_services and any( - service in INTEGRATION_SERVICES for service in existing_services.keys() + service in INTEGRATION_SERVICES for service in existing_services ): # Integration-level services have already been added. Return. return @@ -388,7 +388,7 @@ def async_unload_services(hass: HomeAssistantType): existing_services = hass.services.async_services().get(DOMAIN) if not existing_services or not any( - service in INTEGRATION_SERVICES for service in existing_services.keys() + service in INTEGRATION_SERVICES for service in existing_services ): return diff --git a/homeassistant/components/mailgun/__init__.py b/homeassistant/components/mailgun/__init__.py index 42b51c23c74..220b6a1abc1 100644 --- a/homeassistant/components/mailgun/__init__.py +++ b/homeassistant/components/mailgun/__init__.py @@ -51,7 +51,7 @@ async def handle_webhook(hass, webhook_id, request): except ValueError: return None - if isinstance(data, dict) and "signature" in data.keys(): + if isinstance(data, dict) and "signature" in data: if await verify_webhook(hass, **data["signature"]): data["webhook_id"] = webhook_id hass.bus.async_fire(MESSAGE_RECEIVED, data) diff --git a/homeassistant/components/onvif/__init__.py b/homeassistant/components/onvif/__init__.py index 0a30173c7d7..c4fbdc3f40f 100644 --- a/homeassistant/components/onvif/__init__.py +++ b/homeassistant/components/onvif/__init__.py @@ -45,7 +45,7 @@ async def async_setup(hass: HomeAssistant, config: dict): continue config = p_config.copy() - if config[CONF_HOST] not in configs.keys(): + if config[CONF_HOST] not in configs: configs[config[CONF_HOST]] = { CONF_HOST: config[CONF_HOST], CONF_NAME: config.get(CONF_NAME, DEFAULT_NAME), diff --git a/homeassistant/components/scsgate/__init__.py b/homeassistant/components/scsgate/__init__.py index 71a439fe6f9..f64106049de 100644 --- a/homeassistant/components/scsgate/__init__.py +++ b/homeassistant/components/scsgate/__init__.py @@ -139,7 +139,7 @@ class SCSGate: def is_device_registered(self, device_id): """Check whether a device is already registered or not.""" with self._devices_to_register_lock: - if device_id in self._devices_to_register.keys(): + if device_id in self._devices_to_register: return False with self._device_being_registered_lock: diff --git a/homeassistant/components/shell_command/__init__.py b/homeassistant/components/shell_command/__init__.py index 0d221cb6b0b..1173d0477ab 100644 --- a/homeassistant/components/shell_command/__init__.py +++ b/homeassistant/components/shell_command/__init__.py @@ -114,6 +114,6 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: "Error running command: `%s`, return code: %s", cmd, process.returncode ) - for name in conf.keys(): + for name in conf: hass.services.async_register(DOMAIN, name, async_service_handler) return True diff --git a/homeassistant/components/stream/worker.py b/homeassistant/components/stream/worker.py index 4f972774fcc..40f9ef873ea 100644 --- a/homeassistant/components/stream/worker.py +++ b/homeassistant/components/stream/worker.py @@ -222,7 +222,7 @@ def _stream_worker_internal(hass, stream, quit_event): def finalize_stream(): if not stream.keepalive: # End of stream, clear listeners and stop thread - for fmt in stream.outputs.keys(): + for fmt in stream.outputs: hass.loop.call_soon_threadsafe(stream.outputs[fmt].put, None) if not peek_first_pts(): diff --git a/homeassistant/components/tensorflow/image_processing.py b/homeassistant/components/tensorflow/image_processing.py index 0e73d9e871b..e387ae97afe 100644 --- a/homeassistant/components/tensorflow/image_processing.py +++ b/homeassistant/components/tensorflow/image_processing.py @@ -407,7 +407,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity): continue # If we got here, we should include it - if category not in matches.keys(): + if category not in matches: matches[category] = [] matches[category].append({"score": float(score), "box": boxes}) total_matches += 1 diff --git a/homeassistant/components/thethingsnetwork/sensor.py b/homeassistant/components/thethingsnetwork/sensor.py index 3555816213a..eab843069f4 100644 --- a/homeassistant/components/thethingsnetwork/sensor.py +++ b/homeassistant/components/thethingsnetwork/sensor.py @@ -147,7 +147,7 @@ class TtnDataStorage: self.data = data[-1] for value in self._values.items(): - if value[0] not in self.data.keys(): + if value[0] not in self.data: _LOGGER.warning("Value not available: %s", value[0]) return response diff --git a/homeassistant/components/verisure/alarm_control_panel.py b/homeassistant/components/verisure/alarm_control_panel.py index 1ef3eb442cd..239396b2d0c 100644 --- a/homeassistant/components/verisure/alarm_control_panel.py +++ b/homeassistant/components/verisure/alarm_control_panel.py @@ -55,7 +55,7 @@ class VerisureAlarm(alarm.AlarmControlPanelEntity): giid = hub.config.get(CONF_GIID) if giid is not None: aliass = {i["giid"]: i["alias"] for i in hub.session.installations} - if giid in aliass.keys(): + if giid in aliass: return "{} alarm".format(aliass[giid]) _LOGGER.error("Verisure installation giid not found: %s", giid) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 190cee5e050..add101de5b0 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -123,7 +123,7 @@ def has_at_least_one_key(*keys: str) -> Callable: if not isinstance(obj, dict): raise vol.Invalid("expected dictionary") - for k in obj.keys(): + for k in obj: if k in keys: return obj raise vol.Invalid("must contain at least one of {}.".format(", ".join(keys)))