mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
parent
8ab3d9cc12
commit
3296772bd3
@ -4,7 +4,6 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.switch import DOMAIN, SwitchEntity
|
from homeassistant.components.switch import DOMAIN, SwitchEntity
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
|
||||||
|
|
||||||
from . import ATTR_NEW, CecEntity
|
from . import ATTR_NEW, CecEntity
|
||||||
|
|
||||||
@ -35,30 +34,17 @@ class CecSwitchEntity(CecEntity, SwitchEntity):
|
|||||||
def turn_on(self, **kwargs) -> None:
|
def turn_on(self, **kwargs) -> None:
|
||||||
"""Turn device on."""
|
"""Turn device on."""
|
||||||
self._device.turn_on()
|
self._device.turn_on()
|
||||||
self._state = STATE_ON
|
self._attr_is_on = True
|
||||||
self.schedule_update_ha_state(force_refresh=False)
|
self.schedule_update_ha_state(force_refresh=False)
|
||||||
|
|
||||||
def turn_off(self, **kwargs) -> None:
|
def turn_off(self, **kwargs) -> None:
|
||||||
"""Turn device off."""
|
"""Turn device off."""
|
||||||
self._device.turn_off()
|
self._device.turn_off()
|
||||||
self._state = STATE_OFF
|
self._attr_is_on = False
|
||||||
self.schedule_update_ha_state(force_refresh=False)
|
self.schedule_update_ha_state(force_refresh=False)
|
||||||
|
|
||||||
def toggle(self, **kwargs):
|
def toggle(self, **kwargs):
|
||||||
"""Toggle the entity."""
|
"""Toggle the entity."""
|
||||||
self._device.toggle()
|
self._device.toggle()
|
||||||
if self._state == STATE_ON:
|
self._attr_is_on = not self._attr_is_on
|
||||||
self._state = STATE_OFF
|
|
||||||
else:
|
|
||||||
self._state = STATE_ON
|
|
||||||
self.schedule_update_ha_state(force_refresh=False)
|
self.schedule_update_ha_state(force_refresh=False)
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self) -> bool:
|
|
||||||
"""Return True if entity is on."""
|
|
||||||
return self._state == STATE_ON
|
|
||||||
|
|
||||||
@property # type: ignore
|
|
||||||
def state(self) -> str | None:
|
|
||||||
"""Return the cached state of device."""
|
|
||||||
return self._state
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user