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