Skip to content

Commit

Permalink
Merge branch 'dev' into intellifire_udp_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeftor authored Oct 15, 2022
2 parents 3fef8c4 + 3460e0b commit 356a38f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
23 changes: 13 additions & 10 deletions homeassistant/components/aqualogic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Support for AquaLogic devices."""
from __future__ import annotations

from datetime import timedelta
import logging
import threading
Expand All @@ -13,7 +15,7 @@
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
Expand Down Expand Up @@ -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
Expand All @@ -59,27 +61,28 @@ def __init__(self, hass, host, port):
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
Expand All @@ -88,6 +91,6 @@ def run(self):
time.sleep(RECONNECT_INTERVAL.total_seconds())

@property
def panel(self):
def panel(self) -> AquaLogic | None:
"""Retrieve the AquaLogic object."""
return self._panel
12 changes: 8 additions & 4 deletions homeassistant/components/aqualogic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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
Expand Down Expand Up @@ -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 = [
Expand All @@ -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
Expand All @@ -153,7 +157,7 @@ async def async_added_to_hass(self) -> None:
)

@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:
Expand Down
11 changes: 5 additions & 6 deletions homeassistant/components/aqualogic/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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",
Expand Down Expand Up @@ -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))

Expand All @@ -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 = {
Expand All @@ -77,12 +77,11 @@ def __init__(self, processor, switch_type):
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."""
Expand Down
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 356a38f

Please sign in to comment.