Skip to content

Commit

Permalink
fix: string format Pylint W1202 & C0209 (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentame authored Nov 3, 2024
1 parent 0fdc929 commit fc7b703
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
14 changes: 5 additions & 9 deletions src/freebox_api/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(

async def _get_challenge(self, base_url, timeout=10):
"""
Return challenge from freebox API
Return challenge from Freebox API
"""
url = urljoin(base_url, "login")
resp = await self.session.get(url, timeout=timeout)
Expand All @@ -43,16 +43,14 @@ async def _get_challenge(self, base_url, timeout=10):
# raise exception if resp.success != True
if not resp_data.get("success"):
raise AuthorizationError(
"Getting challenge failed (APIResponse: {})".format(
json.dumps(resp_data)
)
f"Getting challenge failed (APIResponse: {json.dumps(resp_data)})"
)

return resp_data["result"]["challenge"]

async def _get_session_token(self, base_url, app_token, app_id, timeout=10):
"""
Get session token from freebox.
Get session token from Freebox.
Returns (session_token, session_permissions)
"""
# Get challenge from API
Expand All @@ -70,9 +68,7 @@ async def _get_session_token(self, base_url, app_token, app_id, timeout=10):
# raise exception if resp.success != True
if not resp_data.get("success"):
raise AuthorizationError(
"Starting session failed (APIResponse: {})".format(
json.dumps(resp_data)
)
f"Starting session failed (APIResponse: {json.dumps(resp_data)})"
)

session_token = resp_data["result"].get("session_token")
Expand Down Expand Up @@ -122,7 +118,7 @@ async def _perform_request(self, verb, end_url, **kwargs):
resp_data = await resp.json()

if not resp_data["success"]:
err_msg = "Request failed (APIResponse: {})".format(json.dumps(resp_data))
err_msg = f"Request failed (APIResponse: {json.dumps(resp_data)})"
if resp_data.get("error_code") == "insufficient_rights":
raise InsufficientPermissionsError(err_msg)
raise HttpRequestError(err_msg)
Expand Down
4 changes: 2 additions & 2 deletions src/freebox_api/aiofreepybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async def _get_freebox_access(

# Store application token in file
self._writefile_app_token(app_token, track_id, app_desc, token_file)
logger.info("Application token file was generated: {0}".format(token_file))
logger.info("Application token file was generated: %s", token_file)

# Create freebox http access module
fbx_access = Access(
Expand Down Expand Up @@ -255,7 +255,7 @@ async def _get_app_token(
# raise exception if resp.success != True
if not resp_data.get("success"):
raise AuthorizationError(
"Authorization failed (APIResponse: {0})".format(json.dumps(resp_data))
f"Authorization failed (APIResponse: {json.dumps(resp_data)})"
)

app_token: str = resp_data["result"]["app_token"]
Expand Down
8 changes: 2 additions & 6 deletions src/freebox_api/api/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ async def cd(self, path):
if await self._path_exists(path):
self._path = os.path.join(self._path, path)
else:
logger.error(
"{} path does not exist".format(os.path.join(self._path, path))
)
logger.error("%s path does not exist", os.path.join(self._path, path))

async def _path_exists(self, path):
"""
Expand All @@ -72,9 +70,7 @@ async def _path_exists(self, path):
await self.get_file_info(os.path.join(self._path, path))
return True
except freebox_api.exceptions.HttpRequestError:
logger.debug(
"{} path does not exist".format(os.path.join(self._path, path))
)
logger.debug("%s path does not exist", os.path.join(self._path, path))
return False

async def archive_files(self, archive):
Expand Down
16 changes: 8 additions & 8 deletions tests/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ async def demo():
# and default token_file location
fbx = Freepybox()

# To find out the HTTPS host and port of your freebox, go to
# To find out the HTTPS host and port of your Freebox, go to
# http://mafreebox.freebox.fr/api_version

# Connect to the freebox
# Connect to the Freebox
# Be ready to authorize the application on the Freebox if you use this
# example for the first time
await fbx.open(host="abcdefgh.fbxos.fr", port=1234)
Expand All @@ -32,31 +32,31 @@ async def demo():
m3u8_obj = m3u8.loads(await r.text())
fbx_ts = await fbx.home.get_camera_ts(m3u8_obj.files[0]) # noqa F841

# Dump freebox configuration using system API
# Dump Freebox configuration using system API
# Extract temperature and mac address
fbx_config = await fbx.system.get_config()
sensors = fbx_config["sensors"]
temp_sw = next(s for s in sensors if s["id"] == "temp_sw")
print("Freebox temperature : {0}".format(temp_sw["value"]))
print("Freebox mac address : {0}".format(fbx_config["mac"]))
print(f"Freebox temperature : {temp_sw["value"]}")
print(f"Freebox mac address : {fbx_config["mac"]}")

# Dump DHCP configuration using dhcp API
fbx_dhcp_config = await fbx.dhcp.get_config()
# Modify ip_range configuration
fbx_dhcp_config["ip_range_start"] = "192.168.0.10"
fbx_dhcp_config["ip_range_end"] = "192.168.0.50"
# Send new configuration to the freebox. This line is commented to
# Send new configuration to the Freebox. This line is commented to
# avoid any disaster.
# await fbx.dhcp.set_config(fbx_dhcp_config)

# Get the call list and print the last call entry
fbx_call_list = await fbx.call.get_call_list()
print(fbx_call_list[0])

# Reboot your freebox. This line is commented to avoid any disaster.
# Reboot your Freebox. This line is commented to avoid any disaster.
# await fbx.system.reboot()

# Close the freebox session
# Close the Freebox session
await fbx.close()


Expand Down

0 comments on commit fc7b703

Please sign in to comment.