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