From 101ab5c3fad1cb353be01483608c7ea5b6315e6d Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sun, 17 Nov 2019 15:53:34 +0100 Subject: [PATCH] Align naming (#28830) * Align naming * Update tests --- homeassistant/components/wake_on_lan/__init__.py | 4 +--- homeassistant/components/wake_on_lan/switch.py | 14 ++++++-------- tests/components/wake_on_lan/test_switch.py | 14 +++++++------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/wake_on_lan/__init__.py b/homeassistant/components/wake_on_lan/__init__.py index b4aad4925b9..d5b8f92a9bc 100644 --- a/homeassistant/components/wake_on_lan/__init__.py +++ b/homeassistant/components/wake_on_lan/__init__.py @@ -5,15 +5,13 @@ import logging 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( diff --git a/homeassistant/components/wake_on_lan/switch.py b/homeassistant/components/wake_on_lan/switch.py index 01f69679829..8200a0309fa 100644 --- a/homeassistant/components/wake_on_lan/switch.py +++ b/homeassistant/components/wake_on_lan/switch.py @@ -7,14 +7,12 @@ import voluptuous as vol 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" @@ -22,7 +20,7 @@ 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, @@ -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): diff --git a/tests/components/wake_on_lan/test_switch.py b/tests/components/wake_on_lan/test_switch.py index 2d319c2b5e7..1fbcc9cc273 100644 --- a/tests/components/wake_on_lan/test_switch.py +++ b/tests/components/wake_on_lan/test_switch.py @@ -30,7 +30,7 @@ def system(): return "Windows" -class TestWOLSwitch(unittest.TestCase): +class TestWolSwitch(unittest.TestCase): """Test the wol switch.""" def setUp(self): @@ -53,7 +53,7 @@ class TestWOLSwitch(unittest.TestCase): { "switch": { "platform": "wake_on_lan", - "mac_address": "00-01-02-03-04-05", + "mac": "00-01-02-03-04-05", "host": "validhostname", } }, @@ -89,7 +89,7 @@ class TestWOLSwitch(unittest.TestCase): { "switch": { "platform": "wake_on_lan", - "mac_address": "00-01-02-03-04-05", + "mac": "00-01-02-03-04-05", "host": "validhostname", } }, @@ -113,7 +113,7 @@ class TestWOLSwitch(unittest.TestCase): 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) @@ -126,7 +126,7 @@ class TestWOLSwitch(unittest.TestCase): { "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", } }, @@ -150,7 +150,7 @@ class TestWOLSwitch(unittest.TestCase): { "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"}, } @@ -192,7 +192,7 @@ class TestWOLSwitch(unittest.TestCase): { "switch": { "platform": "wake_on_lan", - "mac_address": "00-01-02-03-04-05", + "mac": "00-01-02-03-04-05", "host": "invalidhostname", } },