mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Enable strict typing of homeworks (#112267)
This commit is contained in:
@ -228,6 +228,7 @@ homeassistant.components.homekit_controller.select
|
||||
homeassistant.components.homekit_controller.storage
|
||||
homeassistant.components.homekit_controller.utils
|
||||
homeassistant.components.homewizard.*
|
||||
homeassistant.components.homeworks.*
|
||||
homeassistant.components.http.*
|
||||
homeassistant.components.huawei_lte.*
|
||||
homeassistant.components.humidifier.*
|
||||
|
@ -17,7 +17,7 @@ from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||
@ -118,7 +118,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
except (ConnectionError, OSError) as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
|
||||
def cleanup(event):
|
||||
def cleanup(event: Event) -> None:
|
||||
controller.close()
|
||||
|
||||
entry.async_on_unload(hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, cleanup))
|
||||
@ -158,7 +158,7 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
|
||||
def calculate_unique_id(controller_id, addr, idx):
|
||||
def calculate_unique_id(controller_id: str, addr: str, idx: int) -> str:
|
||||
"""Calculate entity unique id."""
|
||||
return f"homeworks.{controller_id}.{addr}.{idx}"
|
||||
|
||||
@ -194,7 +194,14 @@ class HomeworksKeypad:
|
||||
instead of a sensor entity in hass.
|
||||
"""
|
||||
|
||||
def __init__(self, hass, controller, controller_id, addr, name):
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
controller: Homeworks,
|
||||
controller_id: str,
|
||||
addr: str,
|
||||
name: str,
|
||||
) -> None:
|
||||
"""Register callback that will be used for signals."""
|
||||
self._addr = addr
|
||||
self._controller = controller
|
||||
@ -208,7 +215,7 @@ class HomeworksKeypad:
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_callback(self, msg_type, values):
|
||||
def _update_callback(self, msg_type: str, values: list[Any]) -> None:
|
||||
"""Fire events if button is pressed or released."""
|
||||
|
||||
if msg_type == HW_BUTTON_PRESSED:
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from pyhomeworks.pyhomeworks import HW_LIGHT_CHANGED
|
||||
from pyhomeworks.pyhomeworks import HW_LIGHT_CHANGED, Homeworks
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -47,12 +47,12 @@ class HomeworksLight(HomeworksEntity, LightEntity):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
controller,
|
||||
controller_id,
|
||||
addr,
|
||||
name,
|
||||
rate,
|
||||
):
|
||||
controller: Homeworks,
|
||||
controller_id: str,
|
||||
addr: str,
|
||||
name: str,
|
||||
rate: float,
|
||||
) -> None:
|
||||
"""Create device with Addr, name, and rate."""
|
||||
super().__init__(controller, controller_id, addr, 0, name)
|
||||
self._rate = rate
|
||||
@ -83,28 +83,28 @@ class HomeworksLight(HomeworksEntity, LightEntity):
|
||||
self._set_brightness(0)
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
def brightness(self) -> int:
|
||||
"""Control the brightness."""
|
||||
return self._level
|
||||
|
||||
def _set_brightness(self, level):
|
||||
def _set_brightness(self, level: int) -> None:
|
||||
"""Send the brightness level to the device."""
|
||||
self._controller.fade_dim(
|
||||
float((level * 100.0) / 255.0), self._rate, 0, self._addr
|
||||
)
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
def extra_state_attributes(self) -> dict[str, str]:
|
||||
"""Supported attributes."""
|
||||
return {"homeworks_address": self._addr}
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Is the light on/off."""
|
||||
return self._level != 0
|
||||
|
||||
@callback
|
||||
def _update_callback(self, msg_type, values):
|
||||
def _update_callback(self, msg_type: str, values: list[Any]) -> None:
|
||||
"""Process device specific messages."""
|
||||
|
||||
if msg_type == HW_LIGHT_CHANGED:
|
||||
|
10
mypy.ini
10
mypy.ini
@ -2041,6 +2041,16 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homeworks.*]
|
||||
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.http.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
Reference in New Issue
Block a user