Skip to content

Commit

Permalink
0.25.0 (#737)
Browse files Browse the repository at this point in the history
* Add force clients update (#718)

* Use new `async_set_state` scheme of `asusrouter` (#733)

* Bump asusrouter to `1.4.0`

* Bump version to `0.25.0`
  • Loading branch information
Vaskivskyi authored Dec 21, 2023
1 parent 96c2772 commit 370b66e
Show file tree
Hide file tree
Showing 20 changed files with 739 additions and 649 deletions.
10 changes: 7 additions & 3 deletions custom_components/asusrouter/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,27 @@ async def async_press(
) -> None:
"""Press button."""

kwargs = self._state_args if self._state_args is not None else {}

await self._set_state(
state=self._state,
arguments=self._state_args,
expect_modify=self._state_expect_modify,
**kwargs,
)

async def _set_state(
self,
state: AsusState,
arguments: Optional[dict[str, Any]] = None,
expect_modify: bool = False,
**kwargs: Any,
) -> None:
"""Set switch state."""

try:
_LOGGER.debug("Pressing %s", state)
result = await self.api.async_set_state(state, arguments, expect_modify)
result = await self.api.async_set_state(
state=state, expect_modify=expect_modify, **kwargs
)
if not result:
_LOGGER.debug("Didn't manage to press %s", state)
except Exception as ex: # pylint: disable=broad-except
Expand Down
14 changes: 14 additions & 0 deletions custom_components/asusrouter/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
CONF_DEFAULT_CACHE_TIME,
CONF_DEFAULT_CONSIDER_HOME,
CONF_DEFAULT_EVENT,
CONF_DEFAULT_FORCE_CLIENTS,
CONF_DEFAULT_FORCE_CLIENTS_WAITTIME,
CONF_DEFAULT_HIDE_PASSWORDS,
CONF_DEFAULT_INTERFACES,
CONF_DEFAULT_INTERVALS,
Expand All @@ -47,6 +49,8 @@
CONF_DEFAULT_SSL,
CONF_DEFAULT_TRACK_DEVICES,
CONF_DEFAULT_USERNAME,
CONF_FORCE_CLIENTS,
CONF_FORCE_CLIENTS_WAITTIME,
CONF_HIDE_PASSWORDS,
CONF_INTERFACES,
CONF_INTERVAL,
Expand Down Expand Up @@ -368,6 +372,16 @@ def _create_form_connected_devices(
CONF_TRACK_DEVICES,
default=user_input.get(CONF_TRACK_DEVICES, CONF_DEFAULT_TRACK_DEVICES),
): cv.boolean,
vol.Required(
CONF_FORCE_CLIENTS,
default=user_input.get(CONF_FORCE_CLIENTS, CONF_DEFAULT_FORCE_CLIENTS),
): cv.boolean,
vol.Required(
CONF_FORCE_CLIENTS_WAITTIME,
default=user_input.get(
CONF_FORCE_CLIENTS_WAITTIME, CONF_DEFAULT_FORCE_CLIENTS_WAITTIME
),
): cv.positive_float,
vol.Required(
CONF_LATEST_CONNECTED,
default=user_input.get(
Expand Down
6 changes: 6 additions & 0 deletions custom_components/asusrouter/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@
CONF_EVENT_NODE_CONNECTED = "node_connected"
CONF_EVENT_NODE_DISCONNECTED = "node_disconnected"
CONF_EVENT_NODE_RECONNECTED = "node_reconnected"
CONF_FORCE_CLIENTS = "force_clients"
CONF_FORCE_CLIENTS_WAITTIME = "force_clients_waittime"
CONF_HIDE_PASSWORDS = "hide_passwords"
CONF_INTERFACES = "interfaces"
CONF_INTERVAL = "interval_"
Expand Down Expand Up @@ -481,6 +483,8 @@
CONF_EVENT_NODE_DISCONNECTED: True,
CONF_EVENT_NODE_RECONNECTED: True,
}
CONF_DEFAULT_FORCE_CLIENTS = True
CONF_DEFAULT_FORCE_CLIENTS_WAITTIME = 5.0
CONF_DEFAULT_HIDE_PASSWORDS = False
CONF_DEFAULT_INTERFACES = [WAN.upper()]
CONF_DEFAULT_INTERVALS = {CONF_INTERVAL + FIRMWARE: 21600}
Expand Down Expand Up @@ -523,6 +527,8 @@
CONF_CONFIRM,
CONF_CONSIDER_HOME,
CONF_ENABLE_CONTROL,
CONF_FORCE_CLIENTS,
CONF_FORCE_CLIENTS_WAITTIME,
CONF_HIDE_PASSWORDS,
CONF_INTERFACES,
CONF_INTERVAL_DEVICES,
Expand Down
8 changes: 4 additions & 4 deletions custom_components/asusrouter/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from typing import Any, Optional

from asusrouter.modules.state import AsusState
from asusrouter.modules.state import AsusState, AsusStateNone
from homeassistant.components.binary_sensor import BinarySensorEntityDescription
from homeassistant.components.button import ButtonEntityDescription
from homeassistant.components.light import LightEntityDescription
Expand Down Expand Up @@ -59,9 +59,9 @@ class ARSwitchDescription(AREntityDescription, SwitchEntityDescription):
icon_on: Optional[str] = None
icon_off: Optional[str] = None

state_on: Optional[AsusState] = None
state_on: AsusState = AsusStateNone.NONE
state_on_args: Optional[dict[str, Any]] = None
state_off: Optional[AsusState] = None
state_off: AsusState = AsusStateNone.NONE
state_off_args: Optional[dict[str, Any]] = None

state_expect_modify: bool = False
Expand All @@ -71,7 +71,7 @@ class ARSwitchDescription(AREntityDescription, SwitchEntityDescription):
class ARButtonDescription(AREntityDescription, ButtonEntityDescription):
"""Describe AsusRouter button."""

state: Optional[str] = None
state: AsusState = AsusStateNone.NONE
state_args: Optional[dict[str, Any]] = None
state_expect_modify: bool = False

Expand Down
7 changes: 4 additions & 3 deletions custom_components/asusrouter/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,15 @@ def icon(self) -> Optional[str]:
async def _set_state(
self,
state: AsusState,
arguments: Optional[dict[str, Any]] = None,
expect_modify: bool = False,
**kwargs: Any,
) -> None:
"""Set switch state."""

try:
_LOGGER.debug("Setting state to %s", state)
result = await self.api.async_set_state(state, arguments, expect_modify)
result = await self.api.async_set_state(
state=state, expect_modify=expect_modify, **kwargs
)
await self.coordinator.async_request_refresh()
if not result:
_LOGGER.debug("State was not set!")
Expand Down
4 changes: 2 additions & 2 deletions custom_components/asusrouter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/Vaskivskyi/ha-asusrouter/issues",
"loggers": ["asusrouter"],
"requirements": ["asusrouter==1.1.2"],
"requirements": ["asusrouter==1.4.0"],
"ssdp": [
{
"manufacturer": "ASUSTeK Computer Inc."
}
],
"version": "0.24.2"
"version": "0.25.0"
}
19 changes: 19 additions & 0 deletions custom_components/asusrouter/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
AIMESH,
CONF_DEFAULT_CONSIDER_HOME,
CONF_DEFAULT_EVENT,
CONF_DEFAULT_FORCE_CLIENTS,
CONF_DEFAULT_FORCE_CLIENTS_WAITTIME,
CONF_DEFAULT_INTERVALS,
CONF_DEFAULT_LATEST_CONNECTED,
CONF_DEFAULT_MODE,
Expand All @@ -45,6 +47,8 @@
CONF_DEFAULT_SPLIT_INTERVALS,
CONF_DEFAULT_TRACK_DEVICES,
CONF_EVENT_NODE_CONNECTED,
CONF_FORCE_CLIENTS,
CONF_FORCE_CLIENTS_WAITTIME,
CONF_INTERVAL,
CONF_INTERVAL_DEVICES,
CONF_LATEST_CONNECTED,
Expand Down Expand Up @@ -343,6 +347,21 @@ async def setup(self) -> None:

# Update clients
await self.update_clients()

# Force clients settings
# This should be done after clients update so that first update is fast
force_clients = self._options.get(
CONF_FORCE_CLIENTS, CONF_DEFAULT_FORCE_CLIENTS
)
if force_clients is True:
force_clients_waittime = self._options.get(
CONF_FORCE_CLIENTS_WAITTIME, CONF_DEFAULT_FORCE_CLIENTS_WAITTIME
)
_LOGGER.debug(
"Forcing clients updates with %s s wait time",
force_clients_waittime,
)
self.bridge.api.set_force_clients(force_clients, force_clients_waittime)
else:
_LOGGER.debug(
"Device is in AiMesh node mode. Device tracking and AiMesh monitoring is disabled"
Expand Down
Loading

0 comments on commit 370b66e

Please sign in to comment.