parent
f10b36873a
commit
6e69c57ef5
3 changed files with 38 additions and 44 deletions
|
@ -283,6 +283,7 @@ homeassistant.components.vacuum.*
|
||||||
homeassistant.components.vallox.*
|
homeassistant.components.vallox.*
|
||||||
homeassistant.components.velbus.*
|
homeassistant.components.velbus.*
|
||||||
homeassistant.components.vlc_telnet.*
|
homeassistant.components.vlc_telnet.*
|
||||||
|
homeassistant.components.wake_on_lan.*
|
||||||
homeassistant.components.wallbox.*
|
homeassistant.components.wallbox.*
|
||||||
homeassistant.components.water_heater.*
|
homeassistant.components.water_heater.*
|
||||||
homeassistant.components.watttime.*
|
homeassistant.components.watttime.*
|
||||||
|
|
|
@ -8,7 +8,10 @@ from typing import Any
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import wakeonlan
|
import wakeonlan
|
||||||
|
|
||||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
|
from homeassistant.components.switch import (
|
||||||
|
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||||
|
SwitchEntity,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_BROADCAST_ADDRESS,
|
CONF_BROADCAST_ADDRESS,
|
||||||
CONF_BROADCAST_PORT,
|
CONF_BROADCAST_PORT,
|
||||||
|
@ -32,7 +35,7 @@ CONF_OFF_ACTION = "turn_off"
|
||||||
DEFAULT_NAME = "Wake on LAN"
|
DEFAULT_NAME = "Wake on LAN"
|
||||||
DEFAULT_PING_TIMEOUT = 1
|
DEFAULT_PING_TIMEOUT = 1
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_MAC): cv.string,
|
vol.Required(CONF_MAC): cv.string,
|
||||||
vol.Optional(CONF_BROADCAST_ADDRESS): cv.string,
|
vol.Optional(CONF_BROADCAST_ADDRESS): cv.string,
|
||||||
|
@ -51,12 +54,12 @@ def setup_platform(
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a wake on lan switch."""
|
"""Set up a wake on lan switch."""
|
||||||
broadcast_address = config.get(CONF_BROADCAST_ADDRESS)
|
broadcast_address: str | None = config.get(CONF_BROADCAST_ADDRESS)
|
||||||
broadcast_port = config.get(CONF_BROADCAST_PORT)
|
broadcast_port: int | None = config.get(CONF_BROADCAST_PORT)
|
||||||
host = config.get(CONF_HOST)
|
host: str | None = config.get(CONF_HOST)
|
||||||
mac_address = config[CONF_MAC]
|
mac_address: str = config[CONF_MAC]
|
||||||
name = config[CONF_NAME]
|
name: str = config[CONF_NAME]
|
||||||
off_action = config.get(CONF_OFF_ACTION)
|
off_action: list[Any] | None = config.get(CONF_OFF_ACTION)
|
||||||
|
|
||||||
add_entities(
|
add_entities(
|
||||||
[
|
[
|
||||||
|
@ -79,17 +82,16 @@ class WolSwitch(SwitchEntity):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass,
|
hass: HomeAssistant,
|
||||||
name,
|
name: str,
|
||||||
host,
|
host: str | None,
|
||||||
mac_address,
|
mac_address: str,
|
||||||
off_action,
|
off_action: list[Any] | None,
|
||||||
broadcast_address,
|
broadcast_address: str | None,
|
||||||
broadcast_port,
|
broadcast_port: int | None,
|
||||||
):
|
) -> None:
|
||||||
"""Initialize the WOL switch."""
|
"""Initialize the WOL switch."""
|
||||||
self._hass = hass
|
self._attr_name = name
|
||||||
self._name = name
|
|
||||||
self._host = host
|
self._host = host
|
||||||
self._mac_address = mac_address
|
self._mac_address = mac_address
|
||||||
self._broadcast_address = broadcast_address
|
self._broadcast_address = broadcast_address
|
||||||
|
@ -98,37 +100,18 @@ class WolSwitch(SwitchEntity):
|
||||||
Script(hass, off_action, name, DOMAIN) if off_action else None
|
Script(hass, off_action, name, DOMAIN) if off_action else None
|
||||||
)
|
)
|
||||||
self._state = False
|
self._state = False
|
||||||
self._assumed_state = host is None
|
self._attr_assumed_state = host is None
|
||||||
self._unique_id = dr.format_mac(mac_address)
|
self._attr_should_poll = bool(not self._attr_assumed_state)
|
||||||
|
self._attr_unique_id = dr.format_mac(mac_address)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return true if switch is on."""
|
"""Return true if switch is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the switch."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def assumed_state(self):
|
|
||||||
"""Return true if no host is provided."""
|
|
||||||
return self._assumed_state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return false if assumed state is true."""
|
|
||||||
return not self._assumed_state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the unique id of this switch."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs: Any) -> None:
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
service_kwargs = {}
|
service_kwargs: dict[str, Any] = {}
|
||||||
if self._broadcast_address is not None:
|
if self._broadcast_address is not None:
|
||||||
service_kwargs["ip_address"] = self._broadcast_address
|
service_kwargs["ip_address"] = self._broadcast_address
|
||||||
if self._broadcast_port is not None:
|
if self._broadcast_port is not None:
|
||||||
|
@ -143,7 +126,7 @@ class WolSwitch(SwitchEntity):
|
||||||
|
|
||||||
wakeonlan.send_magic_packet(self._mac_address, **service_kwargs)
|
wakeonlan.send_magic_packet(self._mac_address, **service_kwargs)
|
||||||
|
|
||||||
if self._assumed_state:
|
if self._attr_assumed_state:
|
||||||
self._state = True
|
self._state = True
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
@ -152,7 +135,7 @@ class WolSwitch(SwitchEntity):
|
||||||
if self._off_script is not None:
|
if self._off_script is not None:
|
||||||
self._off_script.run(context=self._context)
|
self._off_script.run(context=self._context)
|
||||||
|
|
||||||
if self._assumed_state:
|
if self._attr_assumed_state:
|
||||||
self._state = False
|
self._state = False
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -2584,6 +2584,16 @@ disallow_untyped_defs = true
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.wake_on_lan.*]
|
||||||
|
check_untyped_defs = true
|
||||||
|
disallow_incomplete_defs = true
|
||||||
|
disallow_subclassing_any = true
|
||||||
|
disallow_untyped_calls = true
|
||||||
|
disallow_untyped_decorators = true
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unreachable = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.wallbox.*]
|
[mypy-homeassistant.components.wallbox.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
|
Loading…
Add table
Reference in a new issue