mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Remove Windows workarounds from wake_on_lan (#64070)
This commit is contained in:
parent
b3421cf727
commit
abce453b5c
@ -2,7 +2,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import platform
|
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -158,24 +157,14 @@ class WolSwitch(SwitchEntity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Check if device is on and update the state. Only called if assumed state is false."""
|
"""Check if device is on and update the state. Only called if assumed state is false."""
|
||||||
if platform.system().lower() == "windows":
|
ping_cmd = [
|
||||||
ping_cmd = [
|
"ping",
|
||||||
"ping",
|
"-c",
|
||||||
"-n",
|
"1",
|
||||||
"1",
|
"-W",
|
||||||
"-w",
|
str(DEFAULT_PING_TIMEOUT),
|
||||||
str(DEFAULT_PING_TIMEOUT * 1000),
|
str(self._host),
|
||||||
str(self._host),
|
]
|
||||||
]
|
|
||||||
else:
|
|
||||||
ping_cmd = [
|
|
||||||
"ping",
|
|
||||||
"-c",
|
|
||||||
"1",
|
|
||||||
"-W",
|
|
||||||
str(DEFAULT_PING_TIMEOUT),
|
|
||||||
str(self._host),
|
|
||||||
]
|
|
||||||
|
|
||||||
status = sp.call(ping_cmd, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
|
status = sp.call(ping_cmd, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
|
||||||
self._state = not bool(status)
|
self._state = not bool(status)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""The tests for the wake on lan switch platform."""
|
"""The tests for the wake on lan switch platform."""
|
||||||
import platform
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@ -66,38 +65,6 @@ async def test_valid_hostname(hass):
|
|||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
|
|
||||||
async def test_valid_hostname_windows(hass):
|
|
||||||
"""Test with valid hostname on windows."""
|
|
||||||
assert await async_setup_component(
|
|
||||||
hass,
|
|
||||||
switch.DOMAIN,
|
|
||||||
{
|
|
||||||
"switch": {
|
|
||||||
"platform": "wake_on_lan",
|
|
||||||
"mac": "00-01-02-03-04-05",
|
|
||||||
"host": "validhostname",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get("switch.wake_on_lan")
|
|
||||||
assert state.state == STATE_OFF
|
|
||||||
|
|
||||||
with patch.object(subprocess, "call", return_value=0), patch.object(
|
|
||||||
platform, "system", return_value="Windows"
|
|
||||||
):
|
|
||||||
await hass.services.async_call(
|
|
||||||
switch.DOMAIN,
|
|
||||||
SERVICE_TURN_ON,
|
|
||||||
{ATTR_ENTITY_ID: "switch.wake_on_lan"},
|
|
||||||
blocking=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
state = hass.states.get("switch.wake_on_lan")
|
|
||||||
assert state.state == STATE_ON
|
|
||||||
|
|
||||||
|
|
||||||
async def test_broadcast_config_ip_and_port(hass, mock_send_magic_packet):
|
async def test_broadcast_config_ip_and_port(hass, mock_send_magic_packet):
|
||||||
"""Test with broadcast address and broadcast port config."""
|
"""Test with broadcast address and broadcast port config."""
|
||||||
mac = "00-01-02-03-04-05"
|
mac = "00-01-02-03-04-05"
|
||||||
@ -245,38 +212,6 @@ async def test_off_script(hass):
|
|||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_hostname_windows(hass):
|
|
||||||
"""Test with invalid hostname on windows."""
|
|
||||||
|
|
||||||
assert await async_setup_component(
|
|
||||||
hass,
|
|
||||||
switch.DOMAIN,
|
|
||||||
{
|
|
||||||
"switch": {
|
|
||||||
"platform": "wake_on_lan",
|
|
||||||
"mac": "00-01-02-03-04-05",
|
|
||||||
"host": "invalidhostname",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get("switch.wake_on_lan")
|
|
||||||
assert state.state == STATE_OFF
|
|
||||||
|
|
||||||
with patch.object(subprocess, "call", return_value=2):
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
|
||||||
switch.DOMAIN,
|
|
||||||
SERVICE_TURN_ON,
|
|
||||||
{ATTR_ENTITY_ID: "switch.wake_on_lan"},
|
|
||||||
blocking=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
state = hass.states.get("switch.wake_on_lan")
|
|
||||||
assert state.state == STATE_OFF
|
|
||||||
|
|
||||||
|
|
||||||
async def test_no_hostname_state(hass):
|
async def test_no_hostname_state(hass):
|
||||||
"""Test that the state updates if we do not pass in a hostname."""
|
"""Test that the state updates if we do not pass in a hostname."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user