mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Make broadlink switch restore its state (#23829)
* Make broadlink switch restore its state Method copied from pilight switch * style
This commit is contained in:
parent
2a9fd9ae26
commit
e687848152
@ -10,9 +10,10 @@ from homeassistant.components.switch import (
|
|||||||
ENTITY_ID_FORMAT, PLATFORM_SCHEMA, SwitchDevice)
|
ENTITY_ID_FORMAT, PLATFORM_SCHEMA, SwitchDevice)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_COMMAND_OFF, CONF_COMMAND_ON, CONF_FRIENDLY_NAME, CONF_HOST, CONF_MAC,
|
CONF_COMMAND_OFF, CONF_COMMAND_ON, CONF_FRIENDLY_NAME, CONF_HOST, CONF_MAC,
|
||||||
CONF_SWITCHES, CONF_TIMEOUT, CONF_TYPE)
|
CONF_SWITCHES, CONF_TIMEOUT, CONF_TYPE, STATE_ON)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util import Throttle, slugify
|
from homeassistant.util import Throttle, slugify
|
||||||
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
|
|
||||||
from . import async_setup_service, data_packet
|
from . import async_setup_service, data_packet
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
add_entities(switches)
|
add_entities(switches)
|
||||||
|
|
||||||
|
|
||||||
class BroadlinkRMSwitch(SwitchDevice):
|
class BroadlinkRMSwitch(SwitchDevice, RestoreEntity):
|
||||||
"""Representation of an Broadlink switch."""
|
"""Representation of an Broadlink switch."""
|
||||||
|
|
||||||
def __init__(self, name, friendly_name, device, command_on, command_off):
|
def __init__(self, name, friendly_name, device, command_on, command_off):
|
||||||
@ -127,6 +128,13 @@ class BroadlinkRMSwitch(SwitchDevice):
|
|||||||
self._command_off = command_off
|
self._command_off = command_off
|
||||||
self._device = device
|
self._device = device
|
||||||
|
|
||||||
|
async def async_added_to_hass(self):
|
||||||
|
"""Call when entity about to be added to hass."""
|
||||||
|
await super().async_added_to_hass()
|
||||||
|
state = await self.async_get_last_state()
|
||||||
|
if state:
|
||||||
|
self._state = state.state == STATE_ON
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the switch."""
|
"""Return the name of the switch."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user