Remove unnecessary instances of dict.keys() (#42518)
This commit is contained in:
parent
6e43d489ca
commit
a967f689c7
21 changed files with 25 additions and 25 deletions
|
@ -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:
|
||||
|
|
|
@ -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]}
|
||||
)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue