mirror of https://github.com/home-assistant/core
Add strict type annotations to aladdin_connect (#50693)
* add strict type annotations * add missing return type annotation
This commit is contained in:
parent
bc006c9ecc
commit
7f6b8bbd1e
|
@ -35,7 +35,7 @@ omit =
|
|||
homeassistant/components/airvisual/__init__.py
|
||||
homeassistant/components/airvisual/air_quality.py
|
||||
homeassistant/components/airvisual/sensor.py
|
||||
homeassistant/components/aladdin_connect/cover.py
|
||||
homeassistant/components/aladdin_connect/*
|
||||
homeassistant/components/alarmdecoder/__init__.py
|
||||
homeassistant/components/alarmdecoder/alarm_control_panel.py
|
||||
homeassistant/components/alarmdecoder/binary_sensor.py
|
||||
|
|
|
@ -6,6 +6,7 @@ homeassistant.components
|
|||
homeassistant.components.acer_projector.*
|
||||
homeassistant.components.aftership.*
|
||||
homeassistant.components.airly.*
|
||||
homeassistant.components.aladdin_connect.*
|
||||
homeassistant.components.automation.*
|
||||
homeassistant.components.binary_sensor.*
|
||||
homeassistant.components.bond.*
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
"""Platform for the Aladdin Connect cover component."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.components.cover import SUPPORT_CLOSE, SUPPORT_OPEN
|
||||
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING
|
||||
|
||||
NOTIFICATION_ID: Final = "aladdin_notification"
|
||||
NOTIFICATION_TITLE: Final = "Aladdin Connect Cover Setup"
|
||||
|
||||
STATES_MAP: Final[dict[str, str]] = {
|
||||
"open": STATE_OPEN,
|
||||
"opening": STATE_OPENING,
|
||||
"closed": STATE_CLOSED,
|
||||
"closing": STATE_CLOSING,
|
||||
}
|
||||
|
||||
SUPPORTED_FEATURES: Final = SUPPORT_OPEN | SUPPORT_CLOSE
|
|
@ -1,13 +1,14 @@
|
|||
"""Platform for the Aladdin Connect cover component."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any, Final
|
||||
|
||||
from aladdin_connect import AladdinConnectClient
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_CLOSE,
|
||||
SUPPORT_OPEN,
|
||||
PLATFORM_SCHEMA as BASE_PLATFORM_SCHEMA,
|
||||
CoverEntity,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
|
@ -15,35 +16,33 @@ from homeassistant.const import (
|
|||
CONF_USERNAME,
|
||||
STATE_CLOSED,
|
||||
STATE_CLOSING,
|
||||
STATE_OPEN,
|
||||
STATE_OPENING,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
from .const import NOTIFICATION_ID, NOTIFICATION_TITLE, STATES_MAP, SUPPORTED_FEATURES
|
||||
from .model import DoorDevice
|
||||
|
||||
NOTIFICATION_ID = "aladdin_notification"
|
||||
NOTIFICATION_TITLE = "Aladdin Connect Cover Setup"
|
||||
_LOGGER: Final = logging.getLogger(__name__)
|
||||
|
||||
STATES_MAP = {
|
||||
"open": STATE_OPEN,
|
||||
"opening": STATE_OPENING,
|
||||
"closed": STATE_CLOSED,
|
||||
"closing": STATE_CLOSING,
|
||||
}
|
||||
|
||||
SUPPORTED_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
PLATFORM_SCHEMA: Final = BASE_PLATFORM_SCHEMA.extend(
|
||||
{vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
def setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Aladdin Connect platform."""
|
||||
|
||||
username = config[CONF_USERNAME]
|
||||
password = config[CONF_PASSWORD]
|
||||
username: str = config[CONF_USERNAME]
|
||||
password: str = config[CONF_PASSWORD]
|
||||
acc = AladdinConnectClient(username, password)
|
||||
|
||||
try:
|
||||
|
@ -62,7 +61,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
class AladdinDevice(CoverEntity):
|
||||
"""Representation of Aladdin Connect cover."""
|
||||
|
||||
def __init__(self, acc, device):
|
||||
def __init__(self, acc: AladdinConnectClient, device: DoorDevice) -> None:
|
||||
"""Initialize the cover."""
|
||||
self._acc = acc
|
||||
self._device_id = device["device_id"]
|
||||
|
@ -71,51 +70,51 @@ class AladdinDevice(CoverEntity):
|
|||
self._status = STATES_MAP.get(device["status"])
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
def device_class(self) -> str:
|
||||
"""Define this cover as a garage door."""
|
||||
return "garage"
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
def supported_features(self) -> int:
|
||||
"""Flag supported features."""
|
||||
return SUPPORTED_FEATURES
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return f"{self._device_id}-{self._number}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Return the name of the garage door."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_opening(self):
|
||||
def is_opening(self) -> bool:
|
||||
"""Return if the cover is opening or not."""
|
||||
return self._status == STATE_OPENING
|
||||
|
||||
@property
|
||||
def is_closing(self):
|
||||
def is_closing(self) -> bool:
|
||||
"""Return if the cover is closing or not."""
|
||||
return self._status == STATE_CLOSING
|
||||
|
||||
@property
|
||||
def is_closed(self):
|
||||
def is_closed(self) -> bool | None:
|
||||
"""Return None if status is unknown, True if closed, else False."""
|
||||
if self._status is None:
|
||||
return None
|
||||
return self._status == STATE_CLOSED
|
||||
|
||||
def close_cover(self, **kwargs):
|
||||
def close_cover(self, **kwargs: Any) -> None:
|
||||
"""Issue close command to cover."""
|
||||
self._acc.close_door(self._device_id, self._number)
|
||||
|
||||
def open_cover(self, **kwargs):
|
||||
def open_cover(self, **kwargs: Any) -> None:
|
||||
"""Issue open command to cover."""
|
||||
self._acc.open_door(self._device_id, self._number)
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update status of cover."""
|
||||
acc_status = self._acc.get_door_status(self._device_id, self._number)
|
||||
self._status = STATES_MAP.get(acc_status)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
"""Models for Aladdin connect cover platform."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
class DoorDevice(TypedDict):
|
||||
"""Aladdin door device."""
|
||||
|
||||
device_id: str
|
||||
door_number: int
|
||||
name: str
|
||||
status: str
|
11
mypy.ini
11
mypy.ini
|
@ -77,6 +77,17 @@ no_implicit_optional = true
|
|||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.aladdin_connect.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
no_implicit_optional = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.automation.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
|
Loading…
Reference in New Issue