mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Remove unnecessary instances of dict.keys() (#42518)
This commit is contained in:
parent
6e43d489ca
commit
a967f689c7
@ -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]:
|
def _get_domains(hass: core.HomeAssistant, config: Dict[str, Any]) -> Set[str]:
|
||||||
"""Get domains of components to set up."""
|
"""Get domains of components to set up."""
|
||||||
# Filter out the repeating and common config section [homeassistant]
|
# 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
|
# Add config entry domains
|
||||||
if not hass.config.safe_mode:
|
if not hass.config.safe_mode:
|
||||||
|
@ -784,7 +784,7 @@ class AlexaInputController(AlexaCapability):
|
|||||||
formatted_source = (
|
formatted_source = (
|
||||||
source.lower().replace("-", "").replace("_", "").replace(" ", "")
|
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(
|
input_list.append(
|
||||||
{"name": Inputs.VALID_SOURCE_NAME_MAP[formatted_source]}
|
{"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(" ", "")
|
media_input = media_input.lower().replace(" ", "")
|
||||||
if (
|
if (
|
||||||
formatted_source in Inputs.VALID_SOURCE_NAME_MAP.keys()
|
formatted_source in Inputs.VALID_SOURCE_NAME_MAP
|
||||||
and formatted_source == media_input
|
and formatted_source == media_input
|
||||||
) or (
|
) or (
|
||||||
media_input.endswith("1") and formatted_source == media_input.rstrip("1")
|
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 = []
|
meters = []
|
||||||
for meter in essent.retrieve_meters():
|
for meter in essent.retrieve_meters():
|
||||||
data = essent.retrieve_meter_data(meter)
|
data = essent.retrieve_meter_data(meter)
|
||||||
for tariff in data["values"]["LVR"].keys():
|
for tariff in data["values"]["LVR"]:
|
||||||
meters.append(
|
meters.append(
|
||||||
EssentMeter(
|
EssentMeter(
|
||||||
essent,
|
essent,
|
||||||
|
@ -142,7 +142,7 @@ class FeedManager:
|
|||||||
def _update_and_fire_entry(self, entry):
|
def _update_and_fire_entry(self, entry):
|
||||||
"""Update last_entry_timestamp and fire entry."""
|
"""Update last_entry_timestamp and fire entry."""
|
||||||
# Check if the entry has a published date.
|
# 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
|
# We are lucky, `published_parsed` data available, let's make use of
|
||||||
# it to publish only new available entries since the last run
|
# it to publish only new available entries since the last run
|
||||||
self._has_published_parsed = True
|
self._has_published_parsed = True
|
||||||
@ -166,7 +166,7 @@ class FeedManager:
|
|||||||
self._last_entry_timestamp = datetime.utcfromtimestamp(0).timetuple()
|
self._last_entry_timestamp = datetime.utcfromtimestamp(0).timetuple()
|
||||||
for entry in self._feed.entries:
|
for entry in self._feed.entries:
|
||||||
if self._firstrun or (
|
if self._firstrun or (
|
||||||
"published_parsed" in entry.keys()
|
"published_parsed" in entry
|
||||||
and entry.published_parsed > self._last_entry_timestamp
|
and entry.published_parsed > self._last_entry_timestamp
|
||||||
):
|
):
|
||||||
self._update_and_fire_entry(entry)
|
self._update_and_fire_entry(entry)
|
||||||
|
@ -164,7 +164,7 @@ class FibaroController:
|
|||||||
for change in state.get("changes", []):
|
for change in state.get("changes", []):
|
||||||
try:
|
try:
|
||||||
dev_id = change.pop("id")
|
dev_id = change.pop("id")
|
||||||
if dev_id not in self._device_map.keys():
|
if dev_id not in self._device_map:
|
||||||
continue
|
continue
|
||||||
device = self._device_map[dev_id]
|
device = self._device_map[dev_id]
|
||||||
for property_name, value in change.items():
|
for property_name, value in change.items():
|
||||||
|
@ -98,7 +98,7 @@ class GitterSensor(Entity):
|
|||||||
_LOGGER.error(error)
|
_LOGGER.error(error)
|
||||||
return
|
return
|
||||||
|
|
||||||
if "error" not in data.keys():
|
if "error" not in data:
|
||||||
self._mention = len(data["mention"])
|
self._mention = len(data["mention"])
|
||||||
self._state = len(data["chat"])
|
self._state = len(data["chat"])
|
||||||
else:
|
else:
|
||||||
|
@ -156,7 +156,7 @@ class GoogleCalendarData:
|
|||||||
items = result.get("items", [])
|
items = result.get("items", [])
|
||||||
event_list = []
|
event_list = []
|
||||||
for item in items:
|
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":
|
if item["transparency"] == "opaque":
|
||||||
event_list.append(item)
|
event_list.append(item)
|
||||||
else:
|
else:
|
||||||
@ -178,7 +178,7 @@ class GoogleCalendarData:
|
|||||||
|
|
||||||
new_event = None
|
new_event = None
|
||||||
for item in items:
|
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":
|
if item["transparency"] == "opaque":
|
||||||
new_event = item
|
new_event = item
|
||||||
break
|
break
|
||||||
|
@ -225,7 +225,7 @@ class HistoryStatsSensor(Entity):
|
|||||||
self.hass, start, end, str(self._entity_id)
|
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
|
return
|
||||||
|
|
||||||
# Get the first state
|
# Get the first state
|
||||||
|
@ -258,7 +258,7 @@ def setup(hass, config):
|
|||||||
|
|
||||||
# Init homematic hubs
|
# Init homematic hubs
|
||||||
entity_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))
|
entity_hubs.append(HMHub(hass, homematic, hub_name))
|
||||||
|
|
||||||
def _hm_service_virtualkey(service):
|
def _hm_service_virtualkey(service):
|
||||||
|
@ -160,7 +160,7 @@ async def async_get_triggers(hass, device_id):
|
|||||||
return
|
return
|
||||||
|
|
||||||
triggers = []
|
triggers = []
|
||||||
for trigger, subtype in REMOTES[device.model].keys():
|
for trigger, subtype in REMOTES[device.model]:
|
||||||
triggers.append(
|
triggers.append(
|
||||||
{
|
{
|
||||||
CONF_DEVICE_ID: device_id,
|
CONF_DEVICE_ID: device_id,
|
||||||
|
@ -87,7 +87,7 @@ VALID_PROGRAM_COMMANDS = [
|
|||||||
def valid_isy_commands(value: Any) -> str:
|
def valid_isy_commands(value: Any) -> str:
|
||||||
"""Validate the command is valid."""
|
"""Validate the command is valid."""
|
||||||
value = str(value).upper()
|
value = str(value).upper()
|
||||||
if value in COMMAND_FRIENDLY_NAME.keys():
|
if value in COMMAND_FRIENDLY_NAME:
|
||||||
return value
|
return value
|
||||||
raise vol.Invalid("Invalid ISY Command.")
|
raise vol.Invalid("Invalid ISY Command.")
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ def async_setup_services(hass: HomeAssistantType):
|
|||||||
"""Create and register services for the ISY integration."""
|
"""Create and register services for the ISY integration."""
|
||||||
existing_services = hass.services.async_services().get(DOMAIN)
|
existing_services = hass.services.async_services().get(DOMAIN)
|
||||||
if existing_services and any(
|
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.
|
# Integration-level services have already been added. Return.
|
||||||
return
|
return
|
||||||
@ -388,7 +388,7 @@ def async_unload_services(hass: HomeAssistantType):
|
|||||||
|
|
||||||
existing_services = hass.services.async_services().get(DOMAIN)
|
existing_services = hass.services.async_services().get(DOMAIN)
|
||||||
if not existing_services or not any(
|
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
|
return
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ async def handle_webhook(hass, webhook_id, request):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
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"]):
|
if await verify_webhook(hass, **data["signature"]):
|
||||||
data["webhook_id"] = webhook_id
|
data["webhook_id"] = webhook_id
|
||||||
hass.bus.async_fire(MESSAGE_RECEIVED, data)
|
hass.bus.async_fire(MESSAGE_RECEIVED, data)
|
||||||
|
@ -45,7 +45,7 @@ async def async_setup(hass: HomeAssistant, config: dict):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
config = p_config.copy()
|
config = p_config.copy()
|
||||||
if config[CONF_HOST] not in configs.keys():
|
if config[CONF_HOST] not in configs:
|
||||||
configs[config[CONF_HOST]] = {
|
configs[config[CONF_HOST]] = {
|
||||||
CONF_HOST: config[CONF_HOST],
|
CONF_HOST: config[CONF_HOST],
|
||||||
CONF_NAME: config.get(CONF_NAME, DEFAULT_NAME),
|
CONF_NAME: config.get(CONF_NAME, DEFAULT_NAME),
|
||||||
|
@ -139,7 +139,7 @@ class SCSGate:
|
|||||||
def is_device_registered(self, device_id):
|
def is_device_registered(self, device_id):
|
||||||
"""Check whether a device is already registered or not."""
|
"""Check whether a device is already registered or not."""
|
||||||
with self._devices_to_register_lock:
|
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
|
return False
|
||||||
|
|
||||||
with self._device_being_registered_lock:
|
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
|
"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)
|
hass.services.async_register(DOMAIN, name, async_service_handler)
|
||||||
return True
|
return True
|
||||||
|
@ -222,7 +222,7 @@ def _stream_worker_internal(hass, stream, quit_event):
|
|||||||
def finalize_stream():
|
def finalize_stream():
|
||||||
if not stream.keepalive:
|
if not stream.keepalive:
|
||||||
# End of stream, clear listeners and stop thread
|
# 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)
|
hass.loop.call_soon_threadsafe(stream.outputs[fmt].put, None)
|
||||||
|
|
||||||
if not peek_first_pts():
|
if not peek_first_pts():
|
||||||
|
@ -407,7 +407,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# If we got here, we should include it
|
# If we got here, we should include it
|
||||||
if category not in matches.keys():
|
if category not in matches:
|
||||||
matches[category] = []
|
matches[category] = []
|
||||||
matches[category].append({"score": float(score), "box": boxes})
|
matches[category].append({"score": float(score), "box": boxes})
|
||||||
total_matches += 1
|
total_matches += 1
|
||||||
|
@ -147,7 +147,7 @@ class TtnDataStorage:
|
|||||||
self.data = data[-1]
|
self.data = data[-1]
|
||||||
|
|
||||||
for value in self._values.items():
|
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])
|
_LOGGER.warning("Value not available: %s", value[0])
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -55,7 +55,7 @@ class VerisureAlarm(alarm.AlarmControlPanelEntity):
|
|||||||
giid = hub.config.get(CONF_GIID)
|
giid = hub.config.get(CONF_GIID)
|
||||||
if giid is not None:
|
if giid is not None:
|
||||||
aliass = {i["giid"]: i["alias"] for i in hub.session.installations}
|
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])
|
return "{} alarm".format(aliass[giid])
|
||||||
|
|
||||||
_LOGGER.error("Verisure installation giid not found: %s", 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):
|
if not isinstance(obj, dict):
|
||||||
raise vol.Invalid("expected dictionary")
|
raise vol.Invalid("expected dictionary")
|
||||||
|
|
||||||
for k in obj.keys():
|
for k in obj:
|
||||||
if k in keys:
|
if k in keys:
|
||||||
return obj
|
return obj
|
||||||
raise vol.Invalid("must contain at least one of {}.".format(", ".join(keys)))
|
raise vol.Invalid("must contain at least one of {}.".format(", ".join(keys)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user