Skip to content
Permalink
Browse files
Disable no-self-use [pylint] (#70641)
* Disable no-self-use

* Remove disable comments
  • Loading branch information
cdce8p committed Apr 25, 2022
1 parent 9dcbc84 commit 9b9b553521cef6138ce07c74b27f2d08d9f117ae
Showing 49 changed files with 14 additions and 64 deletions.
@@ -147,9 +147,7 @@ def validate_login(self, username: str, password: str) -> None:
if not bcrypt.checkpw(password.encode(), user_hash):
raise InvalidAuth

def hash_password( # pylint: disable=no-self-use
self, password: str, for_storage: bool = False
) -> bytes:
def hash_password(self, password: str, for_storage: bool = False) -> bytes:
"""Encode a password."""
hashed: bytes = bcrypt.hashpw(password.encode(), bcrypt.gensalt(rounds=12))

@@ -73,8 +73,6 @@ class AlexaCapability:
https://developer.amazon.com/docs/device-apis/message-guide.html
"""

# pylint: disable=no-self-use

supported_locales = {"en-US"}

def __init__(self, entity: State, instance: str | None = None) -> None:
@@ -84,7 +84,6 @@ async def async_disable_proactive_mode(self):
@callback
def should_expose(self, entity_id):
"""If an entity should be exposed."""
# pylint: disable=no-self-use
return False

@callback
@@ -200,8 +200,6 @@ class AlexaCapabilityResource:
https://developer.amazon.com/docs/device-apis/resources-and-assets.html#capability-resources
"""

# pylint: disable=no-self-use

def __init__(self, labels):
"""Initialize an Alexa resource."""
self._resource_labels = []
@@ -140,7 +140,6 @@ class AmbiclimateAuthCallbackView(HomeAssistantView):

async def get(self, request: web.Request) -> str:
"""Receive authorization token."""
# pylint: disable=no-self-use
if (code := request.query.get("code")) is None:
return "No code"
hass = request.app["hass"]
@@ -89,7 +89,6 @@ class APIEventStream(HomeAssistantView):

async def get(self, request):
"""Provide a streaming interface for the event bus."""
# pylint: disable=no-self-use
if not request["hass_user"].is_admin:
raise Unauthorized()
hass = request.app["hass"]
@@ -379,7 +378,6 @@ class APIErrorLog(HomeAssistantView):

async def get(self, request):
"""Retrieve API error log."""
# pylint: disable=no-self-use
if not request["hass_user"].is_admin:
raise Unauthorized()
return web.FileResponse(request.app["hass"].data[DATA_LOGGING])
@@ -271,7 +271,6 @@ async def post(self, request):

async def _async_handle_revoke_token(self, hass, data):
"""Handle revoke token request."""
# pylint: disable=no-self-use

# OAuth 2.0 Token Revocation [RFC7009]
# 2.2 The authorization server responds with HTTP status code 200
@@ -198,7 +198,6 @@ class LoginFlowIndexView(LoginFlowBaseView):

async def get(self, request):
"""Do not allow index of flows in progress."""
# pylint: disable=no-self-use
return web.Response(status=HTTPStatus.METHOD_NOT_ALLOWED)

@RequestDataValidator(
@@ -76,7 +76,6 @@ async def _async_update_data(self) -> Any | None:

async def _fetch_air_data(self, device):
"""Fetch latest air quality data."""
# pylint: disable=no-self-use
LOGGER.debug("Fetching data for %s", device.uuid)
air_data = await device.air_data_latest()
LOGGER.debug(air_data)
@@ -26,7 +26,7 @@ class DownloadBackupView(HomeAssistantView):
url = "/api/backup/download/{slug}"
name = "api:backup:download"

async def get( # pylint: disable=no-self-use
async def get(
self,
request: Request,
slug: str,
@@ -549,7 +549,6 @@ async def stream_source(self) -> str | None:
This is used by cameras with CameraEntityFeature.STREAM
and StreamType.HLS.
"""
# pylint: disable=no-self-use
return None

async def async_handle_web_rtc_offer(self, offer_sdp: str) -> str | None:
@@ -160,7 +160,6 @@ class ConfigManagerFlowIndexView(FlowManagerIndexView):

async def get(self, request):
"""Not implemented."""
# pylint: disable=no-self-use
raise aiohttp.web_exceptions.HTTPMethodNotAllowed("GET", ["POST"])

# pylint: disable=arguments-differ
@@ -17,12 +17,10 @@ def attribution(self):

async def async_get_onboarding(self):
"""Get onboard data."""
# pylint: disable=no-self-use
return None

async def async_set_onboarding(self, shown):
"""Set onboard data."""
# pylint: disable=no-self-use
return True

@abstractmethod
@@ -180,7 +180,7 @@ class DownloadDiagnosticsView(http.HomeAssistantView):
extra_urls = ["/api/diagnostics/{d_type}/{d_id}/{sub_type}/{sub_id}"]
name = "api:diagnostics"

async def get( # pylint: disable=no-self-use
async def get(
self,
request: web.Request,
d_type: str,
@@ -336,7 +336,6 @@ class DoorBirdRequestView(HomeAssistantView):

async def get(self, request, event):
"""Respond to requests from the device."""
# pylint: disable=no-self-use
hass = request.app["hass"]

token = request.query.get("token")
@@ -127,7 +127,7 @@ def datagram_received(self, data, addr):
_LOGGER.debug("UPNP Responder responding with: %s", response)
self.transport.sendto(response, addr)

def error_received(self, exc): # pylint: disable=no-self-use
def error_received(self, exc):
"""Log UPNP errors."""
_LOGGER.error("UPNP Error received: %s", exc)

@@ -611,7 +611,7 @@ class ManifestJSONView(HomeAssistantView):
name = "manifestjson"

@callback
def get(self, request: web.Request) -> web.Response: # pylint: disable=no-self-use
def get(self, request: web.Request) -> web.Response:
"""Return the manifest.json."""
return web.Response(
text=MANIFEST_JSON.json, content_type="application/manifest+json"
@@ -167,7 +167,6 @@ def should_expose(self, state) -> bool:

def should_2fa(self, state):
"""If an entity should have 2FA checked."""
# pylint: disable=no-self-use
return True

async def async_report_state(self, message, agent_user_id: str):
@@ -1004,7 +1004,6 @@ class HomeKitPairingQRView(HomeAssistantView):

async def get(self, request: web.Request) -> web.Response:
"""Retrieve the pairing QRCode image."""
# pylint: disable=no-self-use
if not request.query_string:
raise Unauthorized()
entry_id, secret = request.query_string.split("-")
@@ -60,7 +60,6 @@ async def async_register(self):

async def get_auth(self, hass: HomeAssistant, hapid, pin):
"""Create a HomematicIP access point object."""
# pylint: disable=no-self-use
auth = AsyncAuth(hass.loop, async_get_clientsession(hass))
try:
await auth.init(hapid)
@@ -69,7 +69,6 @@ async def _validate_input(self, user_input):
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
# pylint: disable=no-self-use
username = user_input[CONF_USERNAME]
password = user_input[CONF_PASSWORD]

@@ -485,7 +485,6 @@ def _get_priority_entry_that_dictates_state(self) -> dict[str, Any] | None:
priority: dict[str, Any] | None = self._client.visible_priority
return priority

# pylint: disable=no-self-use
def _allow_priority_update(self, priority: dict[str, Any] | None = None) -> bool:
"""Determine whether to allow a priority to update internal state."""
return True
@@ -69,12 +69,10 @@ async def async_load(self, force):

async def async_save(self, config):
"""Save config."""
# pylint: disable=no-self-use
raise HomeAssistantError("Not supported")

async def async_delete(self):
"""Delete config."""
# pylint: disable=no-self-use
raise HomeAssistantError("Not supported")

@callback
@@ -540,7 +540,6 @@ async def async_get_browse_image(
Must be implemented by integration.
"""
# pylint: disable=no-self-use
return None, None

@property
@@ -301,9 +301,7 @@ async def post(self, request: web.Request) -> web.Response:
{"media_content_id": f"{data['media_content_id']}/{uploaded_file.filename}"}
)

def _move_file( # pylint: disable=no-self-use
self, target_dir: Path, uploaded_file: FileField
) -> None:
def _move_file(self, target_dir: Path, uploaded_file: FileField) -> None:
"""Move file to target."""
if not target_dir.is_dir():
raise ValueError("Target is not an existing directory")
@@ -168,7 +168,6 @@ def prepare_gpio(event):
return True


# pylint: disable=no-self-use
class NumatoAPI:
"""Home-Assistant specific API for numato device access."""

@@ -420,7 +420,6 @@ class PlexAuthorizationCallbackView(HomeAssistantView):

async def get(self, request):
"""Receive authorization confirmation."""
# pylint: disable=no-self-use
hass = request.app["hass"]
await hass.config_entries.flow.async_configure(
flow_id=request.query["flow_id"], user_input=None
@@ -22,7 +22,7 @@ class PlexImageView(HomeAssistantView):
name = "api:plex:image"
url = "/api/plex_image_proxy/{server_id}/{media_content_id}"

async def get( # pylint: disable=no-self-use
async def get(
self,
request: web.Request,
server_id: str,
@@ -236,7 +236,6 @@ def __init__(self, _getattr_):

def _call_print(self, *objects, **kwargs):
"""Print text."""
# pylint: disable=no-self-use
_LOGGER.warning("Don't use print() inside scripts. Use logger.info() instead")


@@ -246,7 +245,6 @@ class TimeWrapper:
# Class variable, only going to warn once per Home Assistant run
warned = False

# pylint: disable=no-self-use
def sleep(self, *args, **kwargs):
"""Sleep method that warns once."""
if not TimeWrapper.warned:
@@ -124,7 +124,7 @@ async def async_added_to_hass(self):
"""Register callback function."""
self.vacuum.register_on_message_callback(self.on_message)

def new_state_filter(self, new_state): # pylint: disable=no-self-use
def new_state_filter(self, new_state):
"""Filter out wifi state messages."""
return len(new_state) > 1 or "signal" not in new_state

@@ -94,7 +94,6 @@ async def async_update_data(self):
return data

async def _get_spa_data(self, spa):
# pylint: disable=no-self-use
full_status, reminders, errors = await asyncio.gather(
spa.get_status_full(),
spa.get_reminders(),
@@ -73,7 +73,6 @@ def sms_read_messages(self, state_machine, force=False):

self._hass.add_job(self._notify_incoming_sms, data)

# pylint: disable=no-self-use
def get_and_delete_all_sms(self, state_machine, force=False):
"""Read and delete all SMS in the modem."""
# Read SMS memory status ...
@@ -145,7 +145,6 @@ class WebhookView(HomeAssistantView):

async def _handle(self, request: Request, webhook_id: str) -> Response:
"""Handle webhook call."""
# pylint: disable=no-self-use
_LOGGER.debug("Handling webhook %s payload for %s", request.method, webhook_id)
hass = request.app["hass"]
return await async_handle_webhook(hass, webhook_id, request)
@@ -42,7 +42,6 @@ class WebsocketAPIView(HomeAssistantView):

async def get(self, request: web.Request) -> web.WebSocketResponse:
"""Handle an incoming websocket connection."""
# pylint: disable=no-self-use
return await WebSocketHandler(request.app["hass"], request).async_handle()


@@ -186,7 +186,6 @@ def updated_state_value(self):
"""
return self.decorate_value(self.principal_value)

# pylint: disable=no-self-use
def decorate_value(self, value):
"""Decorate input value to be well presented for end user."""
return f"{value:.1f}"
@@ -641,7 +641,6 @@ async def _do_retry(self, func, attempts=3) -> Any:
Withings' API occasionally and incorrectly throws errors. Retrying the call tends to work.
"""
# pylint: disable=no-self-use
exception = None
for attempt in range(1, attempts + 1):
_LOGGER.debug("Attempt %s of %s", attempt, attempts)
@@ -347,7 +347,6 @@ def send_text_message(self):
except NotConnectedError as ex:
_LOGGER.error("Connection error %s", ex)

# pylint: disable=no-self-use
def get_random_filename(self, filename, extension=None):
"""Return a random filename, leaving the extension intact."""
if extension is None: