Skip to content

Commit df5e829

Browse files
authored
Add wifi_setconfig method to configure WiFi access point (#990)
* Add wifi_setconfig method to configure WiFi access point * fixes * debug * debug * debug * debug * Revert "fixes" This reverts commit 9b9f4da. * remove workaround
1 parent bb79c10 commit df5e829

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

aioshelly/rpc_device/device.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
ShellyBLESetConfig,
4646
ShellyScript,
4747
ShellyScriptCode,
48+
ShellyWiFiSetConfig,
4849
ShellyWsConfig,
4950
ShellyWsSetConfig,
5051
)
@@ -698,6 +699,27 @@ async def ble_getconfig(self) -> ShellyBLEConfig:
698699
"""Get the BLE config with BLE.GetConfig."""
699700
return cast(ShellyBLEConfig, await self.call_rpc("BLE.GetConfig"))
700701

702+
async def wifi_setconfig(
703+
self, *, ap_enable: bool | None = None
704+
) -> ShellyWiFiSetConfig:
705+
"""Configure WiFi settings with WiFi.SetConfig.
706+
707+
Args:
708+
ap_enable: Whether to enable the WiFi AP
709+
710+
Returns:
711+
Response dict, may contain "restart_required": bool
712+
713+
"""
714+
config: dict[str, Any] = {}
715+
if ap_enable is not None:
716+
config["ap"] = {"enable": ap_enable}
717+
718+
return cast(
719+
ShellyWiFiSetConfig,
720+
await self.call_rpc("WiFi.SetConfig", {"config": config}),
721+
)
722+
701723
async def ws_setconfig(
702724
self, enable: bool, server: str, ssl_ca: str = "*"
703725
) -> ShellyWsSetConfig:

aioshelly/rpc_device/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class ShellyBLESetConfig(TypedDict, total=False):
3939
restart_required: bool
4040

4141

42+
class ShellyWiFiSetConfig(TypedDict, total=False):
43+
"""Shelly WiFi Set Config."""
44+
45+
restart_required: bool
46+
47+
4248
class ShellyWsConfig(TypedDict, total=False):
4349
"""Shelly Outbound Websocket Config."""
4450

tests/rpc_device/test_device.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,18 @@ async def test_ble_setconfig(rpc_device: RpcDevice) -> None:
537537
}
538538

539539

540+
@pytest.mark.asyncio
541+
async def test_wifi_setconfig(rpc_device: RpcDevice) -> None:
542+
"""Test RpcDevice wifi_setconfig method."""
543+
await rpc_device.wifi_setconfig(ap_enable=False)
544+
545+
assert rpc_device.call_rpc_multiple.call_count == 1
546+
assert rpc_device.call_rpc_multiple.call_args[0][0][0][0] == "WiFi.SetConfig"
547+
assert rpc_device.call_rpc_multiple.call_args[0][0][0][1] == {
548+
"config": {"ap": {"enable": False}}
549+
}
550+
551+
540552
@pytest.mark.asyncio
541553
async def test_script_stop(rpc_device: RpcDevice) -> None:
542554
"""Test RpcDevice script_stop method."""

0 commit comments

Comments
 (0)