mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Enable strict typing for axis (#106844)
This commit is contained in:
parent
e1f078b70a
commit
1526c321f1
@ -94,6 +94,7 @@ homeassistant.components.asuswrt.*
|
||||
homeassistant.components.auth.*
|
||||
homeassistant.components.automation.*
|
||||
homeassistant.components.awair.*
|
||||
homeassistant.components.axis.*
|
||||
homeassistant.components.backup.*
|
||||
homeassistant.components.baf.*
|
||||
homeassistant.components.bayesian.*
|
||||
|
@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from datetime import timedelta
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from axis.models.event import Event, EventGroup, EventOperation, EventTopic
|
||||
|
||||
@ -81,7 +81,7 @@ class AxisBinarySensor(AxisEventEntity, BinarySensorEntity):
|
||||
self._attr_is_on = event.is_tripped
|
||||
|
||||
@callback
|
||||
def scheduled_update(now):
|
||||
def scheduled_update(now: datetime) -> None:
|
||||
"""Timer callback for sensor update."""
|
||||
self.cancel_scheduled_update = None
|
||||
self.async_write_ha_state()
|
||||
|
@ -24,7 +24,7 @@ from homeassistant.const import (
|
||||
CONF_TRIGGER_TIME,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
@ -65,80 +65,87 @@ class AxisNetworkDevice:
|
||||
self.additional_diagnostics: dict[str, Any] = {}
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
def host(self) -> str:
|
||||
"""Return the host address of this device."""
|
||||
return self.config_entry.data[CONF_HOST]
|
||||
host: str = self.config_entry.data[CONF_HOST]
|
||||
return host
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
def port(self) -> int:
|
||||
"""Return the HTTP port of this device."""
|
||||
return self.config_entry.data[CONF_PORT]
|
||||
port: int = self.config_entry.data[CONF_PORT]
|
||||
return port
|
||||
|
||||
@property
|
||||
def username(self):
|
||||
def username(self) -> str:
|
||||
"""Return the username of this device."""
|
||||
return self.config_entry.data[CONF_USERNAME]
|
||||
username: str = self.config_entry.data[CONF_USERNAME]
|
||||
return username
|
||||
|
||||
@property
|
||||
def password(self):
|
||||
def password(self) -> str:
|
||||
"""Return the password of this device."""
|
||||
return self.config_entry.data[CONF_PASSWORD]
|
||||
password: str = self.config_entry.data[CONF_PASSWORD]
|
||||
return password
|
||||
|
||||
@property
|
||||
def model(self):
|
||||
def model(self) -> str:
|
||||
"""Return the model of this device."""
|
||||
return self.config_entry.data[CONF_MODEL]
|
||||
model: str = self.config_entry.data[CONF_MODEL]
|
||||
return model
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Return the name of this device."""
|
||||
return self.config_entry.data[CONF_NAME]
|
||||
name: str = self.config_entry.data[CONF_NAME]
|
||||
return name
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
def unique_id(self) -> str:
|
||||
"""Return the unique ID (serial number) of this device."""
|
||||
return self.config_entry.unique_id
|
||||
assert (unique_id := self.config_entry.unique_id)
|
||||
return unique_id
|
||||
|
||||
# Options
|
||||
|
||||
@property
|
||||
def option_events(self):
|
||||
def option_events(self) -> bool:
|
||||
"""Config entry option defining if platforms based on events should be created."""
|
||||
return self.config_entry.options.get(CONF_EVENTS, DEFAULT_EVENTS)
|
||||
|
||||
@property
|
||||
def option_stream_profile(self):
|
||||
def option_stream_profile(self) -> str:
|
||||
"""Config entry option defining what stream profile camera platform should use."""
|
||||
return self.config_entry.options.get(
|
||||
CONF_STREAM_PROFILE, DEFAULT_STREAM_PROFILE
|
||||
)
|
||||
|
||||
@property
|
||||
def option_trigger_time(self):
|
||||
def option_trigger_time(self) -> int:
|
||||
"""Config entry option defining minimum number of seconds to keep trigger high."""
|
||||
return self.config_entry.options.get(CONF_TRIGGER_TIME, DEFAULT_TRIGGER_TIME)
|
||||
|
||||
@property
|
||||
def option_video_source(self):
|
||||
def option_video_source(self) -> str:
|
||||
"""Config entry option defining what video source camera platform should use."""
|
||||
return self.config_entry.options.get(CONF_VIDEO_SOURCE, DEFAULT_VIDEO_SOURCE)
|
||||
|
||||
# Signals
|
||||
|
||||
@property
|
||||
def signal_reachable(self):
|
||||
def signal_reachable(self) -> str:
|
||||
"""Device specific event to signal a change in connection status."""
|
||||
return f"axis_reachable_{self.unique_id}"
|
||||
|
||||
@property
|
||||
def signal_new_address(self):
|
||||
def signal_new_address(self) -> str:
|
||||
"""Device specific event to signal a change in device address."""
|
||||
return f"axis_new_address_{self.unique_id}"
|
||||
|
||||
# Callbacks
|
||||
|
||||
@callback
|
||||
def async_connection_status_callback(self, status):
|
||||
def async_connection_status_callback(self, status: Signal) -> None:
|
||||
"""Handle signals of device connection status.
|
||||
|
||||
This is called on every RTSP keep-alive message.
|
||||
@ -202,7 +209,7 @@ class AxisNetworkDevice:
|
||||
|
||||
# Setup and teardown methods
|
||||
|
||||
def async_setup_events(self):
|
||||
def async_setup_events(self) -> None:
|
||||
"""Set up the device events."""
|
||||
|
||||
if self.option_events:
|
||||
@ -222,7 +229,7 @@ class AxisNetworkDevice:
|
||||
self.api.stream.connection_status_callback.clear()
|
||||
self.api.stream.stop()
|
||||
|
||||
async def shutdown(self, event) -> None:
|
||||
async def shutdown(self, event: Event) -> None:
|
||||
"""Stop the event stream."""
|
||||
self.disconnect_from_stream()
|
||||
|
||||
|
10
mypy.ini
10
mypy.ini
@ -700,6 +700,16 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.axis.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.backup.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user