Remove Windows workarounds from wake_on_lan (#64070)

pull/64080/head
Erik Montnemery 2022-01-13 20:42:30 +01:00 committed by GitHub
parent b3421cf727
commit abce453b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 84 deletions

View File

@ -2,7 +2,6 @@
from __future__ import annotations
import logging
import platform
import subprocess as sp
import voluptuous as vol
@ -158,24 +157,14 @@ class WolSwitch(SwitchEntity):
def update(self):
"""Check if device is on and update the state. Only called if assumed state is false."""
if platform.system().lower() == "windows":
ping_cmd = [
"ping",
"-n",
"1",
"-w",
str(DEFAULT_PING_TIMEOUT * 1000),
str(self._host),
]
else:
ping_cmd = [
"ping",
"-c",
"1",
"-W",
str(DEFAULT_PING_TIMEOUT),
str(self._host),
]
ping_cmd = [
"ping",
"-c",
"1",
"-W",
str(DEFAULT_PING_TIMEOUT),
str(self._host),
]
status = sp.call(ping_cmd, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
self._state = not bool(status)

View File

@ -1,5 +1,4 @@
"""The tests for the wake on lan switch platform."""
import platform
import subprocess
from unittest.mock import patch
@ -66,38 +65,6 @@ async def test_valid_hostname(hass):
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):
"""Test with broadcast address and broadcast port config."""
mac = "00-01-02-03-04-05"
@ -245,38 +212,6 @@ async def test_off_script(hass):
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):
"""Test that the state updates if we do not pass in a hostname."""