Mark unused sync toggle method from ToggleEntity as final (#72370)

This commit is contained in:
Erik Montnemery 2022-05-23 17:52:21 +02:00 committed by GitHub
parent 7da9cac1f8
commit deedbca46c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 15 deletions

View File

@ -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."""

View File

@ -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: