Static typing for Zodiac (#51622)

This commit is contained in:
Yuval Aboulafia 2021-06-08 17:03:28 +03:00 committed by GitHub
parent 6de604a326
commit 7790e8f90c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 13 deletions

View file

@ -74,6 +74,7 @@ homeassistant.components.vacuum.*
homeassistant.components.water_heater.* homeassistant.components.water_heater.*
homeassistant.components.weather.* homeassistant.components.weather.*
homeassistant.components.websocket_api.* homeassistant.components.websocket_api.*
homeassistant.components.zodiac.*
homeassistant.components.zeroconf.* homeassistant.components.zeroconf.*
homeassistant.components.zone.* homeassistant.components.zone.*
homeassistant.components.zwave_js.* homeassistant.components.zwave_js.*

View file

@ -3,6 +3,7 @@ import voluptuous as vol
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN from .const import DOMAIN
@ -12,7 +13,7 @@ CONFIG_SCHEMA = vol.Schema(
) )
async def async_setup(hass: HomeAssistant, config: dict): async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the zodiac component.""" """Set up the zodiac component."""
hass.async_create_task(async_load_platform(hass, "sensor", DOMAIN, {}, config)) hass.async_create_task(async_load_platform(hass, "sensor", DOMAIN, {}, config))

View file

@ -1,5 +1,10 @@
"""Support for tracking the zodiac sign.""" """Support for tracking the zodiac sign."""
from __future__ import annotations
from homeassistant.components.sensor import SensorEntity from homeassistant.components.sensor import SensorEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util.dt import as_local, utcnow from homeassistant.util.dt import as_local, utcnow
from .const import ( from .const import (
@ -154,7 +159,12 @@ ZODIAC_ICONS = {
} }
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Zodiac sensor platform.""" """Set up the Zodiac sensor platform."""
if discovery_info is None: if discovery_info is None:
return return
@ -165,42 +175,42 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
class ZodiacSensor(SensorEntity): class ZodiacSensor(SensorEntity):
"""Representation of a Zodiac sensor.""" """Representation of a Zodiac sensor."""
def __init__(self): def __init__(self) -> None:
"""Initialize the zodiac sensor.""" """Initialize the zodiac sensor."""
self._attrs = None self._attrs: dict[str, str] = {}
self._state = None self._state: str = ""
@property @property
def unique_id(self): def unique_id(self) -> str:
"""Return a unique ID.""" """Return a unique ID."""
return DOMAIN return DOMAIN
@property @property
def name(self): def name(self) -> str:
"""Return the name of the entity.""" """Return the name of the entity."""
return "Zodiac" return "Zodiac"
@property @property
def device_class(self): def device_class(self) -> str:
"""Return the device class of the entity.""" """Return the device class of the entity."""
return "zodiac__sign" return "zodiac__sign"
@property @property
def state(self): def state(self) -> str:
"""Return the state of the device.""" """Return the state of the device."""
return self._state return self._state
@property @property
def icon(self): def icon(self) -> str | None:
"""Icon to use in the frontend, if any.""" """Icon to use in the frontend."""
return ZODIAC_ICONS.get(self._state) return ZODIAC_ICONS.get(self._state)
@property @property
def extra_state_attributes(self): def extra_state_attributes(self) -> dict[str, str]:
"""Return the state attributes.""" """Return the state attributes."""
return self._attrs return self._attrs
async def async_update(self): async def async_update(self) -> None:
"""Get the time and updates the state.""" """Get the time and updates the state."""
today = as_local(utcnow()).date() today = as_local(utcnow()).date()

View file

@ -825,6 +825,17 @@ no_implicit_optional = true
warn_return_any = true warn_return_any = true
warn_unreachable = true warn_unreachable = true
[mypy-homeassistant.components.zodiac.*]
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.zeroconf.*] [mypy-homeassistant.components.zeroconf.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true