Skip to content

Commit

Permalink
fix: more mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jun 9, 2024
1 parent b59930c commit f889c50
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/uiprotect/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ def decode_ws_msg(
ws_data: str | None = ARG_WS_DATA,
) -> None:
"""Decodes a base64 encoded UniFi Protect Websocket binary message."""
if ws_file is None and ws_data is None:
typer.secho("Websocket data required", fg="red")
if ws_file is None and ws_data is None: # type: ignore[unreachable]
typer.secho("Websocket data required", fg="red") # type: ignore[unreachable]
sys.exit(1)

ws_data_raw = b""
if ws_file is not None:
ws_data_raw = ws_file.read()
elif ws_data is not None:
elif ws_data is not None: # type: ignore[unreachable]
ws_data_raw = base64.b64decode(ws_data.encode("utf8"))

packet = WSPacket(ws_data_raw)
Expand Down
4 changes: 2 additions & 2 deletions src/uiprotect/cli/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ class EventTypeChoice(str, Enum):
SMART_DETECT_LINE = d.EventType.SMART_DETECT_LINE.value


class EventSmartType(Base):
class EventSmartType(Base): # type: ignore[valid-type,misc]
__tablename__ = "event_smart_type"

id = Column(Integer, primary_key=True)
event_id = Column(String(24), ForeignKey("event.id"), nullable=False)
smart_type = Column(String(32), index=True)


class Event(Base):
class Event(Base): # type: ignore[valid-type,misc]
__tablename__ = "event"
__allow_unmapped__ = True

Expand Down
16 changes: 8 additions & 8 deletions src/uiprotect/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def _get_protect_dicts_set(cls) -> set[str]:
@classmethod
def _get_api(cls, api: ProtectApiClient | None) -> ProtectApiClient | None:
"""Helper method to try to find and the current ProjtectAPIClient instance from given data"""
if api is None and isinstance(cls, ProtectBaseObject) and hasattr(cls, "_api"):
api = cls._api
if api is None and isinstance(cls, ProtectBaseObject) and hasattr(cls, "_api"): # type: ignore[unreachable]
api = cls._api # type: ignore[unreachable]

return api

Expand Down Expand Up @@ -479,15 +479,15 @@ def unifi_dict(
data[key] = self._unifi_dict_protect_obj_dict(data, key, use_obj)

# all child objects have been serialized correctly do not do it twice
data: dict[str, Any] = serialize_unifi_obj(data, levels=2)
new_data: dict[str, Any] = serialize_unifi_obj(data, levels=2)
remaps = self._get_to_unifi_remaps()
for to_key in set(data).intersection(remaps):
data[remaps[to_key]] = data.pop(to_key)
for to_key in set(new_data).intersection(remaps):
new_data[remaps[to_key]] = new_data.pop(to_key)

if "api" in data:
del data["api"]
if "api" in new_data:
del new_data["api"]

return data
return new_data

def _inject_api(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/uiprotect/data/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3225,7 +3225,7 @@ def _get_unifi_remaps(cls) -> dict[str, str]:
def camera(self) -> Camera | None:
"""Paired Camera will always be none if no camera is paired"""
if self.camera_id is None:
return None
return None # type: ignore[unreachable]

return self.api.bootstrap.cameras[self.camera_id]

Expand Down
2 changes: 1 addition & 1 deletion src/uiprotect/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def run_async(callback: Coroutine[Any, Any, T]) -> T:
"""Run async coroutine."""
if sys.version_info >= (3, 11):
return asyncio.run(callback)
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop() # type: ignore[unreachable]
return loop.run_until_complete(callback)


Expand Down

0 comments on commit f889c50

Please sign in to comment.