Skip to content

Commit

Permalink
configure linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisChrist committed Mar 9, 2024
1 parent 64fe694 commit eec6368
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
33 changes: 9 additions & 24 deletions blueos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
from blueos.entities import Status, Volume

StringDict: TypeAlias = dict[str, Union[str, "StringDict"]]
# pylint: disable=invalid-name
T: TypeAlias = TypeVar("T")


def chained_get(
data: StringDict, *keys, _map: Callable[[str], T] = lambda x: x
) -> T | None:
def chained_get(data: StringDict, *keys, _map: Callable[[str], T] = lambda x: x) -> T | None:
local_data = data
for key in keys:
local_data = local_data.get(key)
Expand All @@ -21,9 +20,7 @@ def chained_get(


class BlueOS:
def __init__(
self, host: str, port: int = 11000, session: aiohttp.ClientSession = None
):
def __init__(self, host: str, port: int = 11000, session: aiohttp.ClientSession = None):
self.base_url = f"http://{host}:{port}"
if session:
self._owned_session = False
Expand Down Expand Up @@ -55,9 +52,7 @@ async def status(self, etag: str = None, timeout: int = 30) -> Status:
if etag:
params["etag"] = etag
params["timeout"] = timeout
async with self._session.get(
f"{self.base_url}/Status", params=params
) as response:
async with self._session.get(f"{self.base_url}/Status", params=params) as response:
response.raise_for_status()
response_data = await response.text()
response_dict = xmltodict.parse(response_data)
Expand All @@ -72,9 +67,7 @@ async def status(self, etag: str = None, timeout: int = 30) -> Status:
volume=chained_get(response_dict, "status", "volume", _map=int),
mute=chained_get(response_dict, "status", "mute") == "1",
seconds=chained_get(response_dict, "status", "secs", _map=int),
total_seconds=chained_get(
response_dict, "status", "totlen", _map=float
),
total_seconds=chained_get(response_dict, "status", "totlen", _map=float),
)

return status
Expand All @@ -88,9 +81,7 @@ async def mac(self) -> str:

return chained_get(response_dict, "SyncStatus", "@mac")

async def volume(
self, level: int = None, mute: bool = None, tell_slaves: bool = None
) -> Volume:
async def volume(self, level: int = None, mute: bool = None, tell_slaves: bool = None) -> Volume:
"""Get or set the volume of the device. Uses the /Volume endpoint."""
params = {}
if level:
Expand All @@ -100,9 +91,7 @@ async def volume(
if tell_slaves:
params["tell_slaves"] = "1" if tell_slaves else "0"

async with self._session.get(
f"{self.base_url}/Volume", params=params
) as response:
async with self._session.get(f"{self.base_url}/Volume", params=params) as response:
response.raise_for_status()
response_data = await response.text()
response_dict = xmltodict.parse(response_data)
Expand All @@ -120,9 +109,7 @@ async def play(self, seek: int = None) -> str:
if seek:
params["seek"] = seek

async with self._session.get(
f"{self.base_url}/Play", params=params
) as response:
async with self._session.get(f"{self.base_url}/Play", params=params) as response:
response.raise_for_status()
response_data = await response.text()
response_dict = xmltodict.parse(response_data)
Expand All @@ -134,9 +121,7 @@ async def pause(self, toggle: bool = None) -> str:
if toggle:
params["toggle"] = "1"

async with self._session.get(
f"{self.base_url}/Pause", params=params
) as response:
async with self._session.get(f"{self.base_url}/Pause", params=params) as response:
response.raise_for_status()
response_data = await response.text()
response_dict = xmltodict.parse(response_data)
Expand Down
1 change: 1 addition & 0 deletions blueos/cmd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
import asyncio

from blueos import BlueOS, Status, entities
Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ black = "^24.2.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pylint."messages control"]
disable = [
"missing-function-docstring",
"missing-module-docstring",
"missing-class-docstring",
"too-many-instance-attributes",
]

[tool.pylint.format]
max-line-length = 160

[tool.black]
line-length = 160

0 comments on commit eec6368

Please sign in to comment.