Skip to content

Commit

Permalink
Version 4.2.3, refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
autinerd committed Feb 15, 2024
1 parent 2ba9f15 commit 784ce0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion openwebif/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Top-level package for openwebif."""

__version__ = "4.2.2"
__version__ = "4.2.3"
22 changes: 9 additions & 13 deletions openwebif/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class OpenWebIfDevice:
picon_url: str | None = None
source_bouquet: str | None = None
mac_address: str | None = None
sources: dict[str, Any] | None = None
source_list: list[str] | None = None
sources: dict[str, Any]
source_list: list[str]

# pylint: disable=too-many-arguments, disable=too-many-instance-attributes
def __init__(
Expand Down Expand Up @@ -141,11 +141,11 @@ def default_all(self) -> None:
"""Set all properties to default."""
self.status = OpenWebIfStatus(currservice=OpenWebIfServiceEvent())

async def get_about(self) -> dict[str, Any] | None:
async def get_about(self) -> dict[str, Any]:
"""Get general information."""
return await self._call_api(PATH_ABOUT)

async def get_status_info(self) -> dict[str, Any] | None:
async def get_status_info(self) -> dict[str, Any]:
"""Get status info."""
return await self._call_api(PATH_STATUSINFO)

Expand Down Expand Up @@ -212,11 +212,10 @@ async def update(self) -> None:
)
self.picon_url = str(self.base.with_path(url)) if url is not None else None

async def get_volume(self) -> int | None:
async def get_volume(self) -> int:
"""Get the current volume."""

response = await self._call_api(PATH_VOL)
return None if response is None else int(response["current"])
return int((await self._call_api(PATH_VOL))["current"])

async def set_volume(self, new_volume: int | SetVolumeOption) -> bool:
"""Set the volume to the new value.
Expand Down Expand Up @@ -440,7 +439,7 @@ def get_picon_name(channel_name: str) -> str:
.lower(),
)

async def get_version(self) -> str | None:
async def get_version(self) -> str:
"""Return the Openwebif version."""

about = await self.get_about()
Expand Down Expand Up @@ -501,7 +500,7 @@ async def zap(self, source: str) -> bool:

async def _call_api(
self, path: str, params: Mapping[str, str | int | bool] | None = None
) -> dict[str, Any] | None:
) -> dict[str, Any]:
"""Perform one api request operation."""
if self._session is None:
self._session = aiohttp.ClientSession(self.base)
Expand All @@ -516,8 +515,5 @@ async def _call_api(
response.request_info.url,
await response.text(),
)
if not self.is_offline:
_LOGGER.warning("%s is unreachable.", response.request_info.url)
self.is_offline = True
return None
raise ConnectionError
return dict(await response.json(content_type=None))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers = [
license = {file = "LICENSE"}
keywords=['openwebif']

dependencies = ["aiohttp", "yarl", "typing_extensions"]
dependencies = ["aiohttp", "yarl"]
dynamic = ["version"]

[project.urls]
Expand Down

0 comments on commit 784ce0e

Please sign in to comment.