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