Skip to content

Commit

Permalink
Add typing to poolsense (home-assistant#100984)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede authored Sep 27, 2023
1 parent 43954d6 commit 134c005
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ homeassistant.components.persistent_notification.*
homeassistant.components.pi_hole.*
homeassistant.components.ping.*
homeassistant.components.plugwise.*
homeassistant.components.poolsense.*
homeassistant.components.powerwall.*
homeassistant.components.private_ble_device.*
homeassistant.components.proximity.*
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/poolsense/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ class PoolSenseBinarySensor(PoolSenseEntity, BinarySensorEntity):
"""Representation of PoolSense binary sensors."""

@property
def is_on(self):
def is_on(self) -> bool:
"""Return true if the binary sensor is on."""
return self.coordinator.data[self.entity_description.key] == "red"
6 changes: 5 additions & 1 deletion homeassistant/components/poolsense/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Config flow for PoolSense integration."""
import logging
from typing import Any

from poolsense import PoolSense
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import aiohttp_client

from .const import DOMAIN
Expand All @@ -21,7 +23,9 @@ class PoolSenseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
def __init__(self) -> None:
"""Initialize PoolSense config flow."""

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the initial step."""
errors = {}

Expand Down
10 changes: 6 additions & 4 deletions homeassistant/components/poolsense/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@
from poolsense import PoolSense
from poolsense.exceptions import PoolSenseError

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)


class PoolSenseDataUpdateCoordinator(DataUpdateCoordinator):
class PoolSenseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, StateType]]):
"""Define an object to hold PoolSense data."""

def __init__(self, hass, entry):
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Initialize."""
self.poolsense = PoolSense(
aiohttp_client.async_get_clientsession(hass),
entry.data[CONF_EMAIL],
entry.data[CONF_PASSWORD],
)
self.hass = hass
self.entry = entry

super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=timedelta(hours=1))

async def _async_update_data(self):
async def _async_update_data(self) -> dict[str, StateType]:
"""Update data via library."""
data = {}
async with asyncio.timeout(10):
Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/poolsense/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import ATTRIBUTION
from .coordinator import PoolSenseDataUpdateCoordinator


class PoolSenseEntity(CoordinatorEntity):
class PoolSenseEntity(CoordinatorEntity[PoolSenseDataUpdateCoordinator]):
"""Implements a common class elements representing the PoolSense component."""

_attr_attribution = ATTRIBUTION

def __init__(self, coordinator, email, description: EntityDescription) -> None:
def __init__(
self,
coordinator: PoolSenseDataUpdateCoordinator,
email: str,
description: EntityDescription,
) -> None:
"""Initialize poolsense sensor."""
super().__init__(coordinator)
self.entity_description = description
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/poolsense/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType

from .const import DOMAIN
from .entity import PoolSenseEntity
Expand Down Expand Up @@ -93,6 +94,6 @@ class PoolSenseSensor(PoolSenseEntity, SensorEntity):
"""Sensor representing poolsense data."""

@property
def native_value(self):
def native_value(self) -> StateType:
"""State of the sensor."""
return self.coordinator.data[self.entity_description.key]
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true

[mypy-homeassistant.components.poolsense.*]
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.powerwall.*]
check_untyped_defs = true
disallow_incomplete_defs = true
Expand Down

0 comments on commit 134c005

Please sign in to comment.