Improve hydrawise typing (#93503)

* Improve hydrawise generic typing

* Enable strict typing

* Remove unused code
This commit is contained in:
Marc Mueller 2023-05-25 07:58:59 +02:00 committed by GitHub
parent f8d918ca4a
commit 64118ee011
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 18 deletions

View File

@ -169,6 +169,7 @@ homeassistant.components.homekit_controller.utils
homeassistant.components.homewizard.*
homeassistant.components.http.*
homeassistant.components.huawei_lte.*
homeassistant.components.hydrawise.*
homeassistant.components.hyperion.*
homeassistant.components.ibeacon.*
homeassistant.components.image_processing.*

View File

@ -53,18 +53,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
return True
def _show_failure_notification(hass: HomeAssistant, error: str):
def _show_failure_notification(hass: HomeAssistant, error: str) -> None:
persistent_notification.create(
hass,
f"Error: {error}<br />You will need to restart hass after fixing.",
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID,
)
class HydrawiseHub:
"""Representation of a base Hydrawise device."""
def __init__(self, data):
"""Initialize the entity."""
self.data = data

View File

@ -1,15 +1,15 @@
"""Base classes for Hydrawise entities."""
from __future__ import annotations
from typing import Any
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .coordinator import HydrawiseDataUpdateCoordinator
class HydrawiseEntity(CoordinatorEntity):
class HydrawiseEntity(CoordinatorEntity[HydrawiseDataUpdateCoordinator]):
"""Entity class for Hydrawise devices."""
_attr_attribution = "Data provided by hydrawise.com"
@ -18,7 +18,7 @@ class HydrawiseEntity(CoordinatorEntity):
self,
*,
data: dict[str, Any],
coordinator: DataUpdateCoordinator,
coordinator: HydrawiseDataUpdateCoordinator,
description: EntityDescription,
) -> None:
"""Initialize the Hydrawise entity."""
@ -28,6 +28,6 @@ class HydrawiseEntity(CoordinatorEntity):
self._attr_name = f"{self.data['name']} {description.name}"
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {"identifier": self.data.get("relay")}

View File

@ -17,7 +17,6 @@ from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import (
ALLOWED_WATERING_TIME,
@ -90,7 +89,7 @@ class HydrawiseSwitch(HydrawiseEntity, SwitchEntity):
self,
*,
data: dict[str, Any],
coordinator: DataUpdateCoordinator,
coordinator: HydrawiseDataUpdateCoordinator,
description: SwitchEntityDescription,
default_watering_timer: int,
) -> None:

View File

@ -1452,6 +1452,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.hydrawise.*]
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.hyperion.*]
check_untyped_defs = true
disallow_incomplete_defs = true