Skip to content

Commit

Permalink
Enable mccabe complexity checks in flake8 (home-assistant#49616)
Browse files Browse the repository at this point in the history
Co-authored-by: Franck Nijhof <git@frenck.dev>
  • Loading branch information
bdraco and frenck authored Apr 25, 2021
1 parent 9f8e683 commit 3fa8ffa
Show file tree
Hide file tree
Showing 42 changed files with 51 additions and 40 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
)


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 = {}
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/buienradar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def data_updated(self, data):
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def activate_on_start(_):
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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/emulated_hue/hue_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def __init__(self, config):
"""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)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/glances/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def will_remove_from_hass(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hdmi_cec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
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):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/homekit/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
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(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/huawei_lte/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _already_configured(self, user_input: dict[str, Any]) -> bool:
}
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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/influxdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/isy994/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def valid_isy_commands(value: Any) -> str:


@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(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def _setup_from_config(self, config):
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]
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/mqtt/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _setup_from_config(self, config):
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 = {}

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/mqtt/light/schema_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def _setup_from_config(self, config):
)
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 = {}

Expand Down Expand Up @@ -579,7 +579,7 @@ def supported_features(self):

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.
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/light/schema_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def _scale_rgbxx(self, rgbxx, kwargs):
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.
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/light/schema_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _setup_from_config(self, config):
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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/netatmo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def entity_registry_enabled_default(self) -> bool:
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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/ozw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
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] = {}
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/plex/media_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class UnknownMediaType(BrowseError):
_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):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/plex/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def _fetch_platform_data(self):
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")

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/simplisafe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sonos/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __init__(self) -> None:
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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/spotify/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ async def async_browse_media(self, media_content_type=None, media_content_id=Non
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"]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/stream/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def close(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/synology_dsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/systemmonitor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async def async_added_to_hass(self) -> None:
)


def _update(
def _update( # noqa: C901
type_: str, data: SensorData
) -> tuple[str | None, str | None, datetime.datetime | None]:
"""Get the latest system information."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/wink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def wink_configuration_callback(callback_data):
)


def setup(hass, config):
def setup(hass, config): # noqa: C901
"""Set up the Wink component."""

if hass.data.get(DOMAIN) is None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/xmpp/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def async_send_message(self, message="", **kwargs):
)


async def async_send_message(
async def async_send_message( # noqa: C901
sender,
password,
recipients,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/zwave_js/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/helpers/check_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def error_str(self) -> str:
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.
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/entity_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ async def async_add_entities(
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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/update_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def async_refresh(self) -> None:
"""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,
Expand Down
1 change: 1 addition & 0 deletions requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/august/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3fa8ffa

Please sign in to comment.