Fix hdmi_cec switches (#55666)

This commit is contained in:
Joakim Sørensen 2021-09-03 18:17:41 +02:00 committed by GitHub
parent 25b39b36e7
commit 7caa985a59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import logging
from homeassistant.components.switch import DOMAIN, SwitchEntity
from homeassistant.const import STATE_OFF, STATE_ON
from . import ATTR_NEW, CecEntity
@ -34,17 +35,25 @@ class CecSwitchEntity(CecEntity, SwitchEntity):
def turn_on(self, **kwargs) -> None:
"""Turn device on."""
self._device.turn_on()
self._attr_is_on = True
self._state = STATE_ON
self.schedule_update_ha_state(force_refresh=False)
def turn_off(self, **kwargs) -> None:
"""Turn device off."""
self._device.turn_off()
self._attr_is_on = False
self._state = STATE_OFF
self.schedule_update_ha_state(force_refresh=False)
def toggle(self, **kwargs):
"""Toggle the entity."""
self._device.toggle()
self._attr_is_on = not self._attr_is_on
if self._state == STATE_ON:
self._state = STATE_OFF
else:
self._state = STATE_ON
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