mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
parent
cb63a9d7e1
commit
101ab5c3fa
@ -5,15 +5,13 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import wakeonlan
|
import wakeonlan
|
||||||
|
|
||||||
from homeassistant.const import CONF_MAC
|
from homeassistant.const import CONF_BROADCAST_ADDRESS, CONF_MAC
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = "wake_on_lan"
|
DOMAIN = "wake_on_lan"
|
||||||
|
|
||||||
CONF_BROADCAST_ADDRESS = "broadcast_address"
|
|
||||||
|
|
||||||
SERVICE_SEND_MAGIC_PACKET = "send_magic_packet"
|
SERVICE_SEND_MAGIC_PACKET = "send_magic_packet"
|
||||||
|
|
||||||
WAKE_ON_LAN_SEND_MAGIC_PACKET_SCHEMA = vol.Schema(
|
WAKE_ON_LAN_SEND_MAGIC_PACKET_SCHEMA = vol.Schema(
|
||||||
|
@ -7,14 +7,12 @@ import voluptuous as vol
|
|||||||
import wakeonlan
|
import wakeonlan
|
||||||
|
|
||||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
|
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
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.script import Script
|
from homeassistant.helpers.script import Script
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_BROADCAST_ADDRESS = "broadcast_address"
|
|
||||||
CONF_MAC_ADDRESS = "mac_address"
|
|
||||||
CONF_OFF_ACTION = "turn_off"
|
CONF_OFF_ACTION = "turn_off"
|
||||||
|
|
||||||
DEFAULT_NAME = "Wake on LAN"
|
DEFAULT_NAME = "Wake on LAN"
|
||||||
@ -22,7 +20,7 @@ DEFAULT_PING_TIMEOUT = 1
|
|||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
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_BROADCAST_ADDRESS): cv.string,
|
||||||
vol.Optional(CONF_HOST): cv.string,
|
vol.Optional(CONF_HOST): cv.string,
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): 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."""
|
"""Set up a wake on lan switch."""
|
||||||
broadcast_address = config.get(CONF_BROADCAST_ADDRESS)
|
broadcast_address = config.get(CONF_BROADCAST_ADDRESS)
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
mac_address = config.get(CONF_MAC_ADDRESS)
|
mac_address = config[CONF_MAC]
|
||||||
name = config.get(CONF_NAME)
|
name = config[CONF_NAME]
|
||||||
off_action = config.get(CONF_OFF_ACTION)
|
off_action = config.get(CONF_OFF_ACTION)
|
||||||
|
|
||||||
add_entities(
|
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."""
|
"""Representation of a wake on lan switch."""
|
||||||
|
|
||||||
def __init__(self, hass, name, host, mac_address, off_action, broadcast_address):
|
def __init__(self, hass, name, host, mac_address, off_action, broadcast_address):
|
||||||
|
@ -30,7 +30,7 @@ def system():
|
|||||||
return "Windows"
|
return "Windows"
|
||||||
|
|
||||||
|
|
||||||
class TestWOLSwitch(unittest.TestCase):
|
class TestWolSwitch(unittest.TestCase):
|
||||||
"""Test the wol switch."""
|
"""Test the wol switch."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -53,7 +53,7 @@ class TestWOLSwitch(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"switch": {
|
"switch": {
|
||||||
"platform": "wake_on_lan",
|
"platform": "wake_on_lan",
|
||||||
"mac_address": "00-01-02-03-04-05",
|
"mac": "00-01-02-03-04-05",
|
||||||
"host": "validhostname",
|
"host": "validhostname",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -89,7 +89,7 @@ class TestWOLSwitch(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"switch": {
|
"switch": {
|
||||||
"platform": "wake_on_lan",
|
"platform": "wake_on_lan",
|
||||||
"mac_address": "00-01-02-03-04-05",
|
"mac": "00-01-02-03-04-05",
|
||||||
"host": "validhostname",
|
"host": "validhostname",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -113,7 +113,7 @@ class TestWOLSwitch(unittest.TestCase):
|
|||||||
assert setup_component(
|
assert setup_component(
|
||||||
self.hass,
|
self.hass,
|
||||||
switch.DOMAIN,
|
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)
|
@patch("wakeonlan.send_magic_packet", new=send_magic_packet)
|
||||||
@ -126,7 +126,7 @@ class TestWOLSwitch(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"switch": {
|
"switch": {
|
||||||
"platform": "wake_on_lan",
|
"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",
|
"broadcast_address": "255.255.255.255",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -150,7 +150,7 @@ class TestWOLSwitch(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"switch": {
|
"switch": {
|
||||||
"platform": "wake_on_lan",
|
"platform": "wake_on_lan",
|
||||||
"mac_address": "00-01-02-03-04-05",
|
"mac": "00-01-02-03-04-05",
|
||||||
"host": "validhostname",
|
"host": "validhostname",
|
||||||
"turn_off": {"service": "shell_command.turn_off_target"},
|
"turn_off": {"service": "shell_command.turn_off_target"},
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ class TestWOLSwitch(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"switch": {
|
"switch": {
|
||||||
"platform": "wake_on_lan",
|
"platform": "wake_on_lan",
|
||||||
"mac_address": "00-01-02-03-04-05",
|
"mac": "00-01-02-03-04-05",
|
||||||
"host": "invalidhostname",
|
"host": "invalidhostname",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user