Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wake-on-lan #59

Merged
merged 4 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions custom_components/unfoldedcircle/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"issue_tracker": "https://github.com/JackJPowell/hass-unfoldedcircle/issues",
"requirements": [
"websockets==12.0",
"pyUnfoldedCircleRemote==0.11.10",
"pyUnfoldedCircleRemote==0.11.11",
"wakeonlan==3.1.0"
],
"ssdp": [],
"version": "0.12.0",
"version": "0.13.0",
"zeroconf": ["_uc-remote._tcp.local."]
}
19 changes: 13 additions & 6 deletions custom_components/unfoldedcircle/pyUnfoldedCircleRemote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ def __init__(
self._is_simulator = None
self._docks: list[Dock] = []
self._wake_if_asleep = wake_if_asleep
self._wake_on_lan: bool = True
self._wake_on_lan_retries = 3
self._bt_enabled: bool = True
self._wifi_enabled: bool = True
self._wake_on_lan: bool = False
self._wake_on_lan_retries = 2
self._wake_on_lan_available: bool = False
self._bt_enabled: bool = False
self._wifi_enabled: bool = False

@property
def name(self):
Expand Down Expand Up @@ -1289,9 +1290,15 @@ async def get_remote_network_settings(self) -> str:
):
await self.raise_on_error(response)
settings = await response.json()
self._wake_on_lan = settings.get("wake_on_wlan").get("enabled")

self._bt_enabled = settings.get("bt_enabled")
self._wifi_enabled = settings.get("wifi_enabled")

try:
self._wake_on_lan = settings.get("wake_on_wlan").get("enabled")
self._wake_on_lan_available = True
except AttributeError:
self._wake_on_lan = False
return settings

async def patch_remote_network_settings(
Expand All @@ -1310,7 +1317,7 @@ async def patch_remote_network_settings(
network_settings["bt_enabled"] = bt_enabled
if wifi_enabled is not None:
network_settings["wifi_enabled"] = wifi_enabled
if wake_on_lan is not None:
if wake_on_lan is not None and self._sw_version >= 2:
network_settings["wake_on_wlan"]["enabled"] = wake_on_lan

async with (
Expand Down
14 changes: 10 additions & 4 deletions custom_components/unfoldedcircle/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,17 @@ async def async_setup_entry(
for switch in filter(lambda a: a not in activities, coordinator.api.activities)
)

# Remove WOL switch if it is not available on the remote
switches: list = []
if not coordinator.api._wake_on_lan_available:
for item in UNFOLDED_CIRCLE_SWITCH:
if item.key != "wake_on_lan":
switches.append(item)
else:
switches = UNFOLDED_CIRCLE_SWITCH

async_add_entities(
UCRemoteConfigSwitch(coordinator, configSwitch)
for configSwitch in UNFOLDED_CIRCLE_SWITCH
UCRemoteConfigSwitch(coordinator, configSwitch) for configSwitch in switches
)

@service.verify_domain_control(hass, DOMAIN)
Expand Down Expand Up @@ -229,8 +237,6 @@ def _handle_coordinator_update(self) -> None:
class UCRemoteConfigSwitch(UnfoldedCircleEntity, SwitchEntity):
"""Class representing an unfolded circle setting."""

entity_description = UNFOLDED_CIRCLE_SWITCH

def __init__(
self, coordinator, description: UnfoldedCircleSwitchEntityDescription
) -> None:
Expand Down