mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Add type hints to aqualogic (#80328)
This commit is contained in:
@ -57,6 +57,7 @@ homeassistant.components.ambient_station.*
|
||||
homeassistant.components.amcrest.*
|
||||
homeassistant.components.ampio.*
|
||||
homeassistant.components.anthemav.*
|
||||
homeassistant.components.aqualogic.*
|
||||
homeassistant.components.aseko_pool_live.*
|
||||
homeassistant.components.asuswrt.*
|
||||
homeassistant.components.auth.*
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Support for AquaLogic devices."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import threading
|
||||
@ -13,7 +15,7 @@ from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
@ -50,7 +52,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
class AquaLogicProcessor(threading.Thread):
|
||||
"""AquaLogic event processor thread."""
|
||||
|
||||
def __init__(self, hass, host, port):
|
||||
def __init__(self, hass: HomeAssistant, host: str, port: int) -> None:
|
||||
"""Initialize the data object."""
|
||||
super().__init__(daemon=True)
|
||||
self._hass = hass
|
||||
@ -59,27 +61,28 @@ class AquaLogicProcessor(threading.Thread):
|
||||
self._shutdown = False
|
||||
self._panel = None
|
||||
|
||||
def start_listen(self, event):
|
||||
def start_listen(self, event: Event) -> None:
|
||||
"""Start event-processing thread."""
|
||||
_LOGGER.debug("Event processing thread started")
|
||||
self.start()
|
||||
|
||||
def shutdown(self, event):
|
||||
def shutdown(self, event: Event) -> None:
|
||||
"""Signal shutdown of processing event."""
|
||||
_LOGGER.debug("Event processing signaled exit")
|
||||
self._shutdown = True
|
||||
|
||||
def data_changed(self, panel):
|
||||
def data_changed(self, panel: AquaLogic) -> None:
|
||||
"""Aqualogic data changed callback."""
|
||||
dispatcher_send(self._hass, UPDATE_TOPIC)
|
||||
|
||||
def run(self):
|
||||
def run(self) -> None:
|
||||
"""Event thread."""
|
||||
|
||||
while True:
|
||||
self._panel = AquaLogic()
|
||||
self._panel.connect(self._host, self._port)
|
||||
self._panel.process(self.data_changed)
|
||||
panel = AquaLogic()
|
||||
self._panel = panel
|
||||
panel.connect(self._host, self._port)
|
||||
panel.process(self.data_changed)
|
||||
|
||||
if self._shutdown:
|
||||
return
|
||||
@ -88,6 +91,6 @@ class AquaLogicProcessor(threading.Thread):
|
||||
time.sleep(RECONNECT_INTERVAL.total_seconds())
|
||||
|
||||
@property
|
||||
def panel(self):
|
||||
def panel(self) -> AquaLogic | None:
|
||||
"""Retrieve the AquaLogic object."""
|
||||
return self._panel
|
||||
|
@ -24,7 +24,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, UPDATE_TOPIC
|
||||
from . import DOMAIN, UPDATE_TOPIC, AquaLogicProcessor
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -120,7 +120,7 @@ async def async_setup_platform(
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the sensor platform."""
|
||||
processor = hass.data[DOMAIN]
|
||||
processor: AquaLogicProcessor = hass.data[DOMAIN]
|
||||
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
||||
|
||||
entities = [
|
||||
@ -138,7 +138,11 @@ class AquaLogicSensor(SensorEntity):
|
||||
entity_description: AquaLogicSensorEntityDescription
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, processor, description: AquaLogicSensorEntityDescription):
|
||||
def __init__(
|
||||
self,
|
||||
processor: AquaLogicProcessor,
|
||||
description: AquaLogicSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize sensor."""
|
||||
self.entity_description = description
|
||||
self._processor = processor
|
||||
@ -153,7 +157,7 @@ class AquaLogicSensor(SensorEntity):
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_callback(self):
|
||||
def async_update_callback(self) -> None:
|
||||
"""Update callback."""
|
||||
if (panel := self._processor.panel) is not None:
|
||||
if panel.is_metric:
|
||||
|
@ -14,7 +14,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, UPDATE_TOPIC
|
||||
from . import DOMAIN, UPDATE_TOPIC, AquaLogicProcessor
|
||||
|
||||
SWITCH_TYPES = {
|
||||
"lights": "Lights",
|
||||
@ -47,7 +47,7 @@ async def async_setup_platform(
|
||||
"""Set up the switch platform."""
|
||||
switches = []
|
||||
|
||||
processor = hass.data[DOMAIN]
|
||||
processor: AquaLogicProcessor = hass.data[DOMAIN]
|
||||
for switch_type in config[CONF_MONITORED_CONDITIONS]:
|
||||
switches.append(AquaLogicSwitch(processor, switch_type))
|
||||
|
||||
@ -59,7 +59,7 @@ class AquaLogicSwitch(SwitchEntity):
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, processor, switch_type):
|
||||
def __init__(self, processor: AquaLogicProcessor, switch_type: str) -> None:
|
||||
"""Initialize switch."""
|
||||
self._processor = processor
|
||||
self._state_name = {
|
||||
@ -77,12 +77,11 @@ class AquaLogicSwitch(SwitchEntity):
|
||||
self._attr_name = f"AquaLogic {SWITCH_TYPES[switch_type]}"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if device is on."""
|
||||
if (panel := self._processor.panel) is None:
|
||||
return False
|
||||
state = panel.get_state(self._state_name)
|
||||
return state
|
||||
return panel.get_state(self._state_name) # type: ignore[no-any-return]
|
||||
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
|
10
mypy.ini
10
mypy.ini
@ -322,6 +322,16 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.aqualogic.*]
|
||||
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.aseko_pool_live.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
Reference in New Issue
Block a user