Skip to content

Commit

Permalink
no implicit optional typing (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdrob authored Sep 7, 2023
1 parent e32a22e commit feef73f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
19 changes: 10 additions & 9 deletions aioskybell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class Skybell: # pylint:disable=too-many-instance-attributes

def __init__( # pylint:disable=too-many-arguments
self,
username: str = None,
password: str = None,
username: str | None = None,
password: str | None = None,
auto_login: bool = False,
get_devices: bool = False,
cache_path: str = CONST.CACHE_PATH,
disable_cache: bool = False,
login_sleep: bool = True,
session: ClientSession = None,
session: ClientSession | None = None,
) -> None:
"""Initialize Skybell object."""
self._auto_login = auto_login
Expand Down Expand Up @@ -92,7 +92,9 @@ async def async_initialize(self) -> list[SkybellDevice]:
self._user = await self.async_send_request(method="get", url=CONST.USERS_ME_URL)
return await self.async_get_devices()

async def async_login(self, username: str = None, password: str = None) -> bool:
async def async_login(
self, username: str | None = None, password: str | None = None
) -> bool:
"""Execute Skybell login."""
if username is not None:
self._username = username
Expand Down Expand Up @@ -148,7 +150,6 @@ async def async_logout(self) -> bool:
async def async_get_devices(self, refresh: bool = False) -> list[SkybellDevice]:
"""Get all devices from Skybell."""
if refresh or len(self._devices) == 0:

_LOGGER.info("Updating all devices...")
response = await self.async_send_request("get", CONST.DEVICES_URL)

Expand Down Expand Up @@ -203,8 +204,8 @@ async def async_send_request( # pylint:disable=too-many-arguments
self,
method: str,
url: str,
headers: dict[str, str] = None,
json_data: dict[str, str | int] = None,
headers: dict[str, str] | None = None,
json_data: dict[str, str | int] | None = None,
retry: bool = True,
) -> Any:
"""Send requests to Skybell."""
Expand Down Expand Up @@ -267,7 +268,7 @@ async def async_update_cache(
await self._async_save_cache()

def dev_cache(
self, device: SkybellDevice, key: str = None
self, device: SkybellDevice, key: str | None = None
) -> dict[str, EventTypeDict] | EventTypeDict | None:
"""Get a cached value for a device."""
cache = cast(dict[str, DeviceDict], self._cache.get(CONST.DEVICES, {}))
Expand Down Expand Up @@ -303,7 +304,7 @@ async def _async_save_cache(self) -> None:
if not self._disable_cache:
await UTILS.async_save_cache(self._cache, self._cache_path)

async def async_test_ports(self, host: str, ports: list[int] = None) -> bool:
async def async_test_ports(self, host: str, ports: list[int] | None = None) -> bool:
"""Test if ports are open. Only use this for discovery."""
result = False
for port in ports or [6881, 6969]:
Expand Down
18 changes: 9 additions & 9 deletions aioskybell/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def _async_info_request(self) -> InfoDict:
return data

async def _async_settings_request(
self, method: str = "get", json_data: dict[str, str | int] = None
self, method: str = "get", json_data: dict[str, str | int] | None = None
) -> SettingsDict:
url = str.replace(CONST.DEVICE_SETTINGS_URL, "$DEVID$", self.device_id)
return await self._skybell.async_send_request(
Expand All @@ -72,10 +72,10 @@ async def _async_activities_request(self) -> list[EventDict]:

async def async_update( # pylint:disable=too-many-arguments
self,
device_json: dict[str, str | dict[str, str]] = None,
info_json: dict[str, str | dict[str, str]] = None,
settings_json: dict[str, str | int] = None,
avatar_json: dict[str, str] = None,
device_json: dict[str, str | dict[str, str]] | None = None,
info_json: dict[str, str | dict[str, str]] | None = None,
settings_json: dict[str, str | int] | None = None,
avatar_json: dict[str, str] | None = None,
refresh: bool = True,
get_devices: bool = False,
) -> None:
Expand Down Expand Up @@ -137,7 +137,7 @@ async def _async_update_events(

await self._skybell.async_update_dev_cache(self, {CONST.EVENT: events})

def activities(self, limit: int = 1, event: str = None) -> list[EventDict]:
def activities(self, limit: int = 1, event: str | None = None) -> list[EventDict]:
"""Return device activity information."""
activities = self._activities

Expand All @@ -148,7 +148,7 @@ def activities(self, limit: int = 1, event: str = None) -> list[EventDict]:
# Return the requested number
return activities[:limit]

def latest(self, event: str = None) -> EventDict:
def latest(self, event: str | None = None) -> EventDict:
"""Return the latest event activity (motion or button)."""
events = cast(EventTypeDict, self._skybell.dev_cache(self, CONST.EVENT)) or {}
_LOGGER.debug(events)
Expand Down Expand Up @@ -225,8 +225,8 @@ async def async_get_activity_video_url(self, video: str | None = None) -> str:

async def async_download_videos(
self,
path: str = None,
video: str = None,
path: str | None = None,
video: str | None = None,
limit: int = 1,
delete: bool = False,
) -> None:
Expand Down

0 comments on commit feef73f

Please sign in to comment.