Add ruff rules PIE790, PIE794, PIE807, PIE810 (#113617)
This commit is contained in:
parent
cbe2a5883b
commit
0b9c9aff62
25 changed files with 29 additions and 47 deletions
|
@ -50,7 +50,6 @@ async def async_setup_intents(hass: HomeAssistant) -> None:
|
||||||
Right now this module does not expose any, but the intent component breaks
|
Right now this module does not expose any, but the intent component breaks
|
||||||
without it.
|
without it.
|
||||||
"""
|
"""
|
||||||
pass # pylint: disable=unnecessary-pass
|
|
||||||
|
|
||||||
|
|
||||||
class UnknownRequest(HomeAssistantError):
|
class UnknownRequest(HomeAssistantError):
|
||||||
|
|
|
@ -774,13 +774,7 @@ class BrSensor(SensorEntity):
|
||||||
self._measured = data.get(MEASURED)
|
self._measured = data.get(MEASURED)
|
||||||
sensor_type = self.entity_description.key
|
sensor_type = self.entity_description.key
|
||||||
|
|
||||||
if (
|
if sensor_type.endswith(("_1d", "_2d", "_3d", "_4d", "_5d")):
|
||||||
sensor_type.endswith("_1d")
|
|
||||||
or sensor_type.endswith("_2d")
|
|
||||||
or sensor_type.endswith("_3d")
|
|
||||||
or sensor_type.endswith("_4d")
|
|
||||||
or sensor_type.endswith("_5d")
|
|
||||||
):
|
|
||||||
# update forecasting sensors:
|
# update forecasting sensors:
|
||||||
fcday = 0
|
fcday = 0
|
||||||
if sensor_type.endswith("_2d"):
|
if sensor_type.endswith("_2d"):
|
||||||
|
@ -793,7 +787,7 @@ class BrSensor(SensorEntity):
|
||||||
fcday = 4
|
fcday = 4
|
||||||
|
|
||||||
# update weather symbol & status text
|
# update weather symbol & status text
|
||||||
if sensor_type.startswith(SYMBOL) or sensor_type.startswith(CONDITION):
|
if sensor_type.startswith((SYMBOL, CONDITION)):
|
||||||
try:
|
try:
|
||||||
condition = data.get(FORECAST)[fcday].get(CONDITION)
|
condition = data.get(FORECAST)[fcday].get(CONDITION)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|
|
@ -360,7 +360,7 @@ async def parse_pls(hass, url):
|
||||||
|
|
||||||
async def parse_playlist(hass, url):
|
async def parse_playlist(hass, url):
|
||||||
"""Parse an m3u or pls playlist."""
|
"""Parse an m3u or pls playlist."""
|
||||||
if url.endswith(".m3u") or url.endswith(".m3u8"):
|
if url.endswith((".m3u", ".m3u8")):
|
||||||
playlist = await parse_m3u(hass, url)
|
playlist = await parse_m3u(hass, url)
|
||||||
else:
|
else:
|
||||||
playlist = await parse_pls(hass, url)
|
playlist = await parse_pls(hass, url)
|
||||||
|
|
|
@ -685,11 +685,7 @@ class CastMediaPlayerEntity(CastDevice, MediaPlayerEntity):
|
||||||
"hlsVideoSegmentFormat": "fmp4",
|
"hlsVideoSegmentFormat": "fmp4",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
elif (
|
elif media_id.endswith((".m3u", ".m3u8", ".pls")):
|
||||||
media_id.endswith(".m3u")
|
|
||||||
or media_id.endswith(".m3u8")
|
|
||||||
or media_id.endswith(".pls")
|
|
||||||
):
|
|
||||||
try:
|
try:
|
||||||
playlist = await parse_playlist(self.hass, media_id)
|
playlist = await parse_playlist(self.hass, media_id)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
|
|
|
@ -43,7 +43,7 @@ class DiscovergySensorEntityDescription(SensorEntityDescription):
|
||||||
value_fn: Callable[[Reading, str, int], datetime | float | None] = field(
|
value_fn: Callable[[Reading, str, int], datetime | float | None] = field(
|
||||||
default=_get_and_scale
|
default=_get_and_scale
|
||||||
)
|
)
|
||||||
alternative_keys: list[str] = field(default_factory=lambda: [])
|
alternative_keys: list[str] = field(default_factory=list)
|
||||||
scale: int = field(default_factory=lambda: 1000)
|
scale: int = field(default_factory=lambda: 1000)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ async def validate_input(data: dict[str, str], mac: str | None) -> dict[str, str
|
||||||
|
|
||||||
prefix = data[CONF_PREFIX]
|
prefix = data[CONF_PREFIX]
|
||||||
url = _make_url_from_data(data)
|
url = _make_url_from_data(data)
|
||||||
requires_password = url.startswith("elks://") or url.startswith("elksv1_2")
|
requires_password = url.startswith(("elks://", "elksv1_2"))
|
||||||
|
|
||||||
if requires_password and (not userid or not password):
|
if requires_password and (not userid or not password):
|
||||||
raise InvalidAuth
|
raise InvalidAuth
|
||||||
|
|
|
@ -73,7 +73,7 @@ async def _update_google_domains(hass, session, domain, user, password, timeout)
|
||||||
resp = await session.get(url, params=params)
|
resp = await session.get(url, params=params)
|
||||||
body = await resp.text()
|
body = await resp.text()
|
||||||
|
|
||||||
if body.startswith("good") or body.startswith("nochg"):
|
if body.startswith(("good", "nochg")):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
_LOGGER.warning("Updating Google Domains failed: %s => %s", domain, body)
|
_LOGGER.warning("Updating Google Domains failed: %s => %s", domain, body)
|
||||||
|
|
|
@ -40,7 +40,7 @@ class HassAqualinkSwitch(AqualinkEntity, SwitchEntity):
|
||||||
self._attr_icon = "mdi:robot-vacuum"
|
self._attr_icon = "mdi:robot-vacuum"
|
||||||
elif name == "Waterfall" or name.endswith("Dscnt"):
|
elif name == "Waterfall" or name.endswith("Dscnt"):
|
||||||
self._attr_icon = "mdi:fountain"
|
self._attr_icon = "mdi:fountain"
|
||||||
elif name.endswith("Pump") or name.endswith("Blower"):
|
elif name.endswith(("Pump", "Blower")):
|
||||||
self._attr_icon = "mdi:fan"
|
self._attr_icon = "mdi:fan"
|
||||||
if name.endswith("Heater"):
|
if name.endswith("Heater"):
|
||||||
self._attr_icon = "mdi:radiator"
|
self._attr_icon = "mdi:radiator"
|
||||||
|
|
|
@ -213,7 +213,7 @@ class Isy994ConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a discovered ISY/IoX device via dhcp."""
|
"""Handle a discovered ISY/IoX device via dhcp."""
|
||||||
friendly_name = discovery_info.hostname
|
friendly_name = discovery_info.hostname
|
||||||
if friendly_name.startswith("polisy") or friendly_name.startswith("eisy"):
|
if friendly_name.startswith(("polisy", "eisy")):
|
||||||
url = f"http://{discovery_info.ip}:8080"
|
url = f"http://{discovery_info.ip}:8080"
|
||||||
else:
|
else:
|
||||||
url = f"http://{discovery_info.ip}"
|
url = f"http://{discovery_info.ip}"
|
||||||
|
|
|
@ -60,7 +60,7 @@ async def async_get_service(
|
||||||
port: int = config[CONF_PORT]
|
port: int = config[CONF_PORT]
|
||||||
encryption = config.get(CONF_PROXY_SSL)
|
encryption = config.get(CONF_PROXY_SSL)
|
||||||
|
|
||||||
if host.startswith("http://") or host.startswith("https://"):
|
if host.startswith(("http://", "https://")):
|
||||||
host = host[host.index("://") + 3 :]
|
host = host[host.index("://") + 3 :]
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Kodi host name should no longer contain http:// See updated "
|
"Kodi host name should no longer contain http:// See updated "
|
||||||
|
|
|
@ -104,7 +104,7 @@ async def _update_no_ip(
|
||||||
resp = await session.get(url, params=params, headers=headers)
|
resp = await session.get(url, params=params, headers=headers)
|
||||||
body = await resp.text()
|
body = await resp.text()
|
||||||
|
|
||||||
if body.startswith("good") or body.startswith("nochg"):
|
if body.startswith(("good", "nochg")):
|
||||||
_LOGGER.debug("Updating NO-IP success: %s", domain)
|
_LOGGER.debug("Updating NO-IP success: %s", domain)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ def get_preferred_location(locations: set[str]) -> str:
|
||||||
"""Get the preferred location (an IPv4 location) from a set of locations."""
|
"""Get the preferred location (an IPv4 location) from a set of locations."""
|
||||||
# Prefer IPv4 over IPv6.
|
# Prefer IPv4 over IPv6.
|
||||||
for location in locations:
|
for location in locations:
|
||||||
if location.startswith("http://[") or location.startswith("https://["):
|
if location.startswith(("http://[", "https://[")):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return location
|
return location
|
||||||
|
|
|
@ -19,7 +19,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up UptimeRobot from a config entry."""
|
"""Set up UptimeRobot from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
key: str = entry.data[CONF_API_KEY]
|
key: str = entry.data[CONF_API_KEY]
|
||||||
if key.startswith("ur") or key.startswith("m"):
|
if key.startswith(("ur", "m")):
|
||||||
raise ConfigEntryAuthFailed(
|
raise ConfigEntryAuthFailed(
|
||||||
"Wrong API key type detected, use the 'main' API key"
|
"Wrong API key type detected, use the 'main' API key"
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class UptimeRobotConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
response: UptimeRobotApiResponse | UptimeRobotApiError | None = None
|
response: UptimeRobotApiResponse | UptimeRobotApiError | None = None
|
||||||
key: str = data[CONF_API_KEY]
|
key: str = data[CONF_API_KEY]
|
||||||
if key.startswith("ur") or key.startswith("m"):
|
if key.startswith(("ur", "m")):
|
||||||
LOGGER.error("Wrong API key type detected, use the 'main' API key")
|
LOGGER.error("Wrong API key type detected, use the 'main' API key")
|
||||||
errors["base"] = "not_main_key"
|
errors["base"] = "not_main_key"
|
||||||
return errors, None
|
return errors, None
|
||||||
|
|
|
@ -210,7 +210,6 @@ class WebhookView(HomeAssistantView):
|
||||||
head = _handle
|
head = _handle
|
||||||
post = _handle
|
post = _handle
|
||||||
put = _handle
|
put = _handle
|
||||||
get = _handle
|
|
||||||
|
|
||||||
|
|
||||||
@websocket_api.websocket_command(
|
@websocket_api.websocket_command(
|
||||||
|
|
|
@ -158,9 +158,7 @@ class XiaomiAqaraFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
return self.async_abort(reason="not_xiaomi_aqara")
|
return self.async_abort(reason="not_xiaomi_aqara")
|
||||||
|
|
||||||
# Check if the discovered device is an xiaomi aqara gateway.
|
# Check if the discovered device is an xiaomi aqara gateway.
|
||||||
if not (
|
if not (name.startswith((ZEROCONF_GATEWAY, ZEROCONF_ACPARTNER))):
|
||||||
name.startswith(ZEROCONF_GATEWAY) or name.startswith(ZEROCONF_ACPARTNER)
|
|
||||||
):
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
(
|
(
|
||||||
"Xiaomi device '%s' discovered with host %s, not identified as"
|
"Xiaomi device '%s' discovered with host %s, not identified as"
|
||||||
|
|
|
@ -340,10 +340,8 @@ async def async_create_miio_device_and_coordinator(
|
||||||
device = AirFreshA1(host, token, lazy_discover=lazy_discover)
|
device = AirFreshA1(host, token, lazy_discover=lazy_discover)
|
||||||
elif model == MODEL_AIRFRESH_T2017:
|
elif model == MODEL_AIRFRESH_T2017:
|
||||||
device = AirFreshT2017(host, token, lazy_discover=lazy_discover)
|
device = AirFreshT2017(host, token, lazy_discover=lazy_discover)
|
||||||
elif (
|
elif model in MODELS_VACUUM or model.startswith(
|
||||||
model in MODELS_VACUUM
|
(ROBOROCK_GENERIC, ROCKROBO_GENERIC)
|
||||||
or model.startswith(ROBOROCK_GENERIC)
|
|
||||||
or model.startswith(ROCKROBO_GENERIC)
|
|
||||||
):
|
):
|
||||||
# TODO: add lazy_discover as argument when python-miio add support # pylint: disable=fixme
|
# TODO: add lazy_discover as argument when python-miio add support # pylint: disable=fixme
|
||||||
device = RoborockVacuum(host, token)
|
device = RoborockVacuum(host, token)
|
||||||
|
|
|
@ -831,10 +831,8 @@ async def async_setup_entry(
|
||||||
sensors = PURIFIER_MIIO_SENSORS
|
sensors = PURIFIER_MIIO_SENSORS
|
||||||
elif model in MODELS_PURIFIER_MIOT:
|
elif model in MODELS_PURIFIER_MIOT:
|
||||||
sensors = PURIFIER_MIOT_SENSORS
|
sensors = PURIFIER_MIOT_SENSORS
|
||||||
elif (
|
elif model in MODELS_VACUUM or model.startswith(
|
||||||
model in MODELS_VACUUM
|
(ROBOROCK_GENERIC, ROCKROBO_GENERIC)
|
||||||
or model.startswith(ROBOROCK_GENERIC)
|
|
||||||
or model.startswith(ROCKROBO_GENERIC)
|
|
||||||
):
|
):
|
||||||
return _setup_vacuum_sensors(hass, config_entry, async_add_entities)
|
return _setup_vacuum_sensors(hass, config_entry, async_add_entities)
|
||||||
|
|
||||||
|
|
|
@ -276,6 +276,7 @@ disable = [
|
||||||
"unidiomatic-typecheck", # E721
|
"unidiomatic-typecheck", # E721
|
||||||
"unnecessary-direct-lambda-call", # PLC3002
|
"unnecessary-direct-lambda-call", # PLC3002
|
||||||
"unnecessary-lambda-assignment", # PLC3001
|
"unnecessary-lambda-assignment", # PLC3001
|
||||||
|
"unnecessary-pass", # PIE790
|
||||||
"unneeded-not", # SIM208
|
"unneeded-not", # SIM208
|
||||||
"useless-import-alias", # PLC0414
|
"useless-import-alias", # PLC0414
|
||||||
"wrong-import-order", # I001
|
"wrong-import-order", # I001
|
||||||
|
@ -604,6 +605,10 @@ select = [
|
||||||
"N815", # Variable {name} in class scope should not be mixedCase
|
"N815", # Variable {name} in class scope should not be mixedCase
|
||||||
"PERF", # Perflint
|
"PERF", # Perflint
|
||||||
"PGH004", # Use specific rule codes when using noqa
|
"PGH004", # Use specific rule codes when using noqa
|
||||||
|
"PIE790", # Unnecessary pass statement
|
||||||
|
"PIE794", # Class field is defined multiple times
|
||||||
|
"PIE807", # Prefer list/dict over useless lambda
|
||||||
|
"PIE810", # Call startswith/endswith once with a tuple
|
||||||
"PLC0414", # Useless import alias. Import alias does not rename original package.
|
"PLC0414", # Useless import alias. Import alias does not rename original package.
|
||||||
"PLC", # pylint
|
"PLC", # pylint
|
||||||
"PLE", # pylint
|
"PLE", # pylint
|
||||||
|
|
|
@ -1297,7 +1297,7 @@ async def test_homekit_reset_accessories_not_bridged(
|
||||||
acc_mock = MagicMock()
|
acc_mock = MagicMock()
|
||||||
acc_mock.entity_id = entity_id
|
acc_mock.entity_id = entity_id
|
||||||
acc_mock.stop = AsyncMock()
|
acc_mock.stop = AsyncMock()
|
||||||
acc_mock.to_HAP = lambda: {}
|
acc_mock.to_HAP = dict
|
||||||
|
|
||||||
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
||||||
homekit.bridge.accessories = {aid: acc_mock}
|
homekit.bridge.accessories = {aid: acc_mock}
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Events(Base): # type: ignore
|
||||||
context_user_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True)
|
context_user_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True)
|
||||||
context_parent_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True)
|
context_parent_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True)
|
||||||
|
|
||||||
__table_args__ = (
|
__table_args__ = ( # noqa: PIE794
|
||||||
# Used for fetching events at a specific time
|
# Used for fetching events at a specific time
|
||||||
# see logbook
|
# see logbook
|
||||||
Index("ix_events_event_type_time_fired", "event_type", "time_fired"),
|
Index("ix_events_event_type_time_fired", "event_type", "time_fired"),
|
||||||
|
@ -156,7 +156,7 @@ class States(Base): # type: ignore
|
||||||
event = relationship("Events", uselist=False)
|
event = relationship("Events", uselist=False)
|
||||||
old_state = relationship("States", remote_side=[state_id])
|
old_state = relationship("States", remote_side=[state_id])
|
||||||
|
|
||||||
__table_args__ = (
|
__table_args__ = ( # noqa: PIE794
|
||||||
# Used for fetching the state of entities at a specific time
|
# Used for fetching the state of entities at a specific time
|
||||||
# (get_states in history.py)
|
# (get_states in history.py)
|
||||||
Index("ix_states_entity_id_last_updated", "entity_id", "last_updated"),
|
Index("ix_states_entity_id_last_updated", "entity_id", "last_updated"),
|
||||||
|
@ -237,7 +237,7 @@ class Statistics(Base): # type: ignore
|
||||||
state = Column(Float())
|
state = Column(Float())
|
||||||
sum = Column(Float())
|
sum = Column(Float())
|
||||||
|
|
||||||
__table_args__ = (
|
__table_args__ = ( # noqa: PIE794
|
||||||
# Used for fetching statistics for a certain entity at a specific time
|
# Used for fetching statistics for a certain entity at a specific time
|
||||||
Index("ix_statistics_statistic_id_start", "statistic_id", "start"),
|
Index("ix_statistics_statistic_id_start", "statistic_id", "start"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -254,7 +254,7 @@ class States(Base): # type: ignore
|
||||||
TIMESTAMP_TYPE, default=time.time
|
TIMESTAMP_TYPE, default=time.time
|
||||||
) # *** Not originally in v23, only added for recorder to startup ok
|
) # *** Not originally in v23, only added for recorder to startup ok
|
||||||
last_updated = Column(DATETIME_TYPE, default=dt_util.utcnow, index=True)
|
last_updated = Column(DATETIME_TYPE, default=dt_util.utcnow, index=True)
|
||||||
last_updated_ts = Column(
|
last_updated_ts = Column( # noqa: PIE794
|
||||||
TIMESTAMP_TYPE, default=time.time, index=True
|
TIMESTAMP_TYPE, default=time.time, index=True
|
||||||
) # *** Not originally in v23, only added for recorder to startup ok
|
) # *** Not originally in v23, only added for recorder to startup ok
|
||||||
created = Column(DATETIME_TYPE, default=dt_util.utcnow)
|
created = Column(DATETIME_TYPE, default=dt_util.utcnow)
|
||||||
|
|
|
@ -123,7 +123,6 @@ class TwitchMock:
|
||||||
|
|
||||||
async def _noop(self):
|
async def _noop(self):
|
||||||
"""Fake function to create task."""
|
"""Fake function to create task."""
|
||||||
pass
|
|
||||||
|
|
||||||
async def get_users(
|
async def get_users(
|
||||||
self, user_ids: list[str] | None = None, logins: list[str] | None = None
|
self, user_ids: list[str] | None = None, logins: list[str] | None = None
|
||||||
|
@ -157,7 +156,6 @@ class TwitchMock:
|
||||||
validate: bool = True,
|
validate: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set user authentication."""
|
"""Set user authentication."""
|
||||||
pass
|
|
||||||
|
|
||||||
async def get_followed_channels(
|
async def get_followed_channels(
|
||||||
self, user_id: str, broadcaster_id: str | None = None
|
self, user_id: str, broadcaster_id: str | None = None
|
||||||
|
|
|
@ -735,7 +735,6 @@ def test_add_job_pending_tasks_coro(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
async def test_coro():
|
async def test_coro():
|
||||||
"""Test Coro."""
|
"""Test Coro."""
|
||||||
pass
|
|
||||||
|
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
hass.add_job(test_coro())
|
hass.add_job(test_coro())
|
||||||
|
|
|
@ -9,8 +9,6 @@ class MockConfigFlow(
|
||||||
):
|
):
|
||||||
"""Mock config flow."""
|
"""Mock config flow."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
async def _async_has_devices(hass: HomeAssistant) -> bool:
|
async def _async_has_devices(hass: HomeAssistant) -> bool:
|
||||||
"""Return if there are devices that can be discovered."""
|
"""Return if there are devices that can be discovered."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue