From fbad453c89d4a9a1332cf410addc4ec0c05f3f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hjelseth=20H=C3=B8yer?= Date: Thu, 15 Jul 2021 06:44:57 +0200 Subject: [PATCH] Pylint 2.9.3 (#52972) Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> --- homeassistant/components/asuswrt/router.py | 4 ++-- homeassistant/components/august/activity.py | 6 +++--- .../components/august/binary_sensor.py | 4 ++-- .../components/bluesound/media_player.py | 4 ++-- homeassistant/components/decora/light.py | 2 +- homeassistant/components/dynalite/__init__.py | 4 ++-- .../components/eight_sleep/__init__.py | 3 +-- homeassistant/components/emby/media_player.py | 6 ++---- .../components/enphase_envoy/sensor.py | 15 +++++++------- .../components/environment_canada/weather.py | 2 +- .../components/esphome/binary_sensor.py | 4 ---- homeassistant/components/esphome/camera.py | 4 ---- homeassistant/components/esphome/climate.py | 3 +-- homeassistant/components/esphome/cover.py | 3 +-- homeassistant/components/esphome/fan.py | 3 +-- homeassistant/components/esphome/light.py | 3 +-- homeassistant/components/esphome/number.py | 3 +-- homeassistant/components/esphome/sensor.py | 3 +-- homeassistant/components/esphome/switch.py | 3 +-- homeassistant/components/flume/__init__.py | 2 +- homeassistant/components/freebox/sensor.py | 14 ++++++------- homeassistant/components/fritz/switch.py | 8 ++++---- homeassistant/components/glances/sensor.py | 12 +++++------ homeassistant/components/google/__init__.py | 8 ++++---- .../components/google_assistant/smart_home.py | 4 ++-- .../components/google_pubsub/__init__.py | 4 +++- .../components/here_travel_time/sensor.py | 2 +- .../components/homekit/type_cameras.py | 4 ++-- homeassistant/components/hue/sensor_base.py | 4 ++-- homeassistant/components/ios/notify.py | 2 +- .../components/itunes/media_player.py | 2 +- homeassistant/components/knx/climate.py | 2 +- homeassistant/components/kulersky/light.py | 1 - .../components/lg_netcast/media_player.py | 3 ++- .../components/life360/device_tracker.py | 2 +- .../components/luftdaten/config_flow.py | 2 +- homeassistant/components/mobile_app/notify.py | 2 +- homeassistant/components/modern_forms/fan.py | 2 +- .../components/modern_forms/light.py | 2 +- homeassistant/components/mysensors/light.py | 2 ++ homeassistant/components/netatmo/select.py | 8 +++----- homeassistant/components/ombi/sensor.py | 6 +++--- .../components/openhardwaremonitor/sensor.py | 3 +-- homeassistant/components/ozw/entity.py | 4 ++-- .../components/ping/binary_sensor.py | 10 +++++++--- .../components/proximity/__init__.py | 6 +++--- .../components/ring/binary_sensor.py | 4 ++-- homeassistant/components/ring/sensor.py | 10 +++------- homeassistant/components/rpi_camera/camera.py | 10 +++++++--- homeassistant/components/sense/sensor.py | 3 +-- homeassistant/components/sentry/__init__.py | 1 - homeassistant/components/slack/notify.py | 3 +-- homeassistant/components/smappee/sensor.py | 16 +++++++-------- homeassistant/components/snmp/switch.py | 2 +- .../components/switcher_kis/sensor.py | 4 ++-- .../components/synology_dsm/binary_sensor.py | 16 ++++++--------- .../components/synology_dsm/sensor.py | 20 ++++++++----------- .../components/synology_dsm/switch.py | 4 ++-- homeassistant/components/tasmota/discovery.py | 2 +- homeassistant/components/tellstick/sensor.py | 3 +-- homeassistant/components/torque/sensor.py | 4 ++-- homeassistant/components/tuya/__init__.py | 2 +- homeassistant/components/vallox/__init__.py | 4 ++-- homeassistant/components/webostv/__init__.py | 4 ++-- homeassistant/components/withings/const.py | 2 +- .../components/workday/binary_sensor.py | 2 +- homeassistant/components/xiaomi_miio/fan.py | 4 ++-- homeassistant/components/xiaomi_miio/light.py | 6 ++---- .../components/xiaomi_miio/switch.py | 4 ++-- homeassistant/components/xmpp/notify.py | 4 +++- .../components/zha/core/channels/closures.py | 2 +- .../components/zha/core/channels/general.py | 2 +- .../zha/core/channels/homeautomation.py | 2 +- .../components/zha/core/channels/hvac.py | 2 +- .../components/zha/core/channels/lighting.py | 2 +- .../components/zha/core/channels/lightlink.py | 2 +- .../zha/core/channels/measurement.py | 2 +- .../components/zha/core/channels/protocol.py | 2 +- .../components/zha/core/channels/security.py | 2 +- .../zha/core/channels/smartenergy.py | 2 +- .../components/zha/core/registries.py | 2 +- homeassistant/components/zha/core/typing.py | 2 +- homeassistant/components/zha/device_action.py | 4 ++-- homeassistant/components/zha/fan.py | 2 +- homeassistant/components/zwave/__init__.py | 4 ++-- homeassistant/config.py | 2 +- homeassistant/core.py | 8 ++++---- homeassistant/helpers/event.py | 6 +++--- homeassistant/loader.py | 2 +- homeassistant/util/__init__.py | 3 --- homeassistant/util/dt.py | 4 ++-- requirements_test.txt | 2 +- 92 files changed, 182 insertions(+), 213 deletions(-) diff --git a/homeassistant/components/asuswrt/router.py b/homeassistant/components/asuswrt/router.py index 3c911d7712e..9d1bcb35c9e 100644 --- a/homeassistant/components/asuswrt/router.py +++ b/homeassistant/components/asuswrt/router.py @@ -299,9 +299,9 @@ class AsusWrtRouter: ) track_unknown = self._options.get(CONF_TRACK_UNKNOWN, DEFAULT_TRACK_UNKNOWN) - for device_mac in self._devices: + for device_mac, device in self._devices.items(): dev_info = wrt_devices.get(device_mac) - self._devices[device_mac].update(dev_info, consider_home) + device.update(dev_info, consider_home) for device_mac, dev_info in wrt_devices.items(): if device_mac in self._devices: diff --git a/homeassistant/components/august/activity.py b/homeassistant/components/august/activity.py index 402a2ccd610..77630b92511 100644 --- a/homeassistant/components/august/activity.py +++ b/homeassistant/components/august/activity.py @@ -61,9 +61,9 @@ class ActivityStream(AugustSubscriberMixin): """Cleanup any debounces.""" for debouncer in self._update_debounce.values(): debouncer.async_cancel() - for house_id in self._schedule_updates: - if self._schedule_updates[house_id] is not None: - self._schedule_updates[house_id]() + for house_id, updater in self._schedule_updates.items(): + if updater is not None: + updater() self._schedule_updates[house_id] = None def get_latest_device_activity(self, device_id, activity_types): diff --git a/homeassistant/components/august/binary_sensor.py b/homeassistant/components/august/binary_sensor.py index 97faf444f3b..27a115a0823 100644 --- a/homeassistant/components/august/binary_sensor.py +++ b/homeassistant/components/august/binary_sensor.py @@ -112,10 +112,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities): entities.append(AugustDoorBinarySensor(data, "door_open", door)) for doorbell in data.doorbells: - for sensor_type in SENSOR_TYPES_DOORBELL: + for sensor_type, sensor in SENSOR_TYPES_DOORBELL.items(): _LOGGER.debug( "Adding doorbell sensor class %s for %s", - SENSOR_TYPES_DOORBELL[sensor_type][SENSOR_DEVICE_CLASS], + sensor[SENSOR_DEVICE_CLASS], doorbell.device_name, ) entities.append(AugustDoorbellBinarySensor(data, sensor_type, doorbell)) diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index dff45ca68bd..86d0be72bdc 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -193,8 +193,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= for player in target_players: await getattr(player, method["method"])(**params) - for service in SERVICE_TO_METHOD: - schema = SERVICE_TO_METHOD[service]["schema"] + for service, method in SERVICE_TO_METHOD.items(): + schema = method["schema"] hass.services.async_register( DOMAIN, service, async_service_handler, schema=schema ) diff --git a/homeassistant/components/decora/light.py b/homeassistant/components/decora/light.py index 45c42c4bb1c..2564ff0cd9e 100644 --- a/homeassistant/components/decora/light.py +++ b/homeassistant/components/decora/light.py @@ -8,6 +8,7 @@ from bluepy.btle import BTLEException # pylint: disable=import-error import decora # pylint: disable=import-error import voluptuous as vol +from homeassistant import util from homeassistant.components.light import ( ATTR_BRIGHTNESS, PLATFORM_SCHEMA, @@ -16,7 +17,6 @@ from homeassistant.components.light import ( ) from homeassistant.const import CONF_API_KEY, CONF_DEVICES, CONF_NAME import homeassistant.helpers.config_validation as cv -import homeassistant.util as util _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/dynalite/__init__.py b/homeassistant/components/dynalite/__init__.py index 1ee609961cc..703ac1373ba 100644 --- a/homeassistant/components/dynalite/__init__.py +++ b/homeassistant/components/dynalite/__init__.py @@ -108,8 +108,8 @@ TEMPLATE_SCHEMA = vol.Schema({str: TEMPLATE_DATA_SCHEMA}) def validate_area(config: dict[str, Any]) -> dict[str, Any]: """Validate that template parameters are only used if area is using the relevant template.""" conf_set = set() - for template in DEFAULT_TEMPLATES: - for conf in DEFAULT_TEMPLATES[template]: + for configs in DEFAULT_TEMPLATES.values(): + for conf in configs: conf_set.add(conf) if config.get(CONF_TEMPLATE): for conf in DEFAULT_TEMPLATES[config[CONF_TEMPLATE]]: diff --git a/homeassistant/components/eight_sleep/__init__.py b/homeassistant/components/eight_sleep/__init__.py index 4e16cd1087f..f839b3fcc74 100644 --- a/homeassistant/components/eight_sleep/__init__.py +++ b/homeassistant/components/eight_sleep/__init__.py @@ -148,8 +148,7 @@ async def async_setup(hass, config): sensors = [] binary_sensors = [] if eight.users: - for user in eight.users: - obj = eight.users[user] + for obj in eight.users.values(): for sensor in SENSORS: sensors.append(f"{obj.side}_{sensor}") binary_sensors.append(f"{obj.side}_presence") diff --git a/homeassistant/components/emby/media_player.py b/homeassistant/components/emby/media_player.py index 5656a1f1486..c562cf400b6 100644 --- a/homeassistant/components/emby/media_player.py +++ b/homeassistant/components/emby/media_player.py @@ -86,7 +86,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= """Handle devices which are added to Emby.""" new_devices = [] active_devices = [] - for dev_id in emby.devices: + for dev_id, dev in emby.devices.items(): active_devices.append(dev_id) if ( dev_id not in active_emby_devices @@ -96,9 +96,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= active_emby_devices[dev_id] = new new_devices.append(new) - elif ( - dev_id in inactive_emby_devices and emby.devices[dev_id].state != "Off" - ): + elif dev_id in inactive_emby_devices and dev.state != "Off": add = inactive_emby_devices.pop(dev_id) active_emby_devices[dev_id] = add _LOGGER.debug("Showing %s, item: %s", dev_id, add) diff --git a/homeassistant/components/enphase_envoy/sensor.py b/homeassistant/components/enphase_envoy/sensor.py index 5ccb540efd0..3fab9e320dc 100644 --- a/homeassistant/components/enphase_envoy/sensor.py +++ b/homeassistant/components/enphase_envoy/sensor.py @@ -56,14 +56,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities): name = data[NAME] entities = [] - for condition in SENSORS: - entity_name = "" + for condition, sensor in SENSORS.items(): if ( condition == "inverters" and coordinator.data.get("inverters_production") is not None ): for inverter in coordinator.data["inverters_production"]: - entity_name = f"{name} {SENSORS[condition][0]} {inverter}" + entity_name = f"{name} {sensor[0]} {inverter}" split_name = entity_name.split(" ") serial_number = split_name[-1] entities.append( @@ -73,8 +72,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): name, config_entry.unique_id, serial_number, - SENSORS[condition][1], - SENSORS[condition][2], + sensor[1], + sensor[2], coordinator, ) ) @@ -83,7 +82,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if isinstance(data, str) and "not available" in data: continue - entity_name = f"{name} {SENSORS[condition][0]}" + entity_name = f"{name} {sensor[0]}" entities.append( Envoy( condition, @@ -91,8 +90,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): name, config_entry.unique_id, None, - SENSORS[condition][1], - SENSORS[condition][2], + sensor[1], + sensor[2], coordinator, ) ) diff --git a/homeassistant/components/environment_canada/weather.py b/homeassistant/components/environment_canada/weather.py index a4a8a02cee9..cf24146da14 100644 --- a/homeassistant/components/environment_canada/weather.py +++ b/homeassistant/components/environment_canada/weather.py @@ -28,7 +28,7 @@ from homeassistant.components.weather import ( ) from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS import homeassistant.helpers.config_validation as cv -import homeassistant.util.dt as dt +from homeassistant.util import dt CONF_FORECAST = "forecast" CONF_ATTRIBUTION = "Data provided by Environment Canada" diff --git a/homeassistant/components/esphome/binary_sensor.py b/homeassistant/components/esphome/binary_sensor.py index 44ed1806ed6..338f3787090 100644 --- a/homeassistant/components/esphome/binary_sensor.py +++ b/homeassistant/components/esphome/binary_sensor.py @@ -26,10 +26,6 @@ async def async_setup_entry( ) -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=no-member - - class EsphomeBinarySensor( EsphomeEntity[BinarySensorInfo, BinarySensorState], BinarySensorEntity ): diff --git a/homeassistant/components/esphome/camera.py b/homeassistant/components/esphome/camera.py index 34b6d90f4d4..e8f37c3d191 100644 --- a/homeassistant/components/esphome/camera.py +++ b/homeassistant/components/esphome/camera.py @@ -32,10 +32,6 @@ async def async_setup_entry( ) -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=no-member - - class EsphomeCamera(Camera, EsphomeBaseEntity[CameraInfo, CameraState]): """A camera implementation for ESPHome.""" diff --git a/homeassistant/components/esphome/climate.py b/homeassistant/components/esphome/climate.py index 8715cb368c2..218f0fb319b 100644 --- a/homeassistant/components/esphome/climate.py +++ b/homeassistant/components/esphome/climate.py @@ -149,8 +149,7 @@ _PRESETS: EsphomeEnumMapper[ClimatePreset, str] = EsphomeEnumMapper( # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=invalid-overridden-method,no-member +# pylint: disable=invalid-overridden-method class EsphomeClimateEntity(EsphomeEntity[ClimateInfo, ClimateState], ClimateEntity): diff --git a/homeassistant/components/esphome/cover.py b/homeassistant/components/esphome/cover.py index d0d89cf40ad..e055ffc5d03 100644 --- a/homeassistant/components/esphome/cover.py +++ b/homeassistant/components/esphome/cover.py @@ -40,8 +40,7 @@ async def async_setup_entry( # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=invalid-overridden-method,no-member +# pylint: disable=invalid-overridden-method class EsphomeCover(EsphomeEntity[CoverInfo, CoverState], CoverEntity): diff --git a/homeassistant/components/esphome/fan.py b/homeassistant/components/esphome/fan.py index 7052ee42861..6abce0914cb 100644 --- a/homeassistant/components/esphome/fan.py +++ b/homeassistant/components/esphome/fan.py @@ -58,8 +58,7 @@ _FAN_DIRECTIONS: EsphomeEnumMapper[FanDirection, str] = EsphomeEnumMapper( # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=invalid-overridden-method,no-member +# pylint: disable=invalid-overridden-method class EsphomeFan(EsphomeEntity[FanInfo, FanState], FanEntity): diff --git a/homeassistant/components/esphome/light.py b/homeassistant/components/esphome/light.py index 0dd024832bb..ba968900ef0 100644 --- a/homeassistant/components/esphome/light.py +++ b/homeassistant/components/esphome/light.py @@ -50,8 +50,7 @@ async def async_setup_entry( # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=invalid-overridden-method,no-member +# pylint: disable=invalid-overridden-method class EsphomeLight(EsphomeEntity[LightInfo, LightState], LightEntity): diff --git a/homeassistant/components/esphome/number.py b/homeassistant/components/esphome/number.py index 91000731483..1a90cdbeb24 100644 --- a/homeassistant/components/esphome/number.py +++ b/homeassistant/components/esphome/number.py @@ -36,8 +36,7 @@ async def async_setup_entry( # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=invalid-overridden-method,no-member +# pylint: disable=invalid-overridden-method class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity): diff --git a/homeassistant/components/esphome/sensor.py b/homeassistant/components/esphome/sensor.py index 48e32809456..97cb5718903 100644 --- a/homeassistant/components/esphome/sensor.py +++ b/homeassistant/components/esphome/sensor.py @@ -60,8 +60,7 @@ async def async_setup_entry( # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=invalid-overridden-method,no-member +# pylint: disable=invalid-overridden-method _STATE_CLASSES: EsphomeEnumMapper[SensorStateClass, str | None] = EsphomeEnumMapper( diff --git a/homeassistant/components/esphome/switch.py b/homeassistant/components/esphome/switch.py index c2c88ee9376..218cd3905b0 100644 --- a/homeassistant/components/esphome/switch.py +++ b/homeassistant/components/esphome/switch.py @@ -29,8 +29,7 @@ async def async_setup_entry( # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property -# Pylint gets confused with the EsphomeEntity generics -> let mypy handle member checking -# pylint: disable=invalid-overridden-method,no-member +# pylint: disable=invalid-overridden-method class EsphomeSwitch(EsphomeEntity[SwitchInfo, SwitchState], SwitchEntity): diff --git a/homeassistant/components/flume/__init__.py b/homeassistant/components/flume/__init__.py index 4fc66d0ee70..1b441aa6ba5 100644 --- a/homeassistant/components/flume/__init__.py +++ b/homeassistant/components/flume/__init__.py @@ -47,7 +47,7 @@ def _setup_entry(hass: HomeAssistant, entry: ConfigEntry): flume_devices = FlumeDeviceList(flume_auth, http_session=http_session) except RequestException as ex: raise ConfigEntryNotReady from ex - except Exception as ex: # pylint: disable=broad-except + except Exception as ex: raise ConfigEntryAuthFailed from ex return flume_auth, flume_devices, http_session diff --git a/homeassistant/components/freebox/sensor.py b/homeassistant/components/freebox/sensor.py index 8c4e611827e..e68f7208538 100644 --- a/homeassistant/components/freebox/sensor.py +++ b/homeassistant/components/freebox/sensor.py @@ -50,25 +50,23 @@ async def async_setup_entry( ) ) - for sensor_key in CONNECTION_SENSORS: - entities.append( - FreeboxSensor(router, sensor_key, CONNECTION_SENSORS[sensor_key]) - ) + for sensor_key, sensor in CONNECTION_SENSORS.items(): + entities.append(FreeboxSensor(router, sensor_key, sensor)) - for sensor_key in CALL_SENSORS: - entities.append(FreeboxCallSensor(router, sensor_key, CALL_SENSORS[sensor_key])) + for sensor_key, sensor in CALL_SENSORS.items(): + entities.append(FreeboxCallSensor(router, sensor_key, sensor)) _LOGGER.debug("%s - %s - %s disk(s)", router.name, router.mac, len(router.disks)) for disk in router.disks.values(): for partition in disk["partitions"]: - for sensor_key in DISK_PARTITION_SENSORS: + for sensor_key, sensor in DISK_PARTITION_SENSORS.items(): entities.append( FreeboxDiskSensor( router, disk, partition, sensor_key, - DISK_PARTITION_SENSORS[sensor_key], + sensor, ) ) diff --git a/homeassistant/components/fritz/switch.py b/homeassistant/components/fritz/switch.py index 6e808598b77..238e65feacf 100644 --- a/homeassistant/components/fritz/switch.py +++ b/homeassistant/components/fritz/switch.py @@ -262,8 +262,8 @@ def wifi_entities_list( networks[i] = ssid return [ - FritzBoxWifiSwitch(fritzbox_tools, device_friendly_name, net, networks[net]) - for net in networks + FritzBoxWifiSwitch(fritzbox_tools, device_friendly_name, net, network_name) + for net, network_name in networks.items() ] @@ -428,8 +428,8 @@ class FritzBoxPortSwitch(FritzBoxBaseSwitch, SwitchEntity): "NewPortMappingDescription": "description", } - for key in attributes_dict: - self._attributes[attributes_dict[key]] = self.port_mapping[key] + for key, attr in attributes_dict.items(): + self._attributes[attr] = self.port_mapping[key] async def _async_handle_port_switch_on_off(self, turn_on: bool) -> bool: diff --git a/homeassistant/components/glances/sensor.py b/homeassistant/components/glances/sensor.py index 8306543f700..0e032de67be 100644 --- a/homeassistant/components/glances/sensor.py +++ b/homeassistant/components/glances/sensor.py @@ -25,9 +25,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): client, name, disk["mnt_point"], - SENSOR_TYPES[sensor_type][1], + sensor_details[1], sensor_type, - SENSOR_TYPES[sensor_type], + sensor_details, ) ) elif sensor_details[0] == "sensors": @@ -39,9 +39,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): client, name, sensor["label"], - SENSOR_TYPES[sensor_type][1], + sensor_details[1], sensor_type, - SENSOR_TYPES[sensor_type], + sensor_details, ) ) elif client.api.data[sensor_details[0]]: @@ -50,9 +50,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): client, name, "", - SENSOR_TYPES[sensor_type][1], + sensor_details[1], sensor_type, - SENSOR_TYPES[sensor_type], + sensor_details, ) ) diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index b46d48848da..b929c3c4c37 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -223,10 +223,10 @@ def setup(hass, config): def check_correct_scopes(token_file): """Check for the correct scopes in file.""" - tokenfile = open(token_file).read() - if "readonly" in tokenfile: - _LOGGER.warning("Please re-authenticate with Google") - return False + with open(token_file) as tokenfile: + if "readonly" in tokenfile.read(): + _LOGGER.warning("Please re-authenticate with Google") + return False return True diff --git a/homeassistant/components/google_assistant/smart_home.py b/homeassistant/components/google_assistant/smart_home.py index 747dc234efe..2ec51561eeb 100644 --- a/homeassistant/components/google_assistant/smart_home.py +++ b/homeassistant/components/google_assistant/smart_home.py @@ -214,8 +214,8 @@ async def handle_devices_execute(hass, data, payload): execute_results = await asyncio.gather( *[ - _entity_execute(entities[entity_id], data, executions[entity_id]) - for entity_id in executions + _entity_execute(entities[entity_id], data, execution) + for entity_id, execution in executions.items() ] ) diff --git a/homeassistant/components/google_pubsub/__init__.py b/homeassistant/components/google_pubsub/__init__.py index 365c118e99e..514b919e877 100644 --- a/homeassistant/components/google_pubsub/__init__.py +++ b/homeassistant/components/google_pubsub/__init__.py @@ -59,7 +59,9 @@ def setup(hass: HomeAssistant, yaml_config: dict[str, Any]): service_principal_path ) - topic_path = publisher.topic_path(project_id, topic_name) + topic_path = publisher.topic_path( # pylint: disable=no-member + project_id, topic_name + ) encoder = DateTimeJSONEncoder() diff --git a/homeassistant/components/here_travel_time/sensor.py b/homeassistant/components/here_travel_time/sensor.py index c02456b2a3f..11fd19bd895 100644 --- a/homeassistant/components/here_travel_time/sensor.py +++ b/homeassistant/components/here_travel_time/sensor.py @@ -27,7 +27,7 @@ from homeassistant.helpers import location import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import DiscoveryInfoType -import homeassistant.util.dt as dt +from homeassistant.util import dt _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/homekit/type_cameras.py b/homeassistant/components/homekit/type_cameras.py index e21ca189b4e..040c4017bb3 100644 --- a/homeassistant/components/homekit/type_cameras.py +++ b/homeassistant/components/homekit/type_cameras.py @@ -141,9 +141,9 @@ class Camera(HomeAccessory, PyhapCamera): def __init__(self, hass, driver, name, entity_id, aid, config): """Initialize a Camera accessory object.""" self._ffmpeg = hass.data[DATA_FFMPEG] - for config_key in CONFIG_DEFAULTS: + for config_key, conf in CONFIG_DEFAULTS.items(): if config_key not in config: - config[config_key] = CONFIG_DEFAULTS[config_key] + config[config_key] = conf max_fps = config[CONF_MAX_FPS] max_width = config[CONF_MAX_WIDTH] diff --git a/homeassistant/components/hue/sensor_base.py b/homeassistant/components/hue/sensor_base.py index 824f8cf42dc..957565c54e9 100644 --- a/homeassistant/components/hue/sensor_base.py +++ b/homeassistant/components/hue/sensor_base.py @@ -160,8 +160,8 @@ class SensorManager: ) ) - for platform in to_add: - self._component_add_entities[platform](to_add[platform]) + for platform, value in to_add.items(): + self._component_add_entities[platform](value) class GenericHueSensor(GenericHueDevice, entity.Entity): diff --git a/homeassistant/components/ios/notify.py b/homeassistant/components/ios/notify.py index 853fb0d479a..a096a43ac85 100644 --- a/homeassistant/components/ios/notify.py +++ b/homeassistant/components/ios/notify.py @@ -38,7 +38,7 @@ def log_rate_limits(hass, target, resp, level=20): rate_limits["successful"], rate_limits["maximum"], rate_limits["errors"], - str(resetsAtTime).split(".")[0], + str(resetsAtTime).split(".", maxsplit=1)[0], ) diff --git a/homeassistant/components/itunes/media_player.py b/homeassistant/components/itunes/media_player.py index 29ec7eb4558..2b531773d55 100644 --- a/homeassistant/components/itunes/media_player.py +++ b/homeassistant/components/itunes/media_player.py @@ -384,7 +384,7 @@ class ItunesDevice(MediaPlayerEntity): def media_next_track(self): """Send media_next command to media player.""" - response = self.client.next() # pylint: disable=not-callable + response = self.client.next() self.update_state(response) def media_previous_track(self): diff --git a/homeassistant/components/knx/climate.py b/homeassistant/components/knx/climate.py index c2e2a269b27..803ded55441 100644 --- a/homeassistant/components/knx/climate.py +++ b/homeassistant/components/knx/climate.py @@ -185,7 +185,7 @@ class KNXClimate(KnxEntity, ClimateEntity): f"{self._device.temperature.group_address_state}_" f"{self._device.target_temperature.group_address_state}_" f"{self._device.target_temperature.group_address}_" - f"{self._device._setpoint_shift.group_address}" # pylint: disable=protected-access + f"{self._device._setpoint_shift.group_address}" ) async def async_update(self) -> None: diff --git a/homeassistant/components/kulersky/light.py b/homeassistant/components/kulersky/light.py index fd907235b45..6e04dbdfcfd 100644 --- a/homeassistant/components/kulersky/light.py +++ b/homeassistant/components/kulersky/light.py @@ -142,7 +142,6 @@ class KulerskyLight(LightEntity): try: if not self._available: await self._light.connect() - # pylint: disable=invalid-name rgbw = await self._light.get_color() except pykulersky.PykulerskyException as exc: if self._available: diff --git a/homeassistant/components/lg_netcast/media_player.py b/homeassistant/components/lg_netcast/media_player.py index 31316ca975b..5b5ce313689 100644 --- a/homeassistant/components/lg_netcast/media_player.py +++ b/homeassistant/components/lg_netcast/media_player.py @@ -139,7 +139,8 @@ class LgTVDevice(MediaPlayerEntity): self._sources = dict(zip(channel_names, channel_list)) # sort source names by the major channel number source_tuples = [ - (k, self._sources[k].find("major").text) for k in self._sources + (k, source.find("major").text) + for k, source in self._sources.items() ] sorted_sources = sorted( source_tuples, key=lambda channel: int(channel[1]) diff --git a/homeassistant/components/life360/device_tracker.py b/homeassistant/components/life360/device_tracker.py index 5403a483ffb..6697dd50893 100644 --- a/homeassistant/components/life360/device_tracker.py +++ b/homeassistant/components/life360/device_tracker.py @@ -189,7 +189,7 @@ class Life360Scanner: { ATTR_ENTITY_ID: f"{DEVICE_TRACKER_DOMAIN}.{dev_id}", ATTR_WAIT: str(last_seen - (prev_seen or self._started)).split( - "." + ".", maxsplit=1 )[0], }, ) diff --git a/homeassistant/components/luftdaten/config_flow.py b/homeassistant/components/luftdaten/config_flow.py index 0df12fc8907..f13fcc831dc 100644 --- a/homeassistant/components/luftdaten/config_flow.py +++ b/homeassistant/components/luftdaten/config_flow.py @@ -81,7 +81,7 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): return self._show_form({CONF_SENSOR_ID: "invalid_sensor"}) available_sensors = [ - x for x in luftdaten.values if luftdaten.values[x] is not None + x for x, x_values in luftdaten.values.items() if x_values is not None ] if available_sensors: diff --git a/homeassistant/components/mobile_app/notify.py b/homeassistant/components/mobile_app/notify.py index 1acb9f25c0c..162ec8afeab 100644 --- a/homeassistant/components/mobile_app/notify.py +++ b/homeassistant/components/mobile_app/notify.py @@ -79,7 +79,7 @@ def log_rate_limits(hass, device_name, resp, level=logging.INFO): rate_limits[ATTR_PUSH_RATE_LIMITS_SUCCESSFUL], rate_limits[ATTR_PUSH_RATE_LIMITS_MAXIMUM], rate_limits[ATTR_PUSH_RATE_LIMITS_ERRORS], - str(resetsAtTime).split(".")[0], + str(resetsAtTime).split(".", maxsplit=1)[0], ) diff --git a/homeassistant/components/modern_forms/fan.py b/homeassistant/components/modern_forms/fan.py index 2668b26857b..db8f2e011a9 100644 --- a/homeassistant/components/modern_forms/fan.py +++ b/homeassistant/components/modern_forms/fan.py @@ -8,7 +8,7 @@ import voluptuous as vol from homeassistant.components.fan import SUPPORT_DIRECTION, SUPPORT_SET_SPEED, FanEntity from homeassistant.config_entries import ConfigEntry -import homeassistant.helpers.entity_platform as entity_platform +from homeassistant.helpers import entity_platform from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util.percentage import ( diff --git a/homeassistant/components/modern_forms/light.py b/homeassistant/components/modern_forms/light.py index 2c8298f00da..ee30c0c489f 100644 --- a/homeassistant/components/modern_forms/light.py +++ b/homeassistant/components/modern_forms/light.py @@ -12,7 +12,7 @@ from homeassistant.components.light import ( LightEntity, ) from homeassistant.config_entries import ConfigEntry -import homeassistant.helpers.entity_platform as entity_platform +from homeassistant.helpers import entity_platform from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util.percentage import ( diff --git a/homeassistant/components/mysensors/light.py b/homeassistant/components/mysensors/light.py index b08d94cebb0..e1f4dd3d1e0 100644 --- a/homeassistant/components/mysensors/light.py +++ b/homeassistant/components/mysensors/light.py @@ -163,6 +163,8 @@ class MySensorsLight(mysensors.device.MySensorsEntity, LightEntity): if self.assumed_state: # optimistically assume that light has changed state + # pylint: disable=no-value-for-parameter + # https://github.com/PyCQA/pylint/issues/4546 self._hs = color_util.color_RGB_to_hs(*rgb) # type: ignore[assignment] self._white = white self._values[self.value_type] = hex_color diff --git a/homeassistant/components/netatmo/select.py b/homeassistant/components/netatmo/select.py index 726ae919099..718d7e440b9 100644 --- a/homeassistant/components/netatmo/select.py +++ b/homeassistant/components/netatmo/select.py @@ -87,11 +87,9 @@ class NetatmoScheduleSelect(NetatmoBase, SelectEntity): self._attr_unique_id = f"{self._home_id}-schedule-select" - self._attr_current_option = ( - self._data._get_selected_schedule( # pylint: disable=protected-access - home_id=self._home_id - ).get("name") - ) + self._attr_current_option = self._data._get_selected_schedule( + home_id=self._home_id + ).get("name") self._attr_options = options async def async_added_to_hass(self) -> None: diff --git a/homeassistant/components/ombi/sensor.py b/homeassistant/components/ombi/sensor.py index 8c08b026b28..c91cf429c94 100644 --- a/homeassistant/components/ombi/sensor.py +++ b/homeassistant/components/ombi/sensor.py @@ -22,10 +22,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None): ombi = hass.data[DOMAIN]["instance"] - for sensor in SENSOR_TYPES: + for sensor, sensor_val in SENSOR_TYPES.items(): sensor_label = sensor - sensor_type = SENSOR_TYPES[sensor]["type"] - sensor_icon = SENSOR_TYPES[sensor]["icon"] + sensor_type = sensor_val["type"] + sensor_icon = sensor_val["icon"] sensors.append(OmbiSensor(sensor_label, sensor_type, ombi, sensor_icon)) add_entities(sensors, True) diff --git a/homeassistant/components/openhardwaremonitor/sensor.py b/homeassistant/components/openhardwaremonitor/sensor.py index 8d14074892d..8f43c1e5e9b 100644 --- a/homeassistant/components/openhardwaremonitor/sensor.py +++ b/homeassistant/components/openhardwaremonitor/sensor.py @@ -88,8 +88,7 @@ class OpenHardwareMonitorDevice(SensorEntity): array = self._data.data[OHM_CHILDREN] _attributes = {} - for path_index in range(0, len(self.path)): - path_number = self.path[path_index] + for path_index, path_number in enumerate(self.path): values = array[path_number] if path_index == len(self.path) - 1: diff --git a/homeassistant/components/ozw/entity.py b/homeassistant/components/ozw/entity.py index 305601a2333..d5cafa615df 100644 --- a/homeassistant/components/ozw/entity.py +++ b/homeassistant/components/ozw/entity.py @@ -83,9 +83,9 @@ class ZWaveDeviceEntityValues: return # Go through the possible values for this entity defined by the schema. - for name in self._values: + for name, name_value in self._values.items(): # Skip if it's already been added. - if self._values[name] is not None: + if name_value is not None: continue # Skip if the value doesn't match the schema. if not check_value_schema(value, self._schema[const.DISC_VALUES][name]): diff --git a/homeassistant/components/ping/binary_sensor.py b/homeassistant/components/ping/binary_sensor.py index cf2d8f7ed7a..0c82c9ff8c4 100644 --- a/homeassistant/components/ping/binary_sensor.py +++ b/homeassistant/components/ping/binary_sensor.py @@ -256,14 +256,18 @@ class PingDataSubProcess(PingData): ) if sys.platform == "win32": - match = WIN32_PING_MATCHER.search(str(out_data).split("\n")[-1]) + match = WIN32_PING_MATCHER.search( + str(out_data).rsplit("\n", maxsplit=1)[-1] + ) rtt_min, rtt_avg, rtt_max = match.groups() return {"min": rtt_min, "avg": rtt_avg, "max": rtt_max, "mdev": ""} if "max/" not in str(out_data): - match = PING_MATCHER_BUSYBOX.search(str(out_data).split("\n")[-1]) + match = PING_MATCHER_BUSYBOX.search( + str(out_data).rsplit("\n", maxsplit=1)[-1] + ) rtt_min, rtt_avg, rtt_max = match.groups() return {"min": rtt_min, "avg": rtt_avg, "max": rtt_max, "mdev": ""} - match = PING_MATCHER.search(str(out_data).split("\n")[-1]) + match = PING_MATCHER.search(str(out_data).rsplit("\n", maxsplit=1)[-1]) rtt_min, rtt_avg, rtt_max, rtt_mdev = match.groups() return {"min": rtt_min, "avg": rtt_avg, "max": rtt_max, "mdev": rtt_mdev} except asyncio.TimeoutError: diff --git a/homeassistant/components/proximity/__init__.py b/homeassistant/components/proximity/__init__.py index de9d6247f9f..1840162f896 100644 --- a/homeassistant/components/proximity/__init__.py +++ b/homeassistant/components/proximity/__init__.py @@ -230,10 +230,10 @@ class Proximity(Entity): closest_device: str = None dist_to_zone: float = None - for device in distances_to_zone: - if not dist_to_zone or distances_to_zone[device] < dist_to_zone: + for device, zone in distances_to_zone.items(): + if not dist_to_zone or zone < dist_to_zone: closest_device = device - dist_to_zone = distances_to_zone[device] + dist_to_zone = zone # If the closest device is one of the other devices. if closest_device != entity: diff --git a/homeassistant/components/ring/binary_sensor.py b/homeassistant/components/ring/binary_sensor.py index 28d686df06a..d2c412a691d 100644 --- a/homeassistant/components/ring/binary_sensor.py +++ b/homeassistant/components/ring/binary_sensor.py @@ -30,8 +30,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): sensors = [] for device_type in ("doorbots", "authorized_doorbots", "stickup_cams"): - for sensor_type in SENSOR_TYPES: - if device_type not in SENSOR_TYPES[sensor_type][1]: + for sensor_type, sensor in SENSOR_TYPES.items(): + if device_type not in sensor[1]: continue for device in devices[device_type]: diff --git a/homeassistant/components/ring/sensor.py b/homeassistant/components/ring/sensor.py index fb1c38fcbde..97fb8ec9d21 100644 --- a/homeassistant/components/ring/sensor.py +++ b/homeassistant/components/ring/sensor.py @@ -19,19 +19,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities): sensors = [] for device_type in ("chimes", "doorbots", "authorized_doorbots", "stickup_cams"): - for sensor_type in SENSOR_TYPES: - if device_type not in SENSOR_TYPES[sensor_type][1]: + for sensor_type, sensor in SENSOR_TYPES.items(): + if device_type not in sensor[1]: continue for device in devices[device_type]: if device_type == "battery" and device.battery_life is None: continue - sensors.append( - SENSOR_TYPES[sensor_type][6]( - config_entry.entry_id, device, sensor_type - ) - ) + sensors.append(sensor[6](config_entry.entry_id, device, sensor_type)) async_add_entities(sensors) diff --git a/homeassistant/components/rpi_camera/camera.py b/homeassistant/components/rpi_camera/camera.py index 2d7edd83fed..070e861b3c9 100644 --- a/homeassistant/components/rpi_camera/camera.py +++ b/homeassistant/components/rpi_camera/camera.py @@ -26,9 +26,10 @@ _LOGGER = logging.getLogger(__name__) def kill_raspistill(*args): """Kill any previously running raspistill process..""" - subprocess.Popen( + with subprocess.Popen( ["killall", "raspistill"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT - ) + ): + pass def setup_platform(hass, config, add_entities, discovery_info=None): @@ -116,7 +117,10 @@ class RaspberryCamera(Camera): cmd_args.append("-a") cmd_args.append(str(device_info[CONF_OVERLAY_TIMESTAMP])) - subprocess.Popen(cmd_args, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + with subprocess.Popen( + cmd_args, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT + ): + pass def camera_image(self): """Return raspistill image response.""" diff --git a/homeassistant/components/sense/sensor.py b/homeassistant/components/sense/sensor.py index d779870d37d..238b0b83cde 100644 --- a/homeassistant/components/sense/sensor.py +++ b/homeassistant/components/sense/sensor.py @@ -96,8 +96,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): for i in range(len(data.active_voltage)): devices.append(SenseVoltageSensor(data, i, sense_monitor_id)) - for type_id in TRENDS_SENSOR_TYPES: - typ = TRENDS_SENSOR_TYPES[type_id] + for type_id, typ in TRENDS_SENSOR_TYPES.items(): for var in SENSOR_VARIANTS: name = typ.name sensor_type = typ.sensor_type diff --git a/homeassistant/components/sentry/__init__.py b/homeassistant/components/sentry/__init__.py index 37941a0bcaa..c34bc2b350a 100644 --- a/homeassistant/components/sentry/__init__.py +++ b/homeassistant/components/sentry/__init__.py @@ -78,7 +78,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ), } - # pylint: disable=abstract-class-instantiated sentry_sdk.init( dsn=entry.data[CONF_DSN], environment=entry.options.get(CONF_ENVIRONMENT), diff --git a/homeassistant/components/slack/notify.py b/homeassistant/components/slack/notify.py index c2ca834b565..0eadc26075e 100644 --- a/homeassistant/components/slack/notify.py +++ b/homeassistant/components/slack/notify.py @@ -22,8 +22,7 @@ from homeassistant.components.notify import ( ) from homeassistant.const import ATTR_ICON, CONF_API_KEY, CONF_ICON, CONF_USERNAME from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import aiohttp_client, config_validation as cv -import homeassistant.helpers.template as template +from homeassistant.helpers import aiohttp_client, config_validation as cv, template from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index 024845a08fc..75c5da85c34 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -149,38 +149,38 @@ async def async_setup_entry(hass, config_entry, async_add_entities): for service_location in smappee_base.smappee.service_locations.values(): # Add all basic sensors (realtime values and aggregators) # Some are available in local only env - for sensor in TREND_SENSORS: - if not service_location.local_polling or TREND_SENSORS[sensor][5]: + for sensor, attributes in TREND_SENSORS.items(): + if not service_location.local_polling or attributes[5]: entities.append( SmappeeSensor( smappee_base=smappee_base, service_location=service_location, sensor=sensor, - attributes=TREND_SENSORS[sensor], + attributes=attributes, ) ) if service_location.has_reactive_value: - for reactive_sensor in REACTIVE_SENSORS: + for reactive_sensor, attributes in REACTIVE_SENSORS.items(): entities.append( SmappeeSensor( smappee_base=smappee_base, service_location=service_location, sensor=reactive_sensor, - attributes=REACTIVE_SENSORS[reactive_sensor], + attributes=attributes, ) ) # Add solar sensors (some are available in local only env) if service_location.has_solar_production: - for sensor in SOLAR_SENSORS: - if not service_location.local_polling or SOLAR_SENSORS[sensor][5]: + for sensor, attributes in SOLAR_SENSORS.items(): + if not service_location.local_polling or attributes[5]: entities.append( SmappeeSensor( smappee_base=smappee_base, service_location=service_location, sensor=sensor, - attributes=SOLAR_SENSORS[sensor], + attributes=attributes, ) ) diff --git a/homeassistant/components/snmp/switch.py b/homeassistant/components/snmp/switch.py index 7210c8e5fd3..bc7807cb6db 100644 --- a/homeassistant/components/snmp/switch.py +++ b/homeassistant/components/snmp/switch.py @@ -240,7 +240,7 @@ class SnmpSwitch(SwitchEntity): await self._set(command) # User set vartype Null, command must be an empty string elif self._vartype == "Null": - await self._set(Null)("") + await self._set("") # user did not set vartype but command is digit: defaulting to Integer # or user did set vartype else: diff --git a/homeassistant/components/switcher_kis/sensor.py b/homeassistant/components/switcher_kis/sensor.py index 5b6b40a0e2d..2325d382b56 100644 --- a/homeassistant/components/switcher_kis/sensor.py +++ b/homeassistant/components/switcher_kis/sensor.py @@ -78,8 +78,8 @@ async def async_setup_platform( device_data = hass.data[DOMAIN][DATA_DEVICE] async_add_entities( - SwitcherSensorEntity(device_data, attribute, SENSORS[attribute]) - for attribute in SENSORS + SwitcherSensorEntity(device_data, attribute, sensor) + for attribute, sensor in SENSORS.items() ) diff --git a/homeassistant/components/synology_dsm/binary_sensor.py b/homeassistant/components/synology_dsm/binary_sensor.py index e94dc1a94ac..5f27aa3b038 100644 --- a/homeassistant/components/synology_dsm/binary_sensor.py +++ b/homeassistant/components/synology_dsm/binary_sensor.py @@ -32,17 +32,13 @@ async def async_setup_entry( | SynoDSMUpgradeBinarySensor | SynoDSMStorageBinarySensor ] = [ - SynoDSMSecurityBinarySensor( - api, sensor_type, SECURITY_BINARY_SENSORS[sensor_type], coordinator - ) - for sensor_type in SECURITY_BINARY_SENSORS + SynoDSMSecurityBinarySensor(api, sensor_type, sensor, coordinator) + for sensor_type, sensor in SECURITY_BINARY_SENSORS.items() ] entities += [ - SynoDSMUpgradeBinarySensor( - api, sensor_type, UPGRADE_BINARY_SENSORS[sensor_type], coordinator - ) - for sensor_type in UPGRADE_BINARY_SENSORS + SynoDSMUpgradeBinarySensor(api, sensor_type, sensor, coordinator) + for sensor_type, sensor in UPGRADE_BINARY_SENSORS.items() ] # Handle all disks @@ -52,11 +48,11 @@ async def async_setup_entry( SynoDSMStorageBinarySensor( api, sensor_type, - STORAGE_DISK_BINARY_SENSORS[sensor_type], + sensor, coordinator, disk, ) - for sensor_type in STORAGE_DISK_BINARY_SENSORS + for sensor_type, sensor in STORAGE_DISK_BINARY_SENSORS.items() ] async_add_entities(entities) diff --git a/homeassistant/components/synology_dsm/sensor.py b/homeassistant/components/synology_dsm/sensor.py index 4cf982e15f6..5942ce4a5b1 100644 --- a/homeassistant/components/synology_dsm/sensor.py +++ b/homeassistant/components/synology_dsm/sensor.py @@ -46,10 +46,8 @@ async def async_setup_entry( coordinator = data[COORDINATOR_CENTRAL] entities: list[SynoDSMUtilSensor | SynoDSMStorageSensor | SynoDSMInfoSensor] = [ - SynoDSMUtilSensor( - api, sensor_type, UTILISATION_SENSORS[sensor_type], coordinator - ) - for sensor_type in UTILISATION_SENSORS + SynoDSMUtilSensor(api, sensor_type, sensor, coordinator) + for sensor_type, sensor in UTILISATION_SENSORS.items() ] # Handle all volumes @@ -59,11 +57,11 @@ async def async_setup_entry( SynoDSMStorageSensor( api, sensor_type, - STORAGE_VOL_SENSORS[sensor_type], + sensor, coordinator, volume, ) - for sensor_type in STORAGE_VOL_SENSORS + for sensor_type, sensor in STORAGE_VOL_SENSORS.items() ] # Handle all disks @@ -73,18 +71,16 @@ async def async_setup_entry( SynoDSMStorageSensor( api, sensor_type, - STORAGE_DISK_SENSORS[sensor_type], + sensor, coordinator, disk, ) - for sensor_type in STORAGE_DISK_SENSORS + for sensor_type, sensor in STORAGE_DISK_SENSORS.items() ] entities += [ - SynoDSMInfoSensor( - api, sensor_type, INFORMATION_SENSORS[sensor_type], coordinator - ) - for sensor_type in INFORMATION_SENSORS + SynoDSMInfoSensor(api, sensor_type, sensor, coordinator) + for sensor_type, sensor in INFORMATION_SENSORS.items() ] async_add_entities(entities) diff --git a/homeassistant/components/synology_dsm/switch.py b/homeassistant/components/synology_dsm/switch.py index 27ffbfde799..e08516ec03a 100644 --- a/homeassistant/components/synology_dsm/switch.py +++ b/homeassistant/components/synology_dsm/switch.py @@ -44,9 +44,9 @@ async def async_setup_entry( await coordinator.async_refresh() entities += [ SynoDSMSurveillanceHomeModeToggle( - api, sensor_type, SURVEILLANCE_SWITCH[sensor_type], version, coordinator + api, sensor_type, switch, version, coordinator ) - for sensor_type in SURVEILLANCE_SWITCH + for sensor_type, switch in SURVEILLANCE_SWITCH.items() ] async_add_entities(entities, True) diff --git a/homeassistant/components/tasmota/discovery.py b/homeassistant/components/tasmota/discovery.py index 1e5bde5a3d5..37b373d30a1 100644 --- a/homeassistant/components/tasmota/discovery.py +++ b/homeassistant/components/tasmota/discovery.py @@ -18,7 +18,7 @@ from hatasmota.models import DiscoveryHashType, TasmotaDeviceConfig from hatasmota.mqtt import TasmotaMQTTClient from hatasmota.sensor import TasmotaBaseSensorConfig -import homeassistant.components.sensor as sensor +from homeassistant.components import sensor from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dev_reg diff --git a/homeassistant/components/tellstick/sensor.py b/homeassistant/components/tellstick/sensor.py index 5be89216365..599c19388d6 100644 --- a/homeassistant/components/tellstick/sensor.py +++ b/homeassistant/components/tellstick/sensor.py @@ -127,9 +127,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None): else: continue - for datatype in sensor_value_descriptions: + for datatype, sensor_info in sensor_value_descriptions.items(): if datatype & datatype_mask and tellcore_sensor.has_value(datatype): - sensor_info = sensor_value_descriptions[datatype] sensors.append( TellstickSensor(sensor_name, tellcore_sensor, datatype, sensor_info) ) diff --git a/homeassistant/components/torque/sensor.py b/homeassistant/components/torque/sensor.py index 156259adccb..8e3053d9bd8 100644 --- a/homeassistant/components/torque/sensor.py +++ b/homeassistant/components/torque/sensor.py @@ -95,10 +95,10 @@ class TorqueReceiveDataView(HomeAssistantView): if pid in self.sensors: self.sensors[pid].async_on_update(data[key]) - for pid in names: + for pid, name in names.items(): if pid not in self.sensors: self.sensors[pid] = TorqueSensor( - ENTITY_NAME_FORMAT.format(self.vehicle, names[pid]), units.get(pid) + ENTITY_NAME_FORMAT.format(self.vehicle, name), units.get(pid) ) hass.async_add_job(self.add_entities, [self.sensors[pid]]) diff --git a/homeassistant/components/tuya/__init__.py b/homeassistant/components/tuya/__init__.py index 595350324f9..7a639665948 100644 --- a/homeassistant/components/tuya/__init__.py +++ b/homeassistant/components/tuya/__init__.py @@ -197,7 +197,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: @callback def _async_cancel_tuya_tracker(event): - domain_data[TUYA_TRACKER]() + domain_data[TUYA_TRACKER]() # pylint: disable=not-callable domain_data[STOP_CANCEL] = hass.bus.async_listen_once( EVENT_HOMEASSISTANT_STOP, _async_cancel_tuya_tracker diff --git a/homeassistant/components/vallox/__init__.py b/homeassistant/components/vallox/__init__.py index eb5edfe7fcf..27210e0c750 100644 --- a/homeassistant/components/vallox/__init__.py +++ b/homeassistant/components/vallox/__init__.py @@ -112,8 +112,8 @@ async def async_setup(hass, config): hass.data[DOMAIN] = {"client": client, "state_proxy": state_proxy, "name": name} - for vallox_service in SERVICE_TO_METHOD: - schema = SERVICE_TO_METHOD[vallox_service]["schema"] + for vallox_service, method in SERVICE_TO_METHOD.items(): + schema = method["schema"] hass.services.async_register( DOMAIN, vallox_service, service_handler.async_handle, schema=schema ) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index af7f59bd266..96559fe5a68 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -92,8 +92,8 @@ async def async_setup(hass, config): data["method"] = method["method"] async_dispatcher_send(hass, DOMAIN, data) - for service in SERVICE_TO_METHOD: - schema = SERVICE_TO_METHOD[service]["schema"] + for service, method in SERVICE_TO_METHOD.items(): + schema = method["schema"] hass.services.async_register( DOMAIN, service, async_service_handler, schema=schema ) diff --git a/homeassistant/components/withings/const.py b/homeassistant/components/withings/const.py index d88f4e38c6a..dd744152bb1 100644 --- a/homeassistant/components/withings/const.py +++ b/homeassistant/components/withings/const.py @@ -1,7 +1,7 @@ """Constants used by the Withings component.""" from enum import Enum -import homeassistant.const as const +from homeassistant import const CONF_PROFILES = "profiles" CONF_USE_WEBHOOK = "use_webhook" diff --git a/homeassistant/components/workday/binary_sensor.py b/homeassistant/components/workday/binary_sensor.py index ed3822b9698..533bc77e27c 100644 --- a/homeassistant/components/workday/binary_sensor.py +++ b/homeassistant/components/workday/binary_sensor.py @@ -9,7 +9,7 @@ import voluptuous as vol from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity from homeassistant.const import CONF_NAME, WEEKDAYS import homeassistant.helpers.config_validation as cv -import homeassistant.util.dt as dt +from homeassistant.util import dt _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/xiaomi_miio/fan.py b/homeassistant/components/xiaomi_miio/fan.py index a5a5122ea07..49ae1cf7b7c 100644 --- a/homeassistant/components/xiaomi_miio/fan.py +++ b/homeassistant/components/xiaomi_miio/fan.py @@ -634,8 +634,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if update_tasks: await asyncio.wait(update_tasks) - for air_purifier_service in SERVICE_TO_METHOD: - schema = SERVICE_TO_METHOD[air_purifier_service].get( + for air_purifier_service, method in SERVICE_TO_METHOD.items(): + schema = method[air_purifier_service].get( "schema", AIRPURIFIER_SERVICE_SCHEMA ) hass.services.async_register( diff --git a/homeassistant/components/xiaomi_miio/light.py b/homeassistant/components/xiaomi_miio/light.py index f6cd468ad00..6025ae047c6 100644 --- a/homeassistant/components/xiaomi_miio/light.py +++ b/homeassistant/components/xiaomi_miio/light.py @@ -241,10 +241,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if update_tasks: await asyncio.wait(update_tasks) - for xiaomi_miio_service in SERVICE_TO_METHOD: - schema = SERVICE_TO_METHOD[xiaomi_miio_service].get( - "schema", XIAOMI_MIIO_SERVICE_SCHEMA - ) + for xiaomi_miio_service, method in SERVICE_TO_METHOD.items(): + schema = method.get("schema", XIAOMI_MIIO_SERVICE_SCHEMA) hass.services.async_register( DOMAIN, xiaomi_miio_service, async_service_handler, schema=schema ) diff --git a/homeassistant/components/xiaomi_miio/switch.py b/homeassistant/components/xiaomi_miio/switch.py index ace0e52eaea..28c4f79ef28 100644 --- a/homeassistant/components/xiaomi_miio/switch.py +++ b/homeassistant/components/xiaomi_miio/switch.py @@ -250,8 +250,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if update_tasks: await asyncio.wait(update_tasks) - for plug_service in SERVICE_TO_METHOD: - schema = SERVICE_TO_METHOD[plug_service].get("schema", SERVICE_SCHEMA) + for plug_service, method in SERVICE_TO_METHOD.items(): + schema = method[plug_service].get("schema", SERVICE_SCHEMA) hass.services.async_register( DOMAIN, plug_service, async_service_handler, schema=schema ) diff --git a/homeassistant/components/xmpp/notify.py b/homeassistant/components/xmpp/notify.py index bc5ebf12f75..29624f37ffa 100644 --- a/homeassistant/components/xmpp/notify.py +++ b/homeassistant/components/xmpp/notify.py @@ -190,7 +190,9 @@ async def async_send_message( # noqa: C901 _LOGGER.info("Sending file to %s", recipient) message = self.Message(sto=recipient, stype="chat") message["body"] = url - message["oob"]["url"] = url + message["oob"][ # pylint: disable=invalid-sequence-index + "url" + ] = url try: message.send() except (IqError, IqTimeout, XMPPError) as ex: diff --git a/homeassistant/components/zha/core/channels/closures.py b/homeassistant/components/zha/core/channels/closures.py index e427bc962b4..c63d069767d 100644 --- a/homeassistant/components/zha/core/channels/closures.py +++ b/homeassistant/components/zha/core/channels/closures.py @@ -1,5 +1,5 @@ """Closures channels module for Zigbee Home Automation.""" -import zigpy.zcl.clusters.closures as closures +from zigpy.zcl.clusters import closures from homeassistant.core import callback diff --git a/homeassistant/components/zha/core/channels/general.py b/homeassistant/components/zha/core/channels/general.py index a0c2c3bc699..5ca8c9fd4ba 100644 --- a/homeassistant/components/zha/core/channels/general.py +++ b/homeassistant/components/zha/core/channels/general.py @@ -6,7 +6,7 @@ from collections.abc import Coroutine from typing import Any import zigpy.exceptions -import zigpy.zcl.clusters.general as general +from zigpy.zcl.clusters import general from zigpy.zcl.foundation import Status from homeassistant.core import callback diff --git a/homeassistant/components/zha/core/channels/homeautomation.py b/homeassistant/components/zha/core/channels/homeautomation.py index 6e9d4138621..583cfb105bd 100644 --- a/homeassistant/components/zha/core/channels/homeautomation.py +++ b/homeassistant/components/zha/core/channels/homeautomation.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Coroutine -import zigpy.zcl.clusters.homeautomation as homeautomation +from zigpy.zcl.clusters import homeautomation from .. import registries from ..const import ( diff --git a/homeassistant/components/zha/core/channels/hvac.py b/homeassistant/components/zha/core/channels/hvac.py index 76f9c0b4e80..6b0cd9e5e28 100644 --- a/homeassistant/components/zha/core/channels/hvac.py +++ b/homeassistant/components/zha/core/channels/hvac.py @@ -11,7 +11,7 @@ from collections import namedtuple from typing import Any from zigpy.exceptions import ZigbeeException -import zigpy.zcl.clusters.hvac as hvac +from zigpy.zcl.clusters import hvac from zigpy.zcl.foundation import Status from homeassistant.core import callback diff --git a/homeassistant/components/zha/core/channels/lighting.py b/homeassistant/components/zha/core/channels/lighting.py index 8c2b2bddd67..fbf53bec9a5 100644 --- a/homeassistant/components/zha/core/channels/lighting.py +++ b/homeassistant/components/zha/core/channels/lighting.py @@ -4,7 +4,7 @@ from __future__ import annotations from collections.abc import Coroutine from contextlib import suppress -import zigpy.zcl.clusters.lighting as lighting +from zigpy.zcl.clusters import lighting from .. import registries from ..const import REPORT_CONFIG_DEFAULT diff --git a/homeassistant/components/zha/core/channels/lightlink.py b/homeassistant/components/zha/core/channels/lightlink.py index e42a3b20053..46c40fdaff0 100644 --- a/homeassistant/components/zha/core/channels/lightlink.py +++ b/homeassistant/components/zha/core/channels/lightlink.py @@ -2,7 +2,7 @@ import asyncio import zigpy.exceptions -import zigpy.zcl.clusters.lightlink as lightlink +from zigpy.zcl.clusters import lightlink from .. import registries from .base import ChannelStatus, ZigbeeChannel diff --git a/homeassistant/components/zha/core/channels/measurement.py b/homeassistant/components/zha/core/channels/measurement.py index 77351441b56..19ecc8a6335 100644 --- a/homeassistant/components/zha/core/channels/measurement.py +++ b/homeassistant/components/zha/core/channels/measurement.py @@ -1,5 +1,5 @@ """Measurement channels module for Zigbee Home Automation.""" -import zigpy.zcl.clusters.measurement as measurement +from zigpy.zcl.clusters import measurement from .. import registries from ..const import ( diff --git a/homeassistant/components/zha/core/channels/protocol.py b/homeassistant/components/zha/core/channels/protocol.py index 4162809da7a..51d837a8014 100644 --- a/homeassistant/components/zha/core/channels/protocol.py +++ b/homeassistant/components/zha/core/channels/protocol.py @@ -1,5 +1,5 @@ """Protocol channels module for Zigbee Home Automation.""" -import zigpy.zcl.clusters.protocol as protocol +from zigpy.zcl.clusters import protocol from .. import registries from .base import ZigbeeChannel diff --git a/homeassistant/components/zha/core/channels/security.py b/homeassistant/components/zha/core/channels/security.py index 2af44bdf4e1..cb90c740065 100644 --- a/homeassistant/components/zha/core/channels/security.py +++ b/homeassistant/components/zha/core/channels/security.py @@ -11,7 +11,7 @@ from collections.abc import Coroutine import logging from zigpy.exceptions import ZigbeeException -import zigpy.zcl.clusters.security as security +from zigpy.zcl.clusters import security from zigpy.zcl.clusters.security import IasAce as AceCluster from homeassistant.core import CALLABLE_T, callback diff --git a/homeassistant/components/zha/core/channels/smartenergy.py b/homeassistant/components/zha/core/channels/smartenergy.py index cfe395773ad..4e6302d32b5 100644 --- a/homeassistant/components/zha/core/channels/smartenergy.py +++ b/homeassistant/components/zha/core/channels/smartenergy.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Coroutine -import zigpy.zcl.clusters.smartenergy as smartenergy +from zigpy.zcl.clusters import smartenergy from homeassistant.const import ( POWER_WATT, diff --git a/homeassistant/components/zha/core/registries.py b/homeassistant/components/zha/core/registries.py index 6bb9e155b0f..04e97f8b7ed 100644 --- a/homeassistant/components/zha/core/registries.py +++ b/homeassistant/components/zha/core/registries.py @@ -5,9 +5,9 @@ import collections from typing import Callable, Dict import attr +from zigpy import zcl import zigpy.profiles.zha import zigpy.profiles.zll -import zigpy.zcl as zcl from homeassistant.components.alarm_control_panel import DOMAIN as ALARM from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR diff --git a/homeassistant/components/zha/core/typing.py b/homeassistant/components/zha/core/typing.py index 0fe46a4628e..15e8be0db1e 100644 --- a/homeassistant/components/zha/core/typing.py +++ b/homeassistant/components/zha/core/typing.py @@ -26,8 +26,8 @@ ZigpyGroupType = zigpy.group.Group ZigpyZdoType = zigpy.zdo.ZDO if TYPE_CHECKING: + from homeassistant.components.zha.core import channels import homeassistant.components.zha.core.channels - import homeassistant.components.zha.core.channels as channels import homeassistant.components.zha.core.channels.base as base_channels import homeassistant.components.zha.core.device import homeassistant.components.zha.core.gateway diff --git a/homeassistant/components/zha/device_action.py b/homeassistant/components/zha/device_action.py index 9d419b16435..de39ff50511 100644 --- a/homeassistant/components/zha/device_action.py +++ b/homeassistant/components/zha/device_action.py @@ -67,8 +67,8 @@ async def async_get_actions(hass: HomeAssistant, device_id: str) -> list[dict]: ] actions = [ action - for channel in DEVICE_ACTIONS - for action in DEVICE_ACTIONS[channel] + for channel, channel_actions in DEVICE_ACTIONS.items() + for action in channel_actions if channel in cluster_channels ] for action in actions: diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index 3c50261b565..0176cf1ea3b 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -6,7 +6,7 @@ import functools import math from zigpy.exceptions import ZigbeeException -import zigpy.zcl.clusters.hvac as hvac +from zigpy.zcl.clusters import hvac from homeassistant.components.fan import ( ATTR_PERCENTAGE, diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 6cf39709aaf..8a5705ae7bb 100644 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -1114,8 +1114,8 @@ class ZWaveDeviceEntityValues: """ if not check_node_schema(value.node, self._schema): return - for name in self._values: - if self._values[name] is not None: + for name, name_value in self._values.items(): + if name_value is not None: continue if not check_value_schema(value, self._schema[const.DISC_VALUES][name]): continue diff --git a/homeassistant/config.py b/homeassistant/config.py index c5f29f3c3c1..5a8f71bda77 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -899,7 +899,7 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> str | None: This method is a coroutine. """ # pylint: disable=import-outside-toplevel - import homeassistant.helpers.check_config as check_config + from homeassistant.helpers import check_config res = await check_config.async_check_ha_config_file(hass) diff --git a/homeassistant/core.py b/homeassistant/core.py index b9bf97e7e6c..0c2658952ce 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -201,7 +201,7 @@ class CoreState(enum.Enum): final_write = "FINAL_WRITE" stopped = "STOPPED" - def __str__(self) -> str: # pylint: disable=invalid-str-returned + def __str__(self) -> str: """Return the event.""" return self.value @@ -593,7 +593,7 @@ class EventOrigin(enum.Enum): local = "LOCAL" remote = "REMOTE" - def __str__(self) -> str: # pylint: disable=invalid-str-returned + def __str__(self) -> str: """Return the event.""" return self.value @@ -669,7 +669,7 @@ class EventBus: This method must be run in the event loop. """ - return {key: len(self._listeners[key]) for key in self._listeners} + return {key: len(listeners) for key, listeners in self._listeners.items()} @property def listeners(self) -> dict[str, int]: @@ -1298,7 +1298,7 @@ class ServiceRegistry: This method must be run in the event loop. """ - return {domain: self._services[domain].copy() for domain in self._services} + return {domain: service.copy() for domain, service in self._services.items()} def has_service(self, domain: str, service: str) -> bool: """Test if specified service exists. diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index 1fe542c096c..ab54d159f5e 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -977,10 +977,10 @@ class _TrackTemplateResultInfo: self._track_state_changes.async_update_listeners( _render_infos_to_track_states( [ - _suppress_domain_all_in_render_info(self._info[template]) + _suppress_domain_all_in_render_info(info) if self._rate_limit.async_has_timer(template) - else self._info[template] - for template in self._info + else info + for template, info in self._info.items() ] ) ) diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 06bf5045c9f..a535db4bde2 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -534,7 +534,7 @@ async def async_get_integration(hass: HomeAssistant, domain: str) -> Integration try: integration = await _async_get_integration(hass, domain) - except Exception: # pylint: disable=broad-except + except Exception: # Remove event from cache. cache.pop(domain) event.set() diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index f7f07434555..bf11103b3fa 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -161,9 +161,6 @@ def get_random_string(length: int = 10) -> str: class OrderedEnum(enum.Enum): """Taken from Python 3.4.0 docs.""" - # https://github.com/PyCQA/pylint/issues/2306 - # pylint: disable=comparison-with-callable - def __ge__(self, other: ENUM_T) -> bool: """Return the greater than element.""" if self.__class__ is other.__class__: diff --git a/homeassistant/util/dt.py b/homeassistant/util/dt.py index a9a6ca4e3a3..93737ce0c3d 100644 --- a/homeassistant/util/dt.py +++ b/homeassistant/util/dt.py @@ -13,9 +13,9 @@ import ciso8601 from homeassistant.const import MATCH_ALL if sys.version_info[:2] >= (3, 9): - import zoneinfo # pylint: disable=import-error + import zoneinfo else: - from backports import zoneinfo # pylint: disable=import-error + from backports import zoneinfo DATE_STR_FORMAT = "%Y-%m-%d" UTC = dt.timezone.utc diff --git a/requirements_test.txt b/requirements_test.txt index 660ea2a11fd..8b6ab238037 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -10,7 +10,7 @@ jsonpickle==1.4.1 mock-open==1.4.0 mypy==0.902 pre-commit==2.13.0 -pylint==2.8.3 +pylint==2.9.3 pipdeptree==1.0.0 pylint-strict-informational==0.1 pytest-aiohttp==0.3.0