mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add typing to poolsense (#100984)
This commit is contained in:
parent
43954d660b
commit
134c005168
@ -261,6 +261,7 @@ homeassistant.components.persistent_notification.*
|
|||||||
homeassistant.components.pi_hole.*
|
homeassistant.components.pi_hole.*
|
||||||
homeassistant.components.ping.*
|
homeassistant.components.ping.*
|
||||||
homeassistant.components.plugwise.*
|
homeassistant.components.plugwise.*
|
||||||
|
homeassistant.components.poolsense.*
|
||||||
homeassistant.components.powerwall.*
|
homeassistant.components.powerwall.*
|
||||||
homeassistant.components.private_ble_device.*
|
homeassistant.components.private_ble_device.*
|
||||||
homeassistant.components.proximity.*
|
homeassistant.components.proximity.*
|
||||||
|
@ -48,6 +48,6 @@ class PoolSenseBinarySensor(PoolSenseEntity, BinarySensorEntity):
|
|||||||
"""Representation of PoolSense binary sensors."""
|
"""Representation of PoolSense binary sensors."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return true if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return self.coordinator.data[self.entity_description.key] == "red"
|
return self.coordinator.data[self.entity_description.key] == "red"
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
"""Config flow for PoolSense integration."""
|
"""Config flow for PoolSense integration."""
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from poolsense import PoolSense
|
from poolsense import PoolSense
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -21,7 +23,9 @@ class PoolSenseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize PoolSense config flow."""
|
"""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."""
|
"""Handle the initial step."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
|
@ -6,8 +6,11 @@ import logging
|
|||||||
from poolsense import PoolSense
|
from poolsense import PoolSense
|
||||||
from poolsense.exceptions import PoolSenseError
|
from poolsense.exceptions import PoolSenseError
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -15,10 +18,10 @@ from .const import DOMAIN
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PoolSenseDataUpdateCoordinator(DataUpdateCoordinator):
|
class PoolSenseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, StateType]]):
|
||||||
"""Define an object to hold PoolSense data."""
|
"""Define an object to hold PoolSense data."""
|
||||||
|
|
||||||
def __init__(self, hass, entry):
|
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.poolsense = PoolSense(
|
self.poolsense = PoolSense(
|
||||||
aiohttp_client.async_get_clientsession(hass),
|
aiohttp_client.async_get_clientsession(hass),
|
||||||
@ -26,11 +29,10 @@ class PoolSenseDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
entry.data[CONF_PASSWORD],
|
entry.data[CONF_PASSWORD],
|
||||||
)
|
)
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.entry = entry
|
|
||||||
|
|
||||||
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=timedelta(hours=1))
|
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."""
|
"""Update data via library."""
|
||||||
data = {}
|
data = {}
|
||||||
async with asyncio.timeout(10):
|
async with asyncio.timeout(10):
|
||||||
|
@ -3,14 +3,20 @@ from homeassistant.helpers.entity import EntityDescription
|
|||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import ATTRIBUTION
|
from .const import ATTRIBUTION
|
||||||
|
from .coordinator import PoolSenseDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
class PoolSenseEntity(CoordinatorEntity):
|
class PoolSenseEntity(CoordinatorEntity[PoolSenseDataUpdateCoordinator]):
|
||||||
"""Implements a common class elements representing the PoolSense component."""
|
"""Implements a common class elements representing the PoolSense component."""
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
|
|
||||||
def __init__(self, coordinator, email, description: EntityDescription) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: PoolSenseDataUpdateCoordinator,
|
||||||
|
email: str,
|
||||||
|
description: EntityDescription,
|
||||||
|
) -> None:
|
||||||
"""Initialize poolsense sensor."""
|
"""Initialize poolsense sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .entity import PoolSenseEntity
|
from .entity import PoolSenseEntity
|
||||||
@ -93,6 +94,6 @@ class PoolSenseSensor(PoolSenseEntity, SensorEntity):
|
|||||||
"""Sensor representing poolsense data."""
|
"""Sensor representing poolsense data."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self) -> StateType:
|
||||||
"""State of the sensor."""
|
"""State of the sensor."""
|
||||||
return self.coordinator.data[self.entity_description.key]
|
return self.coordinator.data[self.entity_description.key]
|
||||||
|
10
mypy.ini
10
mypy.ini
@ -2372,6 +2372,16 @@ disallow_untyped_defs = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = 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.*]
|
[mypy-homeassistant.components.powerwall.*]
|
||||||
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