Skip to content

Commit

Permalink
String formatting and max line length - Part 6 (home-assistant#84525)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Dec 24, 2022
1 parent ac1359b commit 8819634
Show file tree
Hide file tree
Showing 51 changed files with 238 additions and 102 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/recorder/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ def _apply_update( # noqa: C901
# Using LOCK=EXCLUSIVE to prevent the database from corrupting
# https://github.com/home-assistant/core/issues/56104
text(
f"ALTER TABLE {table} CONVERT TO "
"CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci, LOCK=EXCLUSIVE"
f"ALTER TABLE {table} CONVERT TO CHARACTER SET utf8mb4"
" COLLATE utf8mb4_unicode_ci, LOCK=EXCLUSIVE"
)
)
elif new_version == 22:
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/telegram_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,10 @@ def authorize_update(self, update: Update) -> bool:
if from_user in self.allowed_chat_ids or from_chat in self.allowed_chat_ids:
return True
_LOGGER.error(
"Unauthorized update - neither user id %s nor chat id %s is in allowed chats: %s",
(
"Unauthorized update - neither user id %s nor chat id %s is in allowed"
" chats: %s"
),
from_user,
from_chat,
self.allowed_chat_ids,
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/template/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ async def async_validate_config(hass, config):
if not legacy_warn_printed:
legacy_warn_printed = True
logging.getLogger(__name__).warning(
"The entity definition format under template: differs from the platform "
"The entity definition format under template: differs from the"
" platform "
"configuration format. See "
"https://www.home-assistant.io/integrations/template#configuration-for-trigger-based-template-sensors"
)
Expand Down
30 changes: 24 additions & 6 deletions homeassistant/components/template/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,10 @@ def _update_effect_list(self, effect_list):

if not isinstance(effect_list, list):
_LOGGER.error(
"Received invalid effect list: %s for entity %s. Expected list of strings",
(
"Received invalid effect list: %s for entity %s. Expected list of"
" strings"
),
effect_list,
self.entity_id,
)
Expand Down Expand Up @@ -545,7 +548,10 @@ def _update_temperature(self, render):
self._temperature = temperature
else:
_LOGGER.error(
"Received invalid color temperature : %s for entity %s. Expected: %s-%s",
(
"Received invalid color temperature : %s for entity %s."
" Expected: %s-%s"
),
temperature,
self.entity_id,
self.min_mireds,
Expand All @@ -554,7 +560,10 @@ def _update_temperature(self, render):
self._temperature = None
except ValueError:
_LOGGER.error(
"Template must supply an integer temperature within the range for this light, or 'None'",
(
"Template must supply an integer temperature within the range for"
" this light, or 'None'"
),
exc_info=True,
)
self._temperature = None
Expand Down Expand Up @@ -586,7 +595,10 @@ def _update_color(self, render):
self._color = (h_str, s_str)
elif h_str is not None and s_str is not None:
_LOGGER.error(
"Received invalid hs_color : (%s, %s) for entity %s. Expected: (0-360, 0-100)",
(
"Received invalid hs_color : (%s, %s) for entity %s. Expected:"
" (0-360, 0-100)"
),
h_str,
s_str,
self.entity_id,
Expand All @@ -609,7 +621,10 @@ def _update_max_mireds(self, render):
self._max_mireds = int(render)
except ValueError:
_LOGGER.error(
"Template must supply an integer temperature within the range for this light, or 'None'",
(
"Template must supply an integer temperature within the range for"
" this light, or 'None'"
),
exc_info=True,
)
self._max_mireds = None
Expand All @@ -624,7 +639,10 @@ def _update_min_mireds(self, render):
self._min_mireds = int(render)
except ValueError:
_LOGGER.error(
"Template must supply an integer temperature within the range for this light, or 'None'",
(
"Template must supply an integer temperature within the range for"
" this light, or 'None'"
),
exc_info=True,
)
self._min_mireds = None
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/template/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def extra_validation_checks(val):
"""Run extra validation checks."""
if CONF_TRIGGER in val:
raise vol.Invalid(
"You can only add triggers to template entities if they are defined under `template:`. "
"See the template documentation for more information: https://www.home-assistant.io/integrations/template/"
"You can only add triggers to template entities if they are defined under"
" `template:`. See the template documentation for more information:"
" https://www.home-assistant.io/integrations/template/"
)

if CONF_SENSORS not in val and SENSOR_DOMAIN not in val:
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/tesla_wall_connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ async def async_update_data():
) from ex
except WallConnectorConnectionError as ex:
raise UpdateFailed(
f"Could not fetch data from Tesla WallConnector at {hostname}: Cannot connect"
f"Could not fetch data from Tesla WallConnector at {hostname}: Cannot"
" connect"
) from ex
except WallConnectorError as ex:
raise UpdateFailed(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ async def _async_set_value(entity: TextEntity, service_call: ServiceCall) -> Non
value = service_call.data[ATTR_VALUE]
if len(value) < entity.min:
raise ValueError(
f"Value {value} for {entity.name} is too short (minimum length {entity.min})"
f"Value {value} for {entity.name} is too short (minimum length"
f" {entity.min})"
)
if len(value) > entity.max:
raise ValueError(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/tmb/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ def update(self) -> None:
self._state = self._ibus_client.get_stop_forecast(self._stop, self._line)
except HTTPError:
_LOGGER.error(
"Unable to fetch data from TMB API. Please check your API keys are valid"
"Unable to fetch data from TMB API. Please check your API keys are"
" valid"
)
4 changes: 3 additions & 1 deletion homeassistant/components/tplink/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ async def async_step_pick_device(
}
self._discovered_devices = await async_discover_devices(self.hass)
devices_name = {
formatted_mac: f"{device.alias} {device.model} ({device.host}) {formatted_mac}"
formatted_mac: (
f"{device.alias} {device.model} ({device.host}) {formatted_mac}"
)
for formatted_mac, device in self._discovered_devices.items()
if formatted_mac not in configured_devices
}
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/tractive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ async def _listen(self) -> None:

except aiotractive.exceptions.TractiveError:
_LOGGER.debug(
"Tractive is not available. Internet connection is down? Sleeping %i seconds and retrying",
(
"Tractive is not available. Internet connection is down?"
" Sleeping %i seconds and retrying"
),
RECONNECT_INTERVAL.total_seconds(),
)
self._last_hw_time = 0
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/trafikverket_train/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if "Invalid authentication" in error.args[0]:
raise ConfigEntryAuthFailed from error
raise ConfigEntryNotReady(
f"Problem when trying station {entry.data[CONF_FROM]} to {entry.data[CONF_TO]}. Error: {error} "
f"Problem when trying station {entry.data[CONF_FROM]} to"
f" {entry.data[CONF_TO]}. Error: {error} "
) from error

hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/travisci/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def setup_platform(
_LOGGER.error("Unable to connect to Travis CI service: %s", str(ex))
persistent_notification.create(
hass,
"Error: {}<br />"
"You will need to restart hass after fixing."
"".format(ex),
f"Error: {ex}<br />You will need to restart hass after fixing.",
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID,
)
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/tts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
base_url = conf.get(CONF_BASE_URL)
if base_url is not None:
_LOGGER.warning(
"TTS base_url option is deprecated. Configure internal/external URL instead"
"TTS base_url option is deprecated. Configure internal/external URL"
" instead"
)
hass.data[BASE_URL_KEY] = base_url

Expand Down Expand Up @@ -241,7 +242,9 @@ async def async_say_handle(service: ServiceCall) -> None:
# Register the service description
service_desc = {
CONF_NAME: f"Say a TTS message with {p_type}",
CONF_DESCRIPTION: f"Say something using text-to-speech on a media player with {p_type}.",
CONF_DESCRIPTION: (
f"Say something using text-to-speech on a media player with {p_type}."
),
CONF_FIELDS: services_dict[SERVICE_SAY][CONF_FIELDS],
}
async_set_service_schema(hass, DOMAIN, service_name, service_desc)
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/tuya/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
if self._set_temperature is None:
raise RuntimeError(
"Cannot set target temperature, device doesn't provide methods to set it"
"Cannot set target temperature, device doesn't provide methods to"
" set it"
)

self._send_command(
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/ubus/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def decorator(self, *args, **kwargs):
return func(self, *args, **kwargs)
except PermissionError:
_LOGGER.warning(
"Invalid session detected."
" Trying to refresh session_id and re-run RPC"
"Invalid session detected. Trying to refresh session_id and re-run RPC"
)
self.ubus.connect()

Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/unifiprotect/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
DEVICES_FOR_SUBSCRIBE = DEVICES_WITH_ENTITIES | {ModelType.EVENT}

MIN_REQUIRED_PROTECT_V = Version("1.20.0")
OUTDATED_LOG_MESSAGE = "You are running v%s of UniFi Protect. Minimum required version is v%s. Please upgrade UniFi Protect and then retry"
OUTDATED_LOG_MESSAGE = (
"You are running v%s of UniFi Protect. Minimum required version is v%s. Please"
" upgrade UniFi Protect and then retry"
)

TYPE_EMPTY_VALUE = ""

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/unifiprotect/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def _async_process_ws_message(self, message: WSSubscriptionMessage) -> None:
# alert user viewport needs restart so voice clients can get new options
elif len(self.api.bootstrap.viewers) > 0 and isinstance(obj, Liveview):
_LOGGER.warning(
"Liveviews updated. Restart Home Assistant to update Viewport select options"
"Liveviews updated. Restart Home Assistant to update Viewport select"
" options"
)

@callback
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/unifiprotect/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ async def async_migrate_device_ids(
registry.async_update_entity(entity.entity_id, new_unique_id=new_unique_id)
except ValueError as err:
_LOGGER.warning(
"Could not migrate entity %s (old unique_id: %s, new unique_id: %s): %s",
(
"Could not migrate entity %s (old unique_id: %s, new unique_id:"
" %s): %s"
),
entity.entity_id,
entity.unique_id,
new_unique_id,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/upcloud/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

DOMAIN = "upcloud"
DEFAULT_SCAN_INTERVAL = timedelta(seconds=60)
CONFIG_ENTRY_UPDATE_SIGNAL_TEMPLATE = f"{DOMAIN}_config_entry_update:" "{}"
CONFIG_ENTRY_UPDATE_SIGNAL_TEMPLATE = f"{DOMAIN}_config_entry_update:{{}}"
6 changes: 4 additions & 2 deletions homeassistant/components/venstar/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,10 @@ def set_temperature(self, **kwargs):
else:
success = False
_LOGGER.error(
"The thermostat is currently not in a mode "
"that supports target temperature: %s",
(
"The thermostat is currently not in a mode "
"that supports target temperature: %s"
),
operation_mode,
)

Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/vesync/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ def color_temp(self) -> int:
except ValueError:
# deal if any unexpected/non numeric value
_LOGGER.debug(
"VeSync - received unexpected 'color_temp_pct' value from pyvesync api: %s",
(
"VeSync - received unexpected 'color_temp_pct' value from pyvesync"
" api: %s"
),
result,
)
return 0
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/vivotek/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def setup_platform(
digest_auth=config[CONF_AUTHENTICATION] == HTTP_DIGEST_AUTHENTICATION,
sec_lvl=config[CONF_SECURITY_LEVEL],
),
"stream_source": f"rtsp://{creds}@{config[CONF_IP_ADDRESS]}:554/{config[CONF_STREAM_PATH]}",
"stream_source": (
f"rtsp://{creds}@{config[CONF_IP_ADDRESS]}:554/{config[CONF_STREAM_PATH]}"
),
}
add_entities([VivotekCam(**args)], True)

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/vizio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def validate_apps(config: ConfigType) -> ConfigType:
and config[CONF_DEVICE_CLASS] != MediaPlayerDeviceClass.TV
):
raise vol.Invalid(
f"'{CONF_APPS}' can only be used if {CONF_DEVICE_CLASS}' is '{MediaPlayerDeviceClass.TV}'"
f"'{CONF_APPS}' can only be used if {CONF_DEVICE_CLASS}' is"
f" '{MediaPlayerDeviceClass.TV}'"
)

return config
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/vizio/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,11 @@ async def async_step_user(
# their configuration.yaml or to proceed with config flow pairing. We
# will also provide contextual message to user explaining why
_LOGGER.warning(
"Couldn't complete configuration.yaml import: '%s' key is "
"missing. Either provide '%s' key in configuration.yaml or "
"finish setup by completing configuration via frontend",
(
"Couldn't complete configuration.yaml import: '%s' key is "
"missing. Either provide '%s' key in configuration.yaml or "
"finish setup by completing configuration via frontend"
),
CONF_ACCESS_TOKEN,
CONF_ACCESS_TOKEN,
)
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/volvooncall/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ async def async_step_user(
): vol.In(
{
UNIT_SYSTEM_METRIC: "Metric",
UNIT_SYSTEM_SCANDINAVIAN_MILES: "Metric with Scandinavian Miles",
UNIT_SYSTEM_SCANDINAVIAN_MILES: (
"Metric with Scandinavian Miles"
),
UNIT_SYSTEM_IMPERIAL: "Imperial",
}
),
Expand Down
9 changes: 7 additions & 2 deletions homeassistant/components/vulcan/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ def __init__(self, client, data, entity_id) -> None:
"identifiers": {(DOMAIN, f"calendar_{self.student_info['id']}")},
"entry_type": DeviceEntryType.SERVICE,
"name": f"{self.student_info['full_name']}: Calendar",
"model": f"{self.student_info['full_name']} - {self.student_info['class']} {self.student_info['school']}",
"model": (
f"{self.student_info['full_name']} -"
f" {self.student_info['class']} {self.student_info['school']}"
),
"manufacturer": "Uonet +",
"configuration_url": f"https://uonetplus.vulcan.net.pl/{self.student_info['symbol']}",
"configuration_url": (
f"https://uonetplus.vulcan.net.pl/{self.student_info['symbol']}"
),
}

@property
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/vulcan/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ async def async_step_add_next_config_entry(self, user_input=None):
await self.async_set_unique_id(str(new_students[0].pupil.id))
self._abort_if_unique_id_configured()
return self.async_create_entry(
title=f"{new_students[0].pupil.first_name} {new_students[0].pupil.last_name}",
title=(
f"{new_students[0].pupil.first_name} {new_students[0].pupil.last_name}"
),
data={
"student_id": str(new_students[0].pupil.id),
"keystore": keystore.as_dict,
Expand Down Expand Up @@ -282,7 +284,9 @@ async def async_step_reauth_confirm(self, user_input=None):
if str(student.pupil.id) == str(entry.data["student_id"]):
self.hass.config_entries.async_update_entry(
entry,
title=f"{student.pupil.first_name} {student.pupil.last_name}",
title=(
f"{student.pupil.first_name} {student.pupil.last_name}"
),
data={
"student_id": str(student.pupil.id),
"keystore": keystore.as_dict,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/vultr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
_LOGGER.error("Failed to make update API request because: %s", ex)
persistent_notification.create(
hass,
"Error: {}" "".format(ex),
f"Error: {ex}",
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID,
)
Expand Down
Loading

0 comments on commit 8819634

Please sign in to comment.