Enable mccabe complexity checks in flake8 (#49616)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
J. Nick Koston 2021-04-25 00:38:40 -10:00 committed by GitHub
parent 9f8e683ae3
commit 3fa8ffa731
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 51 additions and 40 deletions

View file

@ -33,6 +33,7 @@ repos:
- pydocstyle==6.0.0
- flake8-comprehensions==3.4.0
- flake8-noqa==1.1.0
- mccabe==0.6.1
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.0

View file

@ -46,7 +46,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
def setup_scanner(hass, config, see, discovery_info=None):
def setup_scanner(hass, config, see, discovery_info=None): # noqa: C901
"""Set up the Bluetooth LE Scanner."""
new_devices = {}

View file

@ -271,7 +271,7 @@ class BrSensor(SensorEntity):
self.async_write_ha_state()
@callback
def _load_data(self, data):
def _load_data(self, data): # noqa: C901
"""Load the sensor with relevant data."""
# Find sensor

View file

@ -80,7 +80,7 @@ async def async_setup(hass, config):
return True
async def activate_automation(
async def activate_automation( # noqa: C901
hass, device_group, light_group, light_profile, disable_turn_off
):
"""Activate the automation."""

View file

@ -322,7 +322,7 @@ class HueOneLightChangeView(HomeAssistantView):
"""Initialize the instance of the view."""
self.config = config
async def put(self, request, username, entity_number):
async def put(self, request, username, entity_number): # noqa: C901
"""Process a request to set the state of an individual light."""
if not is_local(ip_address(request.remote)):
return self.json_message("Only local IPs allowed", HTTP_UNAUTHORIZED)

View file

@ -132,7 +132,7 @@ class GlancesSensor(SensorEntity):
self.unsub_update()
self.unsub_update = None
async def async_update(self):
async def async_update(self): # noqa: C901
"""Get the latest data from REST API."""
value = self.glances_data.api.data
if value is None:

View file

@ -336,7 +336,7 @@ def get_supervisor_ip():
return os.environ["SUPERVISOR"].partition(":")[0]
async def async_setup(hass: HomeAssistant, config: Config) -> bool:
async def async_setup(hass: HomeAssistant, config: Config) -> bool: # noqa: C901
"""Set up the Hass.io component."""
# Check local setup
for env in ("HASSIO", "HASSIO_TOKEN"):

View file

@ -187,7 +187,7 @@ def parse_mapping(mapping, parents=None):
yield (val, pad_physical_address(cur))
def setup(hass: HomeAssistant, base_config):
def setup(hass: HomeAssistant, base_config): # noqa: C901
"""Set up the CEC capability."""
# Parse configuration into a dict of device name to physical address

View file

@ -50,7 +50,7 @@ SCHEMA_RELOAD_CONFIG_ENTRY = vol.All(
SHUTDOWN_SERVICES = (SERVICE_HOMEASSISTANT_STOP, SERVICE_HOMEASSISTANT_RESTART)
async def async_setup(hass: ha.HomeAssistant, config: dict) -> bool:
async def async_setup(hass: ha.HomeAssistant, config: dict) -> bool: # noqa: C901
"""Set up general services related to Home Assistant."""
async def async_handle_turn_service(service):

View file

@ -92,7 +92,7 @@ SWITCH_TYPES = {
TYPES = Registry()
def get_accessory(hass, driver, state, aid, config):
def get_accessory(hass, driver, state, aid, config): # noqa: C901
"""Take state and return an accessory object if supported."""
if not aid:
_LOGGER.warning(

View file

@ -101,7 +101,7 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
}
return user_input[CONF_URL] in existing_urls
async def async_step_user(
async def async_step_user( # noqa: C901
self, user_input: dict[str, Any] | None = None
) -> FlowResultDict:
"""Handle user initiated config flow."""

View file

@ -326,7 +326,7 @@ class InfluxClient:
close: Callable[[], None]
def get_influx_connection(conf, test_write=False, test_read=False):
def get_influx_connection(conf, test_write=False, test_read=False): # noqa: C901
"""Create the correct influx connection for the API version."""
kwargs = {
CONF_TIMEOUT: TIMEOUT,

View file

@ -157,7 +157,7 @@ SERVICE_RUN_NETWORK_RESOURCE_SCHEMA = vol.All(
@callback
def async_setup_services(hass: HomeAssistant):
def async_setup_services(hass: HomeAssistant): # noqa: C901
"""Create and register services for the ISY integration."""
existing_services = hass.services.async_services().get(DOMAIN)
if existing_services and any(

View file

@ -242,7 +242,7 @@ def filter_turn_off_params(params):
return {k: v for k, v in params.items() if k in (ATTR_TRANSITION, ATTR_FLASH)}
async def async_setup(hass, config):
async def async_setup(hass, config): # noqa: C901
"""Expose light control via state machine and services."""
component = hass.data[DOMAIN] = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL

View file

@ -359,7 +359,7 @@ class MqttClimate(MqttEntity, ClimateEntity):
tpl.hass = self.hass
self._command_templates = command_templates
async def _subscribe_topics(self):
async def _subscribe_topics(self): # noqa: C901
"""(Re)Subscribe to topics."""
topics = {}
qos = self._config[CONF_QOS]

View file

@ -79,7 +79,9 @@ class MQTTConfig(dict):
"""Dummy class to allow adding attributes."""
async def async_start(hass: HomeAssistant, discovery_topic, config_entry=None) -> bool:
async def async_start( # noqa: C901
hass: HomeAssistant, discovery_topic, config_entry=None
) -> bool:
"""Start MQTT Discovery."""
mqtt_integrations = {}

View file

@ -335,7 +335,7 @@ class MqttFan(MqttEntity, FanEntity):
tpl.hass = self.hass
tpl_dict[key] = tpl.async_render_with_possible_json_value
async def _subscribe_topics(self):
async def _subscribe_topics(self): # noqa: C901
"""(Re)Subscribe to topics."""
topics = {}

View file

@ -250,7 +250,7 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
)
self._optimistic_xy = optimistic or topic[CONF_XY_STATE_TOPIC] is None
async def _subscribe_topics(self):
async def _subscribe_topics(self): # noqa: C901
"""(Re)Subscribe to topics."""
topics = {}
@ -579,7 +579,7 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
return supported_features
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs): # noqa: C901
"""Turn the device on.
This method is a coroutine.

View file

@ -487,7 +487,7 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
def _supports_color_mode(self, color_mode):
return self.supported_color_modes and color_mode in self.supported_color_modes
async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs): # noqa: C901
"""Turn the device on.
This method is a coroutine.

View file

@ -142,7 +142,7 @@ class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
or self._templates[CONF_STATE_TEMPLATE] is None
)
async def _subscribe_topics(self):
async def _subscribe_topics(self): # noqa: C901
"""(Re)Subscribe to topics."""
for tpl in self._templates.values():
if tpl is not None:

View file

@ -333,7 +333,7 @@ class NetatmoSensor(NetatmoBase, SensorEntity):
return self._enabled_default
@callback
def async_update_callback(self):
def async_update_callback(self): # noqa: C901
"""Update the entity's state."""
if self._data is None:
if self._state is None:

View file

@ -56,7 +56,7 @@ DATA_DEVICES = "zwave-mqtt-devices"
DATA_STOP_MQTT_CLIENT = "ozw_stop_mqtt_client"
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): # noqa: C901
"""Set up ozw from a config entry."""
hass.data.setdefault(DOMAIN, {})
ozw_data = hass.data[DOMAIN][entry.entry_id] = {}

View file

@ -52,7 +52,9 @@ ITEM_TYPE_MEDIA_CLASS = {
_LOGGER = logging.getLogger(__name__)
def browse_media(entity, is_internal, media_content_type=None, media_content_id=None):
def browse_media( # noqa: C901
entity, is_internal, media_content_type=None, media_content_id=None
):
"""Implement the websocket media browsing helper."""
def item_payload(item):

View file

@ -316,7 +316,7 @@ class PlexServer:
self.plextv_clients(),
)
async def _async_update_platforms(self):
async def _async_update_platforms(self): # noqa: C901
"""Update the platform entities."""
_LOGGER.debug("Updating devices")

View file

@ -181,7 +181,7 @@ async def async_setup(hass, config):
return True
async def async_setup_entry(hass, config_entry):
async def async_setup_entry(hass, config_entry): # noqa: C901
"""Set up SimpliSafe as config entry."""
hass.data[DOMAIN][DATA_LISTENER][config_entry.entry_id] = []

View file

@ -158,7 +158,7 @@ class SonosData:
self.hosts_heartbeat = None
async def async_setup_entry(
async def async_setup_entry( # noqa: C901
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable
) -> None:
"""Set up Sonos from a config entry."""

View file

@ -533,7 +533,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
return response
def build_item_response(spotify, user, payload):
def build_item_response(spotify, user, payload): # noqa: C901
"""Create response payload for the provided media query."""
media_content_type = payload["media_content_type"]
media_content_id = payload["media_content_id"]

View file

@ -122,7 +122,7 @@ class SegmentBuffer:
self._stream_buffer.output.close()
def stream_worker(source, options, segment_buffer, quit_event):
def stream_worker(source, options, segment_buffer, quit_event): # noqa: C901
"""Handle consuming streams."""
try:

View file

@ -118,7 +118,7 @@ async def async_setup(hass, config):
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): # noqa: C901
"""Set up Synology DSM sensors."""
# Migrate old unique_id

View file

@ -365,7 +365,7 @@ class SystemMonitorSensor(SensorEntity):
)
def _update(
def _update( # noqa: C901
type_: str, data: SensorData
) -> tuple[str | None, str | None, datetime.datetime | None]:
"""Get the latest system information."""

View file

@ -280,7 +280,7 @@ def _request_oauth_completion(hass, config):
)
def setup(hass, config):
def setup(hass, config): # noqa: C901
"""Set up the Wink component."""
if hass.data.get(DOMAIN) is None:

View file

@ -113,7 +113,7 @@ class XmppNotificationService(BaseNotificationService):
)
async def async_send_message(
async def async_send_message( # noqa: C901
sender,
password,
recipients,

View file

@ -392,7 +392,7 @@ async def async_setup(hass, config):
return True
async def async_setup_entry(hass, config_entry):
async def async_setup_entry(hass, config_entry): # noqa: C901
"""Set up Z-Wave from a config entry.
Will automatically load components to support devices found on the network.

View file

@ -108,7 +108,9 @@ def register_node_in_dev_reg(
return device
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry( # noqa: C901
hass: HomeAssistant, entry: ConfigEntry
) -> bool:
"""Set up Z-Wave JS from a config entry."""
use_addon = entry.data.get(CONF_USE_ADDON)
if use_addon:

View file

@ -755,7 +755,7 @@ async def merge_packages_config(
return config
async def async_process_component_config(
async def async_process_component_config( # noqa: C901
hass: HomeAssistant, config: ConfigType, integration: Integration
) -> ConfigType | None:
"""Check component configuration and return processed configuration.

View file

@ -63,7 +63,9 @@ class HomeAssistantConfig(OrderedDict):
return "\n".join([err.message for err in self.errors])
async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig:
async def async_check_ha_config_file( # noqa: C901
hass: HomeAssistant,
) -> HomeAssistantConfig:
"""Load and check if Home Assistant configuration file is valid.
This method is a coroutine.

View file

@ -301,7 +301,7 @@ def numeric_state(
).result()
def async_numeric_state(
def async_numeric_state( # noqa: C901
hass: HomeAssistant,
entity: None | str | State,
below: float | str | None = None,

View file

@ -388,7 +388,7 @@ class EntityPlatform:
self.scan_interval,
)
async def _async_add_entity( # type: ignore[no-untyped-def]
async def _async_add_entity( # type: ignore[no-untyped-def] # noqa: C901
self, entity, update_before_add, entity_registry, device_registry
):
"""Add an entity to the platform."""

View file

@ -157,7 +157,7 @@ class DataUpdateCoordinator(Generic[T]):
"""Refresh data and log errors."""
await self._async_refresh(log_failures=True)
async def _async_refresh(
async def _async_refresh( # noqa: C901
self,
log_failures: bool = True,
raise_on_auth_failed: bool = False,

View file

@ -8,6 +8,7 @@ flake8-docstrings==1.6.0
flake8-noqa==1.1.0
flake8==3.9.1
isort==5.8.0
mccabe==0.6.1
pycodestyle==2.7.0
pydocstyle==6.0.0
pyflakes==2.3.1

View file

@ -17,6 +17,7 @@ classifier =
[flake8]
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
max-complexity = 25
doctests = True
# To work with Black
# E501: line too long

View file

@ -77,7 +77,7 @@ async def _mock_setup_august(
return entry
async def _create_august_with_devices(
async def _create_august_with_devices( # noqa: C901
hass, devices, api_call_side_effects=None, activities=None, pubnub=None
):
if api_call_side_effects is None: