mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Improve onvif type hints (#73642)
* Remove onvif from mypy ignore list * Adjust parsers * Adjust event * Adjust config_flow
This commit is contained in:
parent
474e0fd6d0
commit
b318b9b196
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
from typing import Any
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from onvif.exceptions import ONVIFError
|
from onvif.exceptions import ONVIFError
|
||||||
@ -44,7 +45,7 @@ def wsdiscovery() -> list[Service]:
|
|||||||
return services
|
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."""
|
"""Return if there are devices that can be discovered."""
|
||||||
LOGGER.debug("Starting ONVIF discovery")
|
LOGGER.debug("Starting ONVIF discovery")
|
||||||
services = await hass.async_add_executor_job(wsdiscovery)
|
services = await hass.async_add_executor_job(wsdiscovery)
|
||||||
|
@ -114,7 +114,7 @@ class EventManager:
|
|||||||
await self._subscription.Unsubscribe()
|
await self._subscription.Unsubscribe()
|
||||||
self._subscription = None
|
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."""
|
"""Restart the subscription assuming the camera rebooted."""
|
||||||
if not self.started:
|
if not self.started:
|
||||||
return
|
return
|
||||||
@ -159,7 +159,7 @@ class EventManager:
|
|||||||
"""Schedule async_pull_messages to run."""
|
"""Schedule async_pull_messages to run."""
|
||||||
self._unsub_refresh = async_call_later(self.hass, 1, self.async_pull_messages)
|
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."""
|
"""Pull messages from device."""
|
||||||
if self.hass.state == CoreState.running:
|
if self.hass.state == CoreState.running:
|
||||||
try:
|
try:
|
||||||
|
@ -11,11 +11,11 @@ from homeassistant.helpers.entity import EntityCategory
|
|||||||
class DeviceInfo:
|
class DeviceInfo:
|
||||||
"""Represent device information."""
|
"""Represent device information."""
|
||||||
|
|
||||||
manufacturer: str = None
|
manufacturer: str | None = None
|
||||||
model: str = None
|
model: str | None = None
|
||||||
fw_version: str = None
|
fw_version: str | None = None
|
||||||
serial_number: str = None
|
serial_number: str | None = None
|
||||||
mac: str = None
|
mac: str | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -41,7 +41,7 @@ class PTZ:
|
|||||||
continuous: bool
|
continuous: bool
|
||||||
relative: bool
|
relative: bool
|
||||||
absolute: bool
|
absolute: bool
|
||||||
presets: list[str] = None
|
presets: list[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -52,7 +52,7 @@ class Profile:
|
|||||||
token: str
|
token: str
|
||||||
name: str
|
name: str
|
||||||
video: Video
|
video: Video
|
||||||
ptz: PTZ = None
|
ptz: PTZ | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -71,8 +71,8 @@ class Event:
|
|||||||
uid: str
|
uid: str
|
||||||
name: str
|
name: str
|
||||||
platform: str
|
platform: str
|
||||||
device_class: str = None
|
device_class: str | None = None
|
||||||
unit_of_measurement: str = None
|
unit_of_measurement: str | None = None
|
||||||
value: Any = None
|
value: Any = None
|
||||||
entity_category: EntityCategory | None = None
|
entity_category: EntityCategory | None = None
|
||||||
entity_enabled: bool = True
|
entity_enabled: bool = True
|
||||||
|
@ -11,7 +11,9 @@ from homeassistant.util.decorator import Registry
|
|||||||
|
|
||||||
from .models import Event
|
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:
|
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")
|
@PARSERS.register("tns1:VideoSource/MotionAlarm")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:VideoSource/MotionAlarm
|
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/ImagingService")
|
||||||
@PARSERS.register("tns1:VideoSource/ImageTooBlurry/RecordingService")
|
@PARSERS.register("tns1:VideoSource/ImageTooBlurry/RecordingService")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:VideoSource/ImageTooBlurry/*
|
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/ImagingService")
|
||||||
@PARSERS.register("tns1:VideoSource/ImageTooDark/RecordingService")
|
@PARSERS.register("tns1:VideoSource/ImageTooDark/RecordingService")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:VideoSource/ImageTooDark/*
|
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/ImagingService")
|
||||||
@PARSERS.register("tns1:VideoSource/ImageTooBright/RecordingService")
|
@PARSERS.register("tns1:VideoSource/ImageTooBright/RecordingService")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:VideoSource/ImageTooBright/*
|
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/ImagingService")
|
||||||
@PARSERS.register("tns1:VideoSource/GlobalSceneChange/RecordingService")
|
@PARSERS.register("tns1:VideoSource/GlobalSceneChange/RecordingService")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:VideoSource/GlobalSceneChange/*
|
Topic: tns1:VideoSource/GlobalSceneChange/*
|
||||||
@ -144,7 +146,7 @@ async def async_parse_scene_change(uid: str, msg) -> Event:
|
|||||||
|
|
||||||
@PARSERS.register("tns1:AudioAnalytics/Audio/DetectedSound")
|
@PARSERS.register("tns1:AudioAnalytics/Audio/DetectedSound")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:AudioAnalytics/Audio/DetectedSound
|
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")
|
@PARSERS.register("tns1:RuleEngine/FieldDetector/ObjectsInside")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:RuleEngine/FieldDetector/ObjectsInside
|
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")
|
@PARSERS.register("tns1:RuleEngine/CellMotionDetector/Motion")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:RuleEngine/CellMotionDetector/Motion
|
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")
|
@PARSERS.register("tns1:RuleEngine/MotionRegionDetector/Motion")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:RuleEngine/MotionRegionDetector/Motion
|
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")
|
@PARSERS.register("tns1:RuleEngine/TamperDetector/Tamper")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:RuleEngine/TamperDetector/Tamper
|
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")
|
@PARSERS.register("tns1:Device/Trigger/DigitalInput")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:Device/Trigger/DigitalInput
|
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")
|
@PARSERS.register("tns1:Device/Trigger/Relay")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:Device/Trigger/Relay
|
Topic: tns1:Device/Trigger/Relay
|
||||||
@ -343,7 +345,7 @@ async def async_parse_relay(uid: str, msg) -> Event:
|
|||||||
|
|
||||||
@PARSERS.register("tns1:Device/HardwareFailure/StorageFailure")
|
@PARSERS.register("tns1:Device/HardwareFailure/StorageFailure")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:Device/HardwareFailure/StorageFailure
|
Topic: tns1:Device/HardwareFailure/StorageFailure
|
||||||
@ -365,7 +367,7 @@ async def async_parse_storage_failure(uid: str, msg) -> Event:
|
|||||||
|
|
||||||
@PARSERS.register("tns1:Monitoring/ProcessorUsage")
|
@PARSERS.register("tns1:Monitoring/ProcessorUsage")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:Monitoring/ProcessorUsage
|
Topic: tns1:Monitoring/ProcessorUsage
|
||||||
@ -390,7 +392,7 @@ async def async_parse_processor_usage(uid: str, msg) -> Event:
|
|||||||
|
|
||||||
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReboot")
|
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReboot")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastReboot
|
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")
|
@PARSERS.register("tns1:Monitoring/OperatingTime/LastReset")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastReset
|
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")
|
@PARSERS.register("tns1:Monitoring/Backup/Last")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:Monitoring/Backup/Last
|
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")
|
@PARSERS.register("tns1:Monitoring/OperatingTime/LastClockSynchronization")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:Monitoring/OperatingTime/LastClockSynchronization
|
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")
|
@PARSERS.register("tns1:RecordingConfig/JobState")
|
||||||
# pylint: disable=protected-access
|
# 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.
|
"""Handle parsing event message.
|
||||||
|
|
||||||
Topic: tns1:RecordingConfig/JobState
|
Topic: tns1:RecordingConfig/JobState
|
||||||
|
15
mypy.ini
15
mypy.ini
@ -2814,27 +2814,12 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.onvif.binary_sensor]
|
[mypy-homeassistant.components.onvif.binary_sensor]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.onvif.button]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.onvif.camera]
|
[mypy-homeassistant.components.onvif.camera]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.onvif.config_flow]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.onvif.device]
|
[mypy-homeassistant.components.onvif.device]
|
||||||
ignore_errors = true
|
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]
|
[mypy-homeassistant.components.onvif.sensor]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -87,13 +87,8 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.omnilogic.switch",
|
"homeassistant.components.omnilogic.switch",
|
||||||
"homeassistant.components.onvif.base",
|
"homeassistant.components.onvif.base",
|
||||||
"homeassistant.components.onvif.binary_sensor",
|
"homeassistant.components.onvif.binary_sensor",
|
||||||
"homeassistant.components.onvif.button",
|
|
||||||
"homeassistant.components.onvif.camera",
|
"homeassistant.components.onvif.camera",
|
||||||
"homeassistant.components.onvif.config_flow",
|
|
||||||
"homeassistant.components.onvif.device",
|
"homeassistant.components.onvif.device",
|
||||||
"homeassistant.components.onvif.event",
|
|
||||||
"homeassistant.components.onvif.models",
|
|
||||||
"homeassistant.components.onvif.parsers",
|
|
||||||
"homeassistant.components.onvif.sensor",
|
"homeassistant.components.onvif.sensor",
|
||||||
"homeassistant.components.philips_js",
|
"homeassistant.components.philips_js",
|
||||||
"homeassistant.components.philips_js.config_flow",
|
"homeassistant.components.philips_js.config_flow",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user