diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index ef345de22cf..618a168be61 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -309,7 +309,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 = set(key.split(" ")[0] for key in config.keys() if key != core.DOMAIN) + domains = {key.split(" ")[0] for key in config.keys() if key != core.DOMAIN} # Add config entry domains if not hass.config.safe_mode: diff --git a/homeassistant/components/august/__init__.py b/homeassistant/components/august/__init__.py index 373fcae8d0c..cd2783e6cb8 100644 --- a/homeassistant/components/august/__init__.py +++ b/homeassistant/components/august/__init__.py @@ -214,11 +214,11 @@ class AugustData(AugustSubscriberMixin): await self._api.async_get_doorbells(self._august_gateway.access_token) or [] ) - self._doorbells_by_id = dict((device.device_id, device) for device in doorbells) - self._locks_by_id = dict((device.device_id, device) for device in locks) - self._house_ids = set( + self._doorbells_by_id = {device.device_id: device for device in doorbells} + self._locks_by_id = {device.device_id: device for device in locks} + self._house_ids = { device.house_id for device in itertools.chain(locks, doorbells) - ) + } await self._async_refresh_device_detail_by_ids( [device.device_id for device in itertools.chain(locks, doorbells)] diff --git a/homeassistant/components/bayesian/binary_sensor.py b/homeassistant/components/bayesian/binary_sensor.py index b922c966ff5..78b30557fce 100644 --- a/homeassistant/components/bayesian/binary_sensor.py +++ b/homeassistant/components/bayesian/binary_sensor.py @@ -303,11 +303,11 @@ class BayesianBinarySensor(BinarySensorDevice): return { ATTR_OBSERVATIONS: list(self.current_observations.values()), ATTR_OCCURRED_OBSERVATION_ENTITIES: list( - set( + { obs.get("entity_id") for obs in self.current_observations.values() if obs is not None - ) + } ), ATTR_PROBABILITY: round(self.probability, 2), ATTR_PROBABILITY_THRESHOLD: self._probability_threshold, diff --git a/homeassistant/components/bme680/sensor.py b/homeassistant/components/bme680/sensor.py index 19d6fbd3086..ba5a3267a23 100644 --- a/homeassistant/components/bme680/sensor.py +++ b/homeassistant/components/bme680/sensor.py @@ -61,8 +61,8 @@ SENSOR_TYPES = { SENSOR_AQ: ["Air Quality", UNIT_PERCENTAGE], } DEFAULT_MONITORED = [SENSOR_TEMP, SENSOR_HUMID, SENSOR_PRESS, SENSOR_AQ] -OVERSAMPLING_VALUES = set([0, 1, 2, 4, 8, 16]) -FILTER_VALUES = set([0, 1, 3, 7, 15, 31, 63, 127]) +OVERSAMPLING_VALUES = {0, 1, 2, 4, 8, 16} +FILTER_VALUES = {0, 1, 3, 7, 15, 31, 63, 127} PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { diff --git a/homeassistant/components/cast/discovery.py b/homeassistant/components/cast/discovery.py index 54f165889af..6991c83959d 100644 --- a/homeassistant/components/cast/discovery.py +++ b/homeassistant/components/cast/discovery.py @@ -30,9 +30,9 @@ def discover_chromecast(hass: HomeAssistant, info: ChromecastInfo): if info.uuid is not None: # Remove previous cast infos with same uuid from known chromecasts. - same_uuid = set( + same_uuid = { x for x in hass.data[KNOWN_CHROMECAST_INFO_KEY] if info.uuid == x.uuid - ) + } hass.data[KNOWN_CHROMECAST_INFO_KEY] -= same_uuid hass.data[KNOWN_CHROMECAST_INFO_KEY].add(info) diff --git a/homeassistant/components/emulated_roku/config_flow.py b/homeassistant/components/emulated_roku/config_flow.py index 3e363e060c2..0f8a82fa893 100644 --- a/homeassistant/components/emulated_roku/config_flow.py +++ b/homeassistant/components/emulated_roku/config_flow.py @@ -11,9 +11,9 @@ from .const import CONF_LISTEN_PORT, DEFAULT_NAME, DEFAULT_PORT, DOMAIN @callback def configured_servers(hass): """Return a set of the configured servers.""" - return set( + return { entry.data[CONF_NAME] for entry in hass.config_entries.async_entries(DOMAIN) - ) + } @config_entries.HANDLERS.register(DOMAIN) diff --git a/homeassistant/components/geonetnz_volcano/config_flow.py b/homeassistant/components/geonetnz_volcano/config_flow.py index 7c079c432dd..c19e7d4b303 100644 --- a/homeassistant/components/geonetnz_volcano/config_flow.py +++ b/homeassistant/components/geonetnz_volcano/config_flow.py @@ -24,10 +24,10 @@ _LOGGER = logging.getLogger(__name__) @callback def configured_instances(hass): """Return a set of configured GeoNet NZ Volcano instances.""" - return set( + return { f"{entry.data[CONF_LATITUDE]}, {entry.data[CONF_LONGITUDE]}" for entry in hass.config_entries.async_entries(DOMAIN) - ) + } class GeonetnzVolcanoFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/components/google_assistant/smart_home.py b/homeassistant/components/google_assistant/smart_home.py index 55e121e2fc7..a3667f4c4f4 100644 --- a/homeassistant/components/google_assistant/smart_home.py +++ b/homeassistant/components/google_assistant/smart_home.py @@ -262,7 +262,7 @@ async def async_devices_reachable(hass, data: RequestData, payload): https://developers.google.com/actions/smarthome/create#actiondevicesdisconnect """ - google_ids = set(dev["id"] for dev in (data.devices or [])) + google_ids = {dev["id"] for dev in (data.devices or [])} return { "devices": [ diff --git a/homeassistant/components/gtfs/sensor.py b/homeassistant/components/gtfs/sensor.py index 08550ed80b8..e4e00c7c2ec 100644 --- a/homeassistant/components/gtfs/sensor.py +++ b/homeassistant/components/gtfs/sensor.py @@ -659,9 +659,9 @@ class GTFSDepartureSensor(Entity): @staticmethod def dict_for_table(resource: Any) -> dict: """Return a dictionary for the SQLAlchemy resource given.""" - return dict( - (col, getattr(resource, col)) for col in resource.__table__.columns.keys() - ) + return { + col: getattr(resource, col) for col in resource.__table__.columns.keys() + } def append_keys(self, resource: dict, prefix: Optional[str] = None) -> None: """Properly format key val pairs to append to attributes.""" diff --git a/homeassistant/components/homematicip_cloud/__init__.py b/homeassistant/components/homematicip_cloud/__init__.py index d1982e289a3..df1f5062fce 100644 --- a/homeassistant/components/homematicip_cloud/__init__.py +++ b/homeassistant/components/homematicip_cloud/__init__.py @@ -50,10 +50,10 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: accesspoints = config.get(DOMAIN, []) for conf in accesspoints: - if conf[CONF_ACCESSPOINT] not in set( + if conf[CONF_ACCESSPOINT] not in { entry.data[HMIPC_HAPID] for entry in hass.config_entries.async_entries(DOMAIN) - ): + }: hass.async_add_job( hass.config_entries.flow.async_init( DOMAIN, diff --git a/homeassistant/components/hue/__init__.py b/homeassistant/components/hue/__init__.py index 7510ff22f16..675fe3ae5e1 100644 --- a/homeassistant/components/hue/__init__.py +++ b/homeassistant/components/hue/__init__.py @@ -70,9 +70,9 @@ async def async_setup(hass, config): bridges = conf[CONF_BRIDGES] - configured_hosts = set( + configured_hosts = { entry.data.get("host") for entry in hass.config_entries.async_entries(DOMAIN) - ) + } for bridge_conf in bridges: host = bridge_conf[CONF_HOST] diff --git a/homeassistant/components/iqvia/config_flow.py b/homeassistant/components/iqvia/config_flow.py index abec8eff09a..6a57f0f24d4 100644 --- a/homeassistant/components/iqvia/config_flow.py +++ b/homeassistant/components/iqvia/config_flow.py @@ -16,9 +16,9 @@ from .const import CONF_ZIP_CODE, DOMAIN @callback def configured_instances(hass): """Return a set of configured IQVIA instances.""" - return set( + return { entry.data[CONF_ZIP_CODE] for entry in hass.config_entries.async_entries(DOMAIN) - ) + } @config_entries.HANDLERS.register(DOMAIN) diff --git a/homeassistant/components/luftdaten/config_flow.py b/homeassistant/components/luftdaten/config_flow.py index 1f382b86c0f..1613e8ea555 100644 --- a/homeassistant/components/luftdaten/config_flow.py +++ b/homeassistant/components/luftdaten/config_flow.py @@ -22,10 +22,10 @@ from .const import CONF_SENSOR_ID, DEFAULT_SCAN_INTERVAL, DOMAIN @callback def configured_sensors(hass): """Return a set of configured Luftdaten sensors.""" - return set( + return { entry.data[CONF_SENSOR_ID] for entry in hass.config_entries.async_entries(DOMAIN) - ) + } @callback diff --git a/homeassistant/components/mold_indicator/sensor.py b/homeassistant/components/mold_indicator/sensor.py index 374866a6859..82f1cfaec9b 100644 --- a/homeassistant/components/mold_indicator/sensor.py +++ b/homeassistant/components/mold_indicator/sensor.py @@ -90,13 +90,11 @@ class MoldIndicator(Entity): self._calib_factor = calib_factor self._is_metric = is_metric self._available = False - self._entities = set( - [ - self._indoor_temp_sensor, - self._indoor_humidity_sensor, - self._outdoor_temp_sensor, - ] - ) + self._entities = { + self._indoor_temp_sensor, + self._indoor_humidity_sensor, + self._outdoor_temp_sensor, + } self._dewpoint = None self._indoor_temp = None diff --git a/homeassistant/components/openuv/config_flow.py b/homeassistant/components/openuv/config_flow.py index 402f6514178..9874cadb566 100644 --- a/homeassistant/components/openuv/config_flow.py +++ b/homeassistant/components/openuv/config_flow.py @@ -19,13 +19,13 @@ from .const import DOMAIN @callback def configured_instances(hass): """Return a set of configured OpenUV instances.""" - return set( + return { "{}, {}".format( entry.data.get(CONF_LATITUDE, hass.config.latitude), entry.data.get(CONF_LONGITUDE, hass.config.longitude), ) for entry in hass.config_entries.async_entries(DOMAIN) - ) + } @config_entries.HANDLERS.register(DOMAIN) diff --git a/homeassistant/components/pioneer/media_player.py b/homeassistant/components/pioneer/media_player.py index b834a8e6829..66e57d156ef 100644 --- a/homeassistant/components/pioneer/media_player.py +++ b/homeassistant/components/pioneer/media_player.py @@ -87,7 +87,7 @@ class PioneerDevice(MediaPlayerDevice): self._muted = False self._selected_source = "" self._source_name_to_number = sources - self._source_number_to_name = dict((v, k) for k, v in sources.items()) + self._source_number_to_name = {v: k for k, v in sources.items()} @classmethod def telnet_request(cls, telnet, command, expected_prefix): diff --git a/homeassistant/components/plex/config_flow.py b/homeassistant/components/plex/config_flow.py index 6edbecf055d..a314aba0ecd 100644 --- a/homeassistant/components/plex/config_flow.py +++ b/homeassistant/components/plex/config_flow.py @@ -43,10 +43,10 @@ _LOGGER = logging.getLogger(__package__) @callback def configured_servers(hass): """Return a set of the configured Plex servers.""" - return set( + return { entry.data[CONF_SERVER_IDENTIFIER] for entry in hass.config_entries.async_entries(DOMAIN) - ) + } class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/components/python_script/__init__.py b/homeassistant/components/python_script/__init__.py index 0c5886e177c..6ec94aa8e52 100644 --- a/homeassistant/components/python_script/__init__.py +++ b/homeassistant/components/python_script/__init__.py @@ -32,30 +32,41 @@ FOLDER = "python_scripts" CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema(dict)}, extra=vol.ALLOW_EXTRA) -ALLOWED_HASS = set(["bus", "services", "states"]) -ALLOWED_EVENTBUS = set(["fire"]) -ALLOWED_STATEMACHINE = set( - ["entity_ids", "all", "get", "is_state", "is_state_attr", "remove", "set"] -) -ALLOWED_SERVICEREGISTRY = set(["services", "has_service", "call"]) -ALLOWED_TIME = set( - ["sleep", "strftime", "strptime", "gmtime", "localtime", "ctime", "time", "mktime"] -) -ALLOWED_DATETIME = set(["date", "time", "datetime", "timedelta", "tzinfo"]) -ALLOWED_DT_UTIL = set( - [ - "utcnow", - "now", - "as_utc", - "as_timestamp", - "as_local", - "utc_from_timestamp", - "start_of_local_day", - "parse_datetime", - "parse_date", - "get_age", - ] -) +ALLOWED_HASS = {"bus", "services", "states"} +ALLOWED_EVENTBUS = {"fire"} +ALLOWED_STATEMACHINE = { + "entity_ids", + "all", + "get", + "is_state", + "is_state_attr", + "remove", + "set", +} +ALLOWED_SERVICEREGISTRY = {"services", "has_service", "call"} +ALLOWED_TIME = { + "sleep", + "strftime", + "strptime", + "gmtime", + "localtime", + "ctime", + "time", + "mktime", +} +ALLOWED_DATETIME = {"date", "time", "datetime", "timedelta", "tzinfo"} +ALLOWED_DT_UTIL = { + "utcnow", + "now", + "as_utc", + "as_timestamp", + "as_local", + "utc_from_timestamp", + "start_of_local_day", + "parse_datetime", + "parse_date", + "get_age", +} class ScriptError(HomeAssistantError): diff --git a/homeassistant/components/smhi/config_flow.py b/homeassistant/components/smhi/config_flow.py index 2c04896497a..8853680af33 100644 --- a/homeassistant/components/smhi/config_flow.py +++ b/homeassistant/components/smhi/config_flow.py @@ -15,10 +15,10 @@ from .const import DOMAIN, HOME_LOCATION_NAME @callback def smhi_locations(hass: HomeAssistant): """Return configurations of SMHI component.""" - return set( + return { (slugify(entry.data[CONF_NAME])) for entry in hass.config_entries.async_entries(DOMAIN) - ) + } @config_entries.HANDLERS.register(DOMAIN) diff --git a/homeassistant/components/solaredge/config_flow.py b/homeassistant/components/solaredge/config_flow.py index 62bf99ab383..8a7f2af3a99 100644 --- a/homeassistant/components/solaredge/config_flow.py +++ b/homeassistant/components/solaredge/config_flow.py @@ -14,10 +14,10 @@ from .const import CONF_SITE_ID, DEFAULT_NAME, DOMAIN @callback def solaredge_entries(hass: HomeAssistant): """Return the site_ids for the domain.""" - return set( + return { (entry.data[CONF_SITE_ID]) for entry in hass.config_entries.async_entries(DOMAIN) - ) + } class SolarEdgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/components/solarlog/config_flow.py b/homeassistant/components/solarlog/config_flow.py index 111155b27b6..39a752855aa 100644 --- a/homeassistant/components/solarlog/config_flow.py +++ b/homeassistant/components/solarlog/config_flow.py @@ -19,9 +19,9 @@ _LOGGER = logging.getLogger(__name__) @callback def solarlog_entries(hass: HomeAssistant): """Return the hosts already configured.""" - return set( + return { entry.data[CONF_HOST] for entry in hass.config_entries.async_entries(DOMAIN) - ) + } class SolarLogConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index d76af1dc704..33ca6265552 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -1109,7 +1109,7 @@ class SonosEntity(MediaPlayerDevice): entity.restore() # Find all affected players - entities = set(e for e in entities if e._soco_snapshot) + entities = {e for e in entities if e._soco_snapshot} if with_group: for entity in [e for e in entities if e._snapshot_group]: entities.update(entity._snapshot_group) diff --git a/homeassistant/components/tesla/config_flow.py b/homeassistant/components/tesla/config_flow.py index b8407653d1b..f9a218d2f5f 100644 --- a/homeassistant/components/tesla/config_flow.py +++ b/homeassistant/components/tesla/config_flow.py @@ -33,7 +33,7 @@ DATA_SCHEMA = vol.Schema( @callback def configured_instances(hass): """Return a set of configured Tesla instances.""" - return set(entry.title for entry in hass.config_entries.async_entries(DOMAIN)) + return {entry.title for entry in hass.config_entries.async_entries(DOMAIN)} class TeslaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/components/toon/config_flow.py b/homeassistant/components/toon/config_flow.py index ce4f347eaf2..c8b4b537853 100644 --- a/homeassistant/components/toon/config_flow.py +++ b/homeassistant/components/toon/config_flow.py @@ -31,9 +31,9 @@ _LOGGER = logging.getLogger(__name__) @callback def configured_displays(hass): """Return a set of configured Toon displays.""" - return set( + return { entry.data[CONF_DISPLAY] for entry in hass.config_entries.async_entries(DOMAIN) - ) + } @config_entries.HANDLERS.register(DOMAIN) diff --git a/homeassistant/components/velbus/config_flow.py b/homeassistant/components/velbus/config_flow.py index 1d081b711a8..e85422d740a 100644 --- a/homeassistant/components/velbus/config_flow.py +++ b/homeassistant/components/velbus/config_flow.py @@ -13,9 +13,9 @@ from .const import DOMAIN @callback def velbus_entries(hass: HomeAssistant): """Return connections for Velbus domain.""" - return set( + return { (entry.data[CONF_PORT]) for entry in hass.config_entries.async_entries(DOMAIN) - ) + } class VelbusConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 945bd3865c3..905baff895f 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -870,11 +870,11 @@ class ConfigFlow(data_entry_flow.FlowHandler): def _async_current_ids(self, include_ignore: bool = True) -> Set[Optional[str]]: """Return current unique IDs.""" assert self.hass is not None - return set( + return { entry.unique_id for entry in self.hass.config_entries.async_entries(self.handler) if include_ignore or entry.source != SOURCE_IGNORE - ) + } @callback def _async_in_progress(self) -> List[Dict]: diff --git a/homeassistant/helpers/check_config.py b/homeassistant/helpers/check_config.py index 0beeb4da4e8..d876748e8d1 100644 --- a/homeassistant/helpers/check_config.py +++ b/homeassistant/helpers/check_config.py @@ -107,7 +107,7 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig core_config.pop(CONF_PACKAGES, None) # Filter out repeating config sections - components = set(key.split(" ")[0] for key in config.keys()) + components = {key.split(" ")[0] for key in config.keys()} # Process and validate config for domain in components: diff --git a/homeassistant/helpers/restore_state.py b/homeassistant/helpers/restore_state.py index d57d3ad9920..57da6960078 100644 --- a/homeassistant/helpers/restore_state.py +++ b/homeassistant/helpers/restore_state.py @@ -123,11 +123,11 @@ class RestoreStateData: now = dt_util.utcnow() all_states = self.hass.states.async_all() # Entities currently backed by an entity object - current_entity_ids = set( + current_entity_ids = { state.entity_id for state in all_states if not state.attributes.get(entity_registry.ATTR_RESTORED) - ) + } # Start with the currently registered states stored_states = [