1
mirror of https://github.com/home-assistant/core synced 2024-09-03 08:14:07 +02:00

Improve onvif type hints (#73642)

* Remove onvif from mypy ignore list

* Adjust parsers

* Adjust event

* Adjust config_flow
This commit is contained in:
epenet 2022-06-20 12:07:33 +02:00 committed by GitHub
parent 474e0fd6d0
commit b318b9b196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 52 deletions

View File

@ -2,6 +2,7 @@
from __future__ import annotations
from pprint import pformat
from typing import Any
from urllib.parse import urlparse
from onvif.exceptions import ONVIFError
@ -44,7 +45,7 @@ def wsdiscovery() -> list[Service]:
return services
async def async_discovery(hass) -> bool:
async def async_discovery(hass) -> list[dict[str, Any]]:
"""Return if there are devices that can be discovered."""
LOGGER.debug("Starting ONVIF discovery")
services = await hass.async_add_executor_job(wsdiscovery)

View File

@ -114,7 +114,7 @@ class EventManager:
await self._subscription.Unsubscribe()
self._subscription = None
async def async_restart(self, _now: dt = None) -> None:
async def async_restart(self, _now: dt.datetime | None = None) -> None:
"""Restart the subscription assuming the camera rebooted."""
if not self.started:
return
@ -159,7 +159,7 @@ class EventManager:
"""Schedule async_pull_messages to run."""
self._unsub_refresh = async_call_later(self.hass, 1, self.async_pull_messages)
async def async_pull_messages(self, _now: dt = None) -> None:
async def async_pull_messages(self, _now: dt.datetime | None = None) -> None:
"""Pull messages from device."""
if self.hass.state == CoreState.running:
try:

View File

@ -11,11 +11,11 @@ from homeassistant.helpers.entity import EntityCategory
class DeviceInfo:
"""Represent device information."""
manufacturer: str = None
model: str = None
fw_version: str = None
serial_number: str = None
mac: str = None
manufacturer: str | None = None
model: str | None = None
fw_version: str | None = None
serial_number: str | None = None
mac: str | None = None
@dataclass
@ -41,7 +41,7 @@ class PTZ:
continuous: bool
relative: bool
absolute: bool
presets: list[str] = None
presets: list[str] | None = None
@dataclass
@ -52,7 +52,7 @@ class Profile:
token: str
name: str
video: Video
ptz: PTZ = None
ptz: PTZ | None = None
@dataclass
@ -71,8 +71,8 @@ class Event:
uid: str
name: str
platform: str
device_class: str = None
unit_of_measurement: str = None
device_class: str | None = None
unit_of_measurement: str | None = None
value: Any = None
entity_category: EntityCategory | None = None
entity_enabled: bool = True

View File

@ -11,7 +11,9 @@ from homeassistant.util.decorator import Registry
from .models import Event
PARSERS: Registry[str, Callable[[str, Any], Coroutine[Any, Any, Event]]] = Registry()
PARSERS: Registry[
str, Callable[[str, Any], Coroutine[Any, Any, Event | None]]
] = Registry()
def local_datetime_or_none(value: str) -> datetime.datetime | None:
@ -28,7 +30,7 @@ def local_datetime_or_none(value: str) -> datetime.datetime | None:
@PARSERS.register("tns1:VideoSource/MotionAlarm")
# pylint: disable=protected-access
async def async_parse_motion_alarm(uid: str, msg) -> Event:
async def async_parse_motion_alarm(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:VideoSource/MotionAlarm
@ -51,7 +53,7 @@ async def async_parse_motion_alarm(uid: str, msg) -> Event:
@PARSERS.register("tns1:VideoSource/ImageTooBlurry/ImagingService")
@PARSERS.register("tns1:VideoSource/ImageTooBlurry/RecordingService")
# pylint: disable=protected-access
async def async_parse_image_too_blurry(uid: str, msg) -> Event:
async def async_parse_image_too_blurry(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:VideoSource/ImageTooBlurry/*
@ -75,7 +77,7 @@ async def async_parse_image_too_blurry(uid: str, msg) -> Event:
@PARSERS.register("tns1:VideoSource/ImageTooDark/ImagingService")
@PARSERS.register("tns1:VideoSource/ImageTooDark/RecordingService")
# pylint: disable=protected-access
async def async_parse_image_too_dark(uid: str, msg) -> Event:
async def async_parse_image_too_dark(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:VideoSource/ImageTooDark/*
@ -99,7 +101,7 @@ async def async_parse_image_too_dark(uid: str, msg) -> Event:
@PARSERS.register("tns1:VideoSource/ImageTooBright/ImagingService")
@PARSERS.register("tns1:VideoSource/ImageTooBright/RecordingService")
# pylint: disable=protected-access
async def async_parse_image_too_bright(uid: str, msg) -> Event:
async def async_parse_image_too_bright(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:VideoSource/ImageTooBright/*
@ -123,7 +125,7 @@ async def async_parse_image_too_bright(uid: str, msg) -> Event:
@PARSERS.register("tns1:VideoSource/GlobalSceneChange/ImagingService")
@PARSERS.register("tns1:VideoSource/GlobalSceneChange/RecordingService")
# pylint: disable=protected-access
async def async_parse_scene_change(uid: str, msg) -> Event:
async def async_parse_scene_change(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:VideoSource/GlobalSceneChange/*
@ -144,7 +146,7 @@ async def async_parse_scene_change(uid: str, msg) -> Event:
@PARSERS.register("tns1:AudioAnalytics/Audio/DetectedSound")
# pylint: disable=protected-access
async def async_parse_detected_sound(uid: str, msg) -> Event:
async def async_parse_detected_sound(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:AudioAnalytics/Audio/DetectedSound
@ -175,7 +177,7 @@ async def async_parse_detected_sound(uid: str, msg) -> Event:
@PARSERS.register("tns1:RuleEngine/FieldDetector/ObjectsInside")
# pylint: disable=protected-access
async def async_parse_field_detector(uid: str, msg) -> Event:
async def async_parse_field_detector(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:RuleEngine/FieldDetector/ObjectsInside
@ -207,7 +209,7 @@ async def async_parse_field_detector(uid: str, msg) -> Event:
@PARSERS.register("tns1:RuleEngine/CellMotionDetector/Motion")
# pylint: disable=protected-access
async def async_parse_cell_motion_detector(uid: str, msg) -> Event:
async def async_parse_cell_motion_detector(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:RuleEngine/CellMotionDetector/Motion
@ -238,7 +240,7 @@ async def async_parse_cell_motion_detector(uid: str, msg) -> Event:
@PARSERS.register("tns1:RuleEngine/MotionRegionDetector/Motion")
# pylint: disable=protected-access
async def async_parse_motion_region_detector(uid: str, msg) -> Event:
async def async_parse_motion_region_detector(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:RuleEngine/MotionRegionDetector/Motion
@ -269,7 +271,7 @@ async def async_parse_motion_region_detector(uid: str, msg) -> Event:
@PARSERS.register("tns1:RuleEngine/TamperDetector/Tamper")
# pylint: disable=protected-access
async def async_parse_tamper_detector(uid: str, msg) -> Event:
async def async_parse_tamper_detector(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:RuleEngine/TamperDetector/Tamper
@ -301,7 +303,7 @@ async def async_parse_tamper_detector(uid: str, msg) -> Event:
@PARSERS.register("tns1:Device/Trigger/DigitalInput")
# pylint: disable=protected-access
async def async_parse_digital_input(uid: str, msg) -> Event:
async def async_parse_digital_input(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:Device/Trigger/DigitalInput
@ -322,7 +324,7 @@ async def async_parse_digital_input(uid: str, msg) -> Event:
@PARSERS.register("tns1:Device/Trigger/Relay")
# pylint: disable=protected-access
async def async_parse_relay(uid: str, msg) -> Event:
async def async_parse_relay(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:Device/Trigger/Relay
@ -343,7 +345,7 @@ async def async_parse_relay(uid: str, msg) -> Event:
@PARSERS.register("tns1:Device/HardwareFailure/StorageFailure")
# pylint: disable=protected-access
async def async_parse_storage_failure(uid: str, msg) -> Event:
async def async_parse_storage_failure(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:Device/HardwareFailure/StorageFailure
@ -365,7 +367,7 @@ async def async_parse_storage_failure(uid: str, msg) -> Event:
@PARSERS.register("tns1:Monitoring/ProcessorUsage")
# pylint: disable=protected-access
async def async_parse_processor_usage(uid: str, msg) -> Event:
async def async_parse_processor_usage(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:Monitoring/ProcessorUsage
@ -390,7 +392,7 @@ async def async_parse_processor_usage(uid: str, msg) -> Event:
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReboot")
# pylint: disable=protected-access
async def async_parse_last_reboot(uid: str, msg) -> Event:
async def async_parse_last_reboot(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:Monitoring/OperatingTime/LastReboot
@ -414,7 +416,7 @@ async def async_parse_last_reboot(uid: str, msg) -> Event:
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReset")
# pylint: disable=protected-access
async def async_parse_last_reset(uid: str, msg) -> Event:
async def async_parse_last_reset(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:Monitoring/OperatingTime/LastReset
@ -439,7 +441,7 @@ async def async_parse_last_reset(uid: str, msg) -> Event:
@PARSERS.register("tns1:Monitoring/Backup/Last")
# pylint: disable=protected-access
async def async_parse_backup_last(uid: str, msg) -> Event:
async def async_parse_backup_last(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:Monitoring/Backup/Last
@ -465,7 +467,7 @@ async def async_parse_backup_last(uid: str, msg) -> Event:
@PARSERS.register("tns1:Monitoring/OperatingTime/LastClockSynchronization")
# pylint: disable=protected-access
async def async_parse_last_clock_sync(uid: str, msg) -> Event:
async def async_parse_last_clock_sync(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:Monitoring/OperatingTime/LastClockSynchronization
@ -490,7 +492,7 @@ async def async_parse_last_clock_sync(uid: str, msg) -> Event:
@PARSERS.register("tns1:RecordingConfig/JobState")
# pylint: disable=protected-access
async def async_parse_jobstate(uid: str, msg) -> Event:
async def async_parse_jobstate(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:RecordingConfig/JobState

View File

@ -2814,27 +2814,12 @@ ignore_errors = true
[mypy-homeassistant.components.onvif.binary_sensor]
ignore_errors = true
[mypy-homeassistant.components.onvif.button]
ignore_errors = true
[mypy-homeassistant.components.onvif.camera]
ignore_errors = true
[mypy-homeassistant.components.onvif.config_flow]
ignore_errors = true
[mypy-homeassistant.components.onvif.device]
ignore_errors = true
[mypy-homeassistant.components.onvif.event]
ignore_errors = true
[mypy-homeassistant.components.onvif.models]
ignore_errors = true
[mypy-homeassistant.components.onvif.parsers]
ignore_errors = true
[mypy-homeassistant.components.onvif.sensor]
ignore_errors = true

View File

@ -87,13 +87,8 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.omnilogic.switch",
"homeassistant.components.onvif.base",
"homeassistant.components.onvif.binary_sensor",
"homeassistant.components.onvif.button",
"homeassistant.components.onvif.camera",
"homeassistant.components.onvif.config_flow",
"homeassistant.components.onvif.device",
"homeassistant.components.onvif.event",
"homeassistant.components.onvif.models",
"homeassistant.components.onvif.parsers",
"homeassistant.components.onvif.sensor",
"homeassistant.components.philips_js",
"homeassistant.components.philips_js.config_flow",