Skip to content

Commit

Permalink
Align naming (home-assistant#28830)
Browse files Browse the repository at this point in the history
* Align naming

* Update tests
  • Loading branch information
fabaff authored and pull[bot] committed Nov 17, 2019
1 parent 4ed274d commit 3a5f087
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
4 changes: 1 addition & 3 deletions homeassistant/components/wake_on_lan/__init__.py
Expand Up @@ -5,15 +5,13 @@
import voluptuous as vol
import wakeonlan

from homeassistant.const import CONF_MAC
from homeassistant.const import CONF_BROADCAST_ADDRESS, CONF_MAC
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

DOMAIN = "wake_on_lan"

CONF_BROADCAST_ADDRESS = "broadcast_address"

SERVICE_SEND_MAGIC_PACKET = "send_magic_packet"

WAKE_ON_LAN_SEND_MAGIC_PACKET_SCHEMA = vol.Schema(
Expand Down
14 changes: 6 additions & 8 deletions homeassistant/components/wake_on_lan/switch.py
Expand Up @@ -7,22 +7,20 @@
import wakeonlan

from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
from homeassistant.const import CONF_HOST, CONF_NAME
from homeassistant.const import CONF_BROADCAST_ADDRESS, CONF_HOST, CONF_MAC, CONF_NAME
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.script import Script

_LOGGER = logging.getLogger(__name__)

CONF_BROADCAST_ADDRESS = "broadcast_address"
CONF_MAC_ADDRESS = "mac_address"
CONF_OFF_ACTION = "turn_off"

DEFAULT_NAME = "Wake on LAN"
DEFAULT_PING_TIMEOUT = 1

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_MAC_ADDRESS): cv.string,
vol.Required(CONF_MAC): cv.string,
vol.Optional(CONF_BROADCAST_ADDRESS): cv.string,
vol.Optional(CONF_HOST): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
Expand All @@ -35,16 +33,16 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up a wake on lan switch."""
broadcast_address = config.get(CONF_BROADCAST_ADDRESS)
host = config.get(CONF_HOST)
mac_address = config.get(CONF_MAC_ADDRESS)
name = config.get(CONF_NAME)
mac_address = config[CONF_MAC]
name = config[CONF_NAME]
off_action = config.get(CONF_OFF_ACTION)

add_entities(
[WOLSwitch(hass, name, host, mac_address, off_action, broadcast_address)], True
[WolSwitch(hass, name, host, mac_address, off_action, broadcast_address)], True
)


class WOLSwitch(SwitchDevice):
class WolSwitch(SwitchDevice):
"""Representation of a wake on lan switch."""

def __init__(self, hass, name, host, mac_address, off_action, broadcast_address):
Expand Down
14 changes: 7 additions & 7 deletions tests/components/wake_on_lan/test_switch.py
Expand Up @@ -30,7 +30,7 @@ def system():
return "Windows"


class TestWOLSwitch(unittest.TestCase):
class TestWolSwitch(unittest.TestCase):
"""Test the wol switch."""

def setUp(self):
Expand All @@ -53,7 +53,7 @@ def test_valid_hostname(self):
{
"switch": {
"platform": "wake_on_lan",
"mac_address": "00-01-02-03-04-05",
"mac": "00-01-02-03-04-05",
"host": "validhostname",
}
},
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_valid_hostname_windows(self):
{
"switch": {
"platform": "wake_on_lan",
"mac_address": "00-01-02-03-04-05",
"mac": "00-01-02-03-04-05",
"host": "validhostname",
}
},
Expand All @@ -113,7 +113,7 @@ def test_minimal_config(self):
assert setup_component(
self.hass,
switch.DOMAIN,
{"switch": {"platform": "wake_on_lan", "mac_address": "00-01-02-03-04-05"}},
{"switch": {"platform": "wake_on_lan", "mac": "00-01-02-03-04-05"}},
)

@patch("wakeonlan.send_magic_packet", new=send_magic_packet)
Expand All @@ -126,7 +126,7 @@ def test_broadcast_config(self):
{
"switch": {
"platform": "wake_on_lan",
"mac_address": "00-01-02-03-04-05",
"mac": "00-01-02-03-04-05",
"broadcast_address": "255.255.255.255",
}
},
Expand All @@ -150,7 +150,7 @@ def test_off_script(self):
{
"switch": {
"platform": "wake_on_lan",
"mac_address": "00-01-02-03-04-05",
"mac": "00-01-02-03-04-05",
"host": "validhostname",
"turn_off": {"service": "shell_command.turn_off_target"},
}
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_invalid_hostname_windows(self):
{
"switch": {
"platform": "wake_on_lan",
"mac_address": "00-01-02-03-04-05",
"mac": "00-01-02-03-04-05",
"host": "invalidhostname",
}
},
Expand Down

0 comments on commit 3a5f087

Please sign in to comment.