Skip to content

Commit 370b66e

Browse files
authored
0.25.0 (#737)
* 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`
1 parent 96c2772 commit 370b66e

File tree

20 files changed

+739
-649
lines changed

20 files changed

+739
-649
lines changed

custom_components/asusrouter/button.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,27 @@ async def async_press(
7878
) -> None:
7979
"""Press button."""
8080

81+
kwargs = self._state_args if self._state_args is not None else {}
82+
8183
await self._set_state(
8284
state=self._state,
83-
arguments=self._state_args,
8485
expect_modify=self._state_expect_modify,
86+
**kwargs,
8587
)
8688

8789
async def _set_state(
8890
self,
8991
state: AsusState,
90-
arguments: Optional[dict[str, Any]] = None,
9192
expect_modify: bool = False,
93+
**kwargs: Any,
9294
) -> None:
9395
"""Set switch state."""
9496

9597
try:
9698
_LOGGER.debug("Pressing %s", state)
97-
result = await self.api.async_set_state(state, arguments, expect_modify)
99+
result = await self.api.async_set_state(
100+
state=state, expect_modify=expect_modify, **kwargs
101+
)
98102
if not result:
99103
_LOGGER.debug("Didn't manage to press %s", state)
100104
except Exception as ex: # pylint: disable=broad-except

custom_components/asusrouter/config_flow.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
CONF_DEFAULT_CACHE_TIME,
3737
CONF_DEFAULT_CONSIDER_HOME,
3838
CONF_DEFAULT_EVENT,
39+
CONF_DEFAULT_FORCE_CLIENTS,
40+
CONF_DEFAULT_FORCE_CLIENTS_WAITTIME,
3941
CONF_DEFAULT_HIDE_PASSWORDS,
4042
CONF_DEFAULT_INTERFACES,
4143
CONF_DEFAULT_INTERVALS,
@@ -47,6 +49,8 @@
4749
CONF_DEFAULT_SSL,
4850
CONF_DEFAULT_TRACK_DEVICES,
4951
CONF_DEFAULT_USERNAME,
52+
CONF_FORCE_CLIENTS,
53+
CONF_FORCE_CLIENTS_WAITTIME,
5054
CONF_HIDE_PASSWORDS,
5155
CONF_INTERFACES,
5256
CONF_INTERVAL,
@@ -368,6 +372,16 @@ def _create_form_connected_devices(
368372
CONF_TRACK_DEVICES,
369373
default=user_input.get(CONF_TRACK_DEVICES, CONF_DEFAULT_TRACK_DEVICES),
370374
): cv.boolean,
375+
vol.Required(
376+
CONF_FORCE_CLIENTS,
377+
default=user_input.get(CONF_FORCE_CLIENTS, CONF_DEFAULT_FORCE_CLIENTS),
378+
): cv.boolean,
379+
vol.Required(
380+
CONF_FORCE_CLIENTS_WAITTIME,
381+
default=user_input.get(
382+
CONF_FORCE_CLIENTS_WAITTIME, CONF_DEFAULT_FORCE_CLIENTS_WAITTIME
383+
),
384+
): cv.positive_float,
371385
vol.Required(
372386
CONF_LATEST_CONNECTED,
373387
default=user_input.get(

custom_components/asusrouter/const.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@
441441
CONF_EVENT_NODE_CONNECTED = "node_connected"
442442
CONF_EVENT_NODE_DISCONNECTED = "node_disconnected"
443443
CONF_EVENT_NODE_RECONNECTED = "node_reconnected"
444+
CONF_FORCE_CLIENTS = "force_clients"
445+
CONF_FORCE_CLIENTS_WAITTIME = "force_clients_waittime"
444446
CONF_HIDE_PASSWORDS = "hide_passwords"
445447
CONF_INTERFACES = "interfaces"
446448
CONF_INTERVAL = "interval_"
@@ -481,6 +483,8 @@
481483
CONF_EVENT_NODE_DISCONNECTED: True,
482484
CONF_EVENT_NODE_RECONNECTED: True,
483485
}
486+
CONF_DEFAULT_FORCE_CLIENTS = True
487+
CONF_DEFAULT_FORCE_CLIENTS_WAITTIME = 5.0
484488
CONF_DEFAULT_HIDE_PASSWORDS = False
485489
CONF_DEFAULT_INTERFACES = [WAN.upper()]
486490
CONF_DEFAULT_INTERVALS = {CONF_INTERVAL + FIRMWARE: 21600}
@@ -523,6 +527,8 @@
523527
CONF_CONFIRM,
524528
CONF_CONSIDER_HOME,
525529
CONF_ENABLE_CONTROL,
530+
CONF_FORCE_CLIENTS,
531+
CONF_FORCE_CLIENTS_WAITTIME,
526532
CONF_HIDE_PASSWORDS,
527533
CONF_INTERFACES,
528534
CONF_INTERVAL_DEVICES,

custom_components/asusrouter/dataclass.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dataclasses import dataclass
77
from typing import Any, Optional
88

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

62-
state_on: Optional[AsusState] = None
62+
state_on: AsusState = AsusStateNone.NONE
6363
state_on_args: Optional[dict[str, Any]] = None
64-
state_off: Optional[AsusState] = None
64+
state_off: AsusState = AsusStateNone.NONE
6565
state_off_args: Optional[dict[str, Any]] = None
6666

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

74-
state: Optional[str] = None
74+
state: AsusState = AsusStateNone.NONE
7575
state_args: Optional[dict[str, Any]] = None
7676
state_expect_modify: bool = False
7777

custom_components/asusrouter/entity.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,15 @@ def icon(self) -> Optional[str]:
153153
async def _set_state(
154154
self,
155155
state: AsusState,
156-
arguments: Optional[dict[str, Any]] = None,
157156
expect_modify: bool = False,
157+
**kwargs: Any,
158158
) -> None:
159159
"""Set switch state."""
160-
161160
try:
162161
_LOGGER.debug("Setting state to %s", state)
163-
result = await self.api.async_set_state(state, arguments, expect_modify)
162+
result = await self.api.async_set_state(
163+
state=state, expect_modify=expect_modify, **kwargs
164+
)
164165
await self.coordinator.async_request_refresh()
165166
if not result:
166167
_LOGGER.debug("State was not set!")

custom_components/asusrouter/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"iot_class": "local_polling",
99
"issue_tracker": "https://github.com/Vaskivskyi/ha-asusrouter/issues",
1010
"loggers": ["asusrouter"],
11-
"requirements": ["asusrouter==1.1.2"],
11+
"requirements": ["asusrouter==1.4.0"],
1212
"ssdp": [
1313
{
1414
"manufacturer": "ASUSTeK Computer Inc."
1515
}
1616
],
17-
"version": "0.24.2"
17+
"version": "0.25.0"
1818
}

custom_components/asusrouter/router.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
AIMESH,
3737
CONF_DEFAULT_CONSIDER_HOME,
3838
CONF_DEFAULT_EVENT,
39+
CONF_DEFAULT_FORCE_CLIENTS,
40+
CONF_DEFAULT_FORCE_CLIENTS_WAITTIME,
3941
CONF_DEFAULT_INTERVALS,
4042
CONF_DEFAULT_LATEST_CONNECTED,
4143
CONF_DEFAULT_MODE,
@@ -45,6 +47,8 @@
4547
CONF_DEFAULT_SPLIT_INTERVALS,
4648
CONF_DEFAULT_TRACK_DEVICES,
4749
CONF_EVENT_NODE_CONNECTED,
50+
CONF_FORCE_CLIENTS,
51+
CONF_FORCE_CLIENTS_WAITTIME,
4852
CONF_INTERVAL,
4953
CONF_INTERVAL_DEVICES,
5054
CONF_LATEST_CONNECTED,
@@ -343,6 +347,21 @@ async def setup(self) -> None:
343347

344348
# Update clients
345349
await self.update_clients()
350+
351+
# Force clients settings
352+
# This should be done after clients update so that first update is fast
353+
force_clients = self._options.get(
354+
CONF_FORCE_CLIENTS, CONF_DEFAULT_FORCE_CLIENTS
355+
)
356+
if force_clients is True:
357+
force_clients_waittime = self._options.get(
358+
CONF_FORCE_CLIENTS_WAITTIME, CONF_DEFAULT_FORCE_CLIENTS_WAITTIME
359+
)
360+
_LOGGER.debug(
361+
"Forcing clients updates with %s s wait time",
362+
force_clients_waittime,
363+
)
364+
self.bridge.api.set_force_clients(force_clients, force_clients_waittime)
346365
else:
347366
_LOGGER.debug(
348367
"Device is in AiMesh node mode. Device tracking and AiMesh monitoring is disabled"

0 commit comments

Comments
 (0)