diff --git a/homeassistant/components/hdmi_cec/switch.py b/homeassistant/components/hdmi_cec/switch.py index a5d64b2a7fa..076bedde0b2 100644 --- a/homeassistant/components/hdmi_cec/switch.py +++ b/homeassistant/components/hdmi_cec/switch.py @@ -52,15 +52,6 @@ class CecSwitchEntity(CecEntity, SwitchEntity): self._state = STATE_OFF self.schedule_update_ha_state(force_refresh=False) - def toggle(self, **kwargs): - """Toggle the entity.""" - self._device.toggle() - 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.""" diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index c8faad53b0e..1c03e2334fe 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -1025,15 +1025,20 @@ class ToggleEntity(Entity): """Turn the entity off.""" await self.hass.async_add_executor_job(ft.partial(self.turn_off, **kwargs)) + @final def toggle(self, **kwargs: Any) -> None: - """Toggle the entity.""" - if self.is_on: - self.turn_off(**kwargs) - else: - self.turn_on(**kwargs) + """Toggle the entity. + + This method will never be called by Home Assistant and should not be implemented + by integrations. + """ async def async_toggle(self, **kwargs: Any) -> None: - """Toggle the entity.""" + """Toggle the entity. + + This method should typically not be implemented by integrations, it's enough to + implement async_turn_on + async_turn_off or turn_on + turn_off. + """ if self.is_on: await self.async_turn_off(**kwargs) else: