Skip to content

Commit 6f6ff20

Browse files
authored
0.25.0b1 (#734)
* Use new `async_set_state` scheme of `asusrouter` (#733) * Bump asusrouter to `1.3.0` * Bump version to `0.25.0b1`
1 parent 95874a3 commit 6f6ff20

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
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/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.2.0"],
11+
"requirements": ["asusrouter==1.3.0"],
1212
"ssdp": [
1313
{
1414
"manufacturer": "ASUSTeK Computer Inc."
1515
}
1616
],
17-
"version": "0.25.0b0"
17+
"version": "0.25.0b1"
1818
}

custom_components/asusrouter/switch.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
from __future__ import annotations
44

5-
import logging
6-
from typing import Any, Optional
5+
from typing import Any
76

8-
from asusrouter.modules.state import AsusState
97
from homeassistant.components.switch import SwitchEntity
108
from homeassistant.config_entries import ConfigEntry
119
from homeassistant.core import HomeAssistant
@@ -17,8 +15,6 @@
1715
from .entity import ARBinaryEntity, async_setup_ar_entry
1816
from .router import ARDevice
1917

20-
_LOGGER = logging.getLogger(__name__)
21-
2218

2319
async def async_setup_entry(
2420
hass: HomeAssistant,
@@ -67,10 +63,12 @@ async def async_turn_on(
6763
) -> None:
6864
"""Turn on switch."""
6965

66+
kwargs = self._state_on_args if self._state_on_args is not None else {}
67+
7068
await self._set_state(
7169
state=self._state_on,
72-
arguments=self._state_on_args,
7370
expect_modify=self._state_expect_modify,
71+
**kwargs,
7472
)
7573

7674
async def async_turn_off(
@@ -79,8 +77,10 @@ async def async_turn_off(
7977
) -> None:
8078
"""Turn off switch."""
8179

80+
kwargs = self._state_off_args if self._state_off_args is not None else {}
81+
8282
await self._set_state(
8383
state=self._state_off,
84-
arguments=self._state_off_args,
8584
expect_modify=self._state_expect_modify,
85+
**kwargs,
8686
)

0 commit comments

Comments
 (0)